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).
Current code is https://github.com/KCL-BMEIS/niftyreg/blob/f673b7837c0824f55dedb1534b32b55bf68a2823/CMakeLists.txt#L169-L177 On MacOS, this can lead to a
find_package(OpenMP)
returning ok, but compilation failing withomp.h not found
. (tested with CMake 3.21.1)https://cmake.org/cmake/help/latest/module/FindOpenMP.html says
Checking the
CMakeCache.txt
, thefind_package
statement setsOpenMP_CXX_FLAGS
to-xclang -fopenmp
. We can setOpenMP_CXX_INCLUDE_DIR=/usr/local/include
(which is whereomp.h
is found) but it is not used by NiftyReg. (Same for the C versions).This should be resolvable by adding
Better would be to depend on the
OpenMP::OpenMP_CXX
(or C) target instead.