diff options
Diffstat (limited to 'Modules/FindOpenMP.cmake')
-rw-r--r-- | Modules/FindOpenMP.cmake | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake index def23bb..94e5258 100644 --- a/Modules/FindOpenMP.cmake +++ b/Modules/FindOpenMP.cmake @@ -36,6 +36,9 @@ project, where ``<lang>`` is one of C, CXX, or Fortran: Variable indicating if OpenMP support for ``<lang>`` was detected. ``OpenMP_<lang>_FLAGS`` OpenMP compiler flags for ``<lang>``, separated by spaces. +``OpenMP_<lang>_INCLUDE_DIRS`` + Directories that must be added to the header search path for ``<lang>`` + when using OpenMP. For linking with OpenMP code written in ``<lang>``, the following variables are provided: @@ -73,6 +76,14 @@ The module will also try to provide the OpenMP version variables: The specification date is formatted as given in the OpenMP standard: ``yyyymm`` where ``yyyy`` and ``mm`` represents the year and month of the OpenMP specification implemented by the ``<lang>`` compiler. + +For some compilers, it may be necessary to add a header search path to find +the relevant OpenMP headers. This location may be language-specific. Where +this is needed, the module may attempt to find the location, but it can be +provided directly by setting the ``OpenMP_<lang>_INCLUDE_DIR`` cache variable. +Note that this variable is an _input_ control to the module. Project code +should use the ``OpenMP_<lang>_INCLUDE_DIRS`` _output_ variable if it needs +to know what include directories are needed. #]=======================================================================] cmake_policy(PUSH) @@ -259,11 +270,27 @@ function(_OPENMP_GET_FLAGS LANG FLAG_MODE OPENMP_FLAG_VAR OPENMP_LIB_NAMES_VAR) mark_as_advanced(OpenMP_libomp_LIBRARY) if(OpenMP_libomp_LIBRARY) + # Try without specifying include directory first. We only want to + # explicitly add a search path if the header can't be found on the + # default header search path already. try_compile( OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG} ${CMAKE_BINARY_DIR} ${_OPENMP_TEST_SRC} CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${OPENMP_FLAGS_TEST}" LINK_LIBRARIES ${CMAKE_${LANG}_VERBOSE_FLAG} ${OpenMP_libomp_LIBRARY} OUTPUT_VARIABLE OpenMP_TRY_COMPILE_OUTPUT ) + if(NOT OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG}) + find_path(OpenMP_${LANG}_INCLUDE_DIR omp.h) + mark_as_advanced(OpenMP_${LANG}_INCLUDE_DIR) + set(OpenMP_${LANG}_INCLUDE_DIR "${OpenMP_${LANG}_INCLUDE_DIR}" PARENT_SCOPE) + if(OpenMP_${LANG}_INCLUDE_DIR) + try_compile( OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG} ${CMAKE_BINARY_DIR} ${_OPENMP_TEST_SRC} + CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${OPENMP_FLAGS_TEST}" + "-DINCLUDE_DIRECTORIES:STRING=${OpenMP_${LANG}_INCLUDE_DIR}" + LINK_LIBRARIES ${CMAKE_${LANG}_VERBOSE_FLAG} ${OpenMP_libomp_LIBRARY} + OUTPUT_VARIABLE OpenMP_TRY_COMPILE_OUTPUT + ) + endif() + endif() if(OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG}) set("${OPENMP_FLAG_VAR}" "${OPENMP_FLAG}" PARENT_SCOPE) set("${OPENMP_LIB_NAMES_VAR}" "libomp" PARENT_SCOPE) @@ -323,10 +350,15 @@ set(OpenMP_Fortran_CHECK_VERSION_SOURCE function(_OPENMP_GET_SPEC_DATE LANG SPEC_DATE) _OPENMP_WRITE_SOURCE_FILE("${LANG}" "CHECK_VERSION_SOURCE" OpenMPCheckVersion _OPENMP_TEST_SRC) + unset(_includeDirFlags) + if(OpenMP_${LANG}_INCLUDE_DIR) + set(_includeDirFlags "-DINCLUDE_DIRECTORIES:STRING=${OpenMP_${LANG}_INCLUDE_DIR}") + endif() + set(BIN_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/FindOpenMP/ompver_${LANG}.bin") string(REGEX REPLACE "[-/=+]" "" OPENMP_PLAIN_FLAG "${OPENMP_FLAG}") try_compile(OpenMP_SPECTEST_${LANG}_${OPENMP_PLAIN_FLAG} "${CMAKE_BINARY_DIR}" "${_OPENMP_TEST_SRC}" - CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${OpenMP_${LANG}_FLAGS}" + CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${OpenMP_${LANG}_FLAGS}" ${_includeDirFlags} COPY_FILE ${BIN_FILE} OUTPUT_VARIABLE OpenMP_TRY_COMPILE_OUTPUT) @@ -489,6 +521,11 @@ foreach(LANG IN LISTS OpenMP_FINDLIST) foreach(_OPENMP_IMPLICIT_LIB IN LISTS OpenMP_${LANG}_LIB_NAMES) list(APPEND OpenMP_${LANG}_LIBRARIES "${OpenMP_${_OPENMP_IMPLICIT_LIB}_LIBRARY}") endforeach() + if(OpenMP_${LANG}_INCLUDE_DIR) + set(OpenMP_${LANG}_INCLUDE_DIRS ${OpenMP_${LANG}_INCLUDE_DIR}) + else() + set(OpenMP_${LANG}_INCLUDE_DIRS "") + endif() if(NOT TARGET OpenMP::OpenMP_${LANG}) add_library(OpenMP::OpenMP_${LANG} INTERFACE IMPORTED) @@ -499,6 +536,10 @@ foreach(LANG IN LISTS OpenMP_FINDLIST) INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:${LANG}>:${_OpenMP_${LANG}_OPTIONS}>") unset(_OpenMP_${LANG}_OPTIONS) endif() + if(OpenMP_${LANG}_INCLUDE_DIRS) + set_property(TARGET OpenMP::OpenMP_${LANG} PROPERTY + INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${OpenMP_${LANG}_INCLUDE_DIRS}>") + endif() if(OpenMP_${LANG}_LIBRARIES) set_property(TARGET OpenMP::OpenMP_${LANG} PROPERTY INTERFACE_LINK_LIBRARIES "${OpenMP_${LANG}_LIBRARIES}") |