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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

omp.h not found on MacOS with Xclang

KrisThielemans opened this issue · comments

Current code is

niftyreg/CMakeLists.txt

Lines 169 to 177 in f673b78

find_package(OpenMP)
if(NOT OPENMP_FOUND)
set(USE_OPENMP OFF CACHE BOOL "To use openMP for multi-CPU processing" FORCE)
message(WARNING "OpenMP does not appear to be supported by your compiler, forcing USE_OPENMP to OFF")
else(NOT OPENMP_FOUND)
message(STATUS "Found OpenMP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif(NOT OPENMP_FOUND)

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.