Commit ede1bebd authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'FindOpenMP-include-dir'

409891ba FindOpenMP: Allow try_compile() to find omp.h for AppleClang
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !3916
parents 61c6d49f 409891ba
......@@ -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)
......@@ -261,11 +272,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)
......@@ -325,10 +352,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)
......@@ -491,6 +523,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)
......@@ -501,6 +538,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}")
......
......@@ -42,6 +42,7 @@ foreach(c C CXX Fortran)
separate_arguments(_OpenMP_${c}_OPTIONS NATIVE_COMMAND "${OpenMP_${c}_FLAGS}")
target_compile_options(test_var_${c} PRIVATE "${_OpenMP_${c}_OPTIONS}")
target_link_libraries(test_var_${c} PRIVATE "${OpenMP_${c}_FLAGS}")
target_include_directories(test_var_${c} PRIVATE ${OpenMP_${c}_INCLUDE_DIRS})
set_property(TARGET test_var_${c} PROPERTY LINKER_LANGUAGE ${c})
add_test(NAME test_var_${c} COMMAND test_var_${c})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment