KCL-BMEIS / niftyreg

This project contains command line tools to perform rigid, affine and non-linear registration of nifti or analyse images as well as utilities
BSD 3-Clause "New" or "Revised" License
141 stars 42 forks source link

omp.h not found on MacOS with Xclang #109

Closed KrisThielemans closed 8 months ago

KrisThielemans commented 8 months ago

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 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.