omp.h not found on MacOS with Xclang
KrisThielemans opened this issue · comments
Current code is
Lines 169 to 177 in f673b78
On MacOS, this can lead to a
find_package(OpenMP)
returning ok, but compilation failing with omp.h not found
.(tested with CMake 3.21.1)
https://cmake.org/cmake/help/latest/module/FindOpenMP.html says
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_INCLUDE_DIR cache variable. Note that this variable is an input control to the module. Project code should use the OpenMP_INCLUDE_DIRS output variable if it needs to know what include directories are needed.
Checking the CMakeCache.txt
, the find_package
statement sets OpenMP_CXX_FLAGS
to -xclang -fopenmp
. We can set OpenMP_CXX_INCLUDE_DIR=/usr/local/include
(which is where omp.h
is found) but it is not used by NiftyReg. (Same for the C versions).
This should be resolvable by adding
include_directories(${OpenMP_CXX_INCLUDE_DIRS})
include_directories(${OpenMP_C_INCLUDE_DIRS})
Better would be to depend on the OpenMP::OpenMP_CXX
(or C) target instead.