# FindOpenThreads

Finds the OpenThreads C++ based threading library:

    find_package(OpenThreads [...])

OpenThreads header files are intended to be included as:

`example.cxx`

    #include <OpenThreads/Thread>

## Result Variables

This module defines the following variables:

`OpenThreads_FOUND`

  Added in version 3.3.

  Boolean indicating whether the OpenThreads library was found.

`OPENTHREADS_LIBRARY`

  Libraries needed to link against to use OpenThreads. This provides either release (optimized) or debug library variant, which are found separately depending on the project's Build Configurations.

## Cache Variables

The following cache variables may also be set:

`OPENTHREADS_INCLUDE_DIR`

  The directory containing the header files needed to use OpenThreads.

## Hints

This module accepts the following variables:

`OPENTHREADS_DIR`

  An environment or CMake variable that can be set to help find an OpenThreads library installed in a custom location. It should point to the installation destination that was used when configuring, building, and installing OpenThreads library: `./configure --prefix=$OPENTHREADS_DIR`.

This module was originally introduced to support the `FindOpenSceneGraph` module and its components. To simplify one-step automated configuration and builds when the OpenSceneGraph package is developed and distributed upstream, this module supports additional environment variables to find dependencies in specific locations. This approach is used by upstream package over specifying `-DVAR=value` on the command line because it offers better isolation from internal changes to the module and allows more flexibility when specifying individual OSG components independently of the `CMAKE_*_PATH` variables. Explicit `-DVAR=value` arguments can still override these settings if needed. Since OpenThreads is an optional standalone dependency of OpenSceneGraph, this module also honors the following variables for convenience:

`OSG_DIR`

  May be set as an environment or CMake variable. Treated the same as `OPENTHREADS_DIR`.

`OSGDIR`

  Environment variable treated the same as `OPENTHREADS_DIR`.

## Deprecated Variables

The following variables are provided for backward compatibility:

`OPENTHREADS_FOUND`

  Deprecated since version 4.2: Use `OpenThreads_FOUND`, which has the same value.

  Boolean indicating whether the OpenThreads library was found.

## Examples

Finding the OpenThreads library and creating an interface imported target that encapsulates its usage requirements for linking to a project target:

    find_package(OpenThreads)

    if(OpenThreads_FOUND AND NOT TARGET OpenThreads::OpenThreads)
      add_library(OpenThreads::OpenThreads INTERFACE IMPORTED)
      set_target_properties(
        OpenThreads::OpenThreads
        PROPERTIES
          INTERFACE_INCLUDE_DIRECTORIES "${OPENTHREADS_INCLUDE_DIR}"
          INTERFACE_LINK_LIBRARIES "${OPENTHREADS_LIBRARY}"
      )
    endif()

    target_link_libraries(example PRIVATE OpenThreads::OpenThreads)