FindOpenMP doesn't find OpenMP for generate Xcode project about cmake version 3.12
- Install OpenMP on macOS
brew install libomp
- Generate Make project is ok.
cmake .. --debug-trycompile
-- Found OpenMP_C: -Xclang -fopenmp (found version "3.1")
-- Found OpenMP_CXX: -Xclang -fopenmp (found version "3.1")
-- Found OpenMP: TRUE (found version "3.1")
- Generate Xcode project is wrong.
cmake -G Xcode .. --debug-trycompile
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
Cause:
- Generate Make project's compile argument(include path)
clang -x c++ -v -E /dev/null # /usr/local/include/omp.h is right
/usr/local/include
/usr/include
- Generate Xcode project's compile argument(include path), if contains "-isysroot"
clang -x c++ -v -E /dev/null -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
No contain /usr/local/include
/Users/test/Desktop/test/build/CMakeFiles/FindOpenMP/OpenMPTryFlag.cpp:2:10: fatal error: 'omp.h' file not found
#include <omp.h>
^~~~~~~
1 error generated.
Fixed:
FindOpenMP.cmake
unset(OMP_INCLUDE_DIR CACHE)
find_path(OMP_INCLUDE_DIR NAMES omp.h)
if(OMP_INCLUDE_DIR)
include_directories(${OMP_INCLUDE_DIR})
endif(OMP_INCLUDE_DIR)
and
set(OMP_INCLUDE_DIR_FLAGS "")
if(OMP_INCLUDE_DIR)
string(APPEND OMP_INCLUDE_DIR_FLAGS " -I${OMP_INCLUDE_DIR}")
endif(OMP_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} ${OMP_INCLUDE_DIR_FLAGS}"
LINK_LIBRARIES ${CMAKE_${LANG}_VERBOSE_FLAG}
OUTPUT_VARIABLE OpenMP_TRY_COMPILE_OUTPUT
)
unset(OMP_INCLUDE_DIR_FLAGS)
Multi "try_compile" will be added "OMP_INCLUDE_DIR_FLAGS"