System info
- macos 12.5.1
- Compiler Apple clang 14.0.0
- Cmake version 3.24.2 from
brew
- OpenMP version 15.0.7 from
brew
, this installs the library in/opt/homebrew/opt/libomp/
The problem
I am debugging an issue where OpenMP cannot be found by cmake, but it does not make sense and I must be missing something obvious.
Assume initially this CMakeLists.txt
# attempt 1
cmake_minimum_required(VERSION 3.24)
project(openmp-bug)
find_package(OpenMP REQUIRED)
Running rm -rf * && cmake ..
inside build/
, results in OpenMP not being found
> rm -rf * && cmake ..
-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call Stack (most recent call first):
/opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/FindOpenMP.cmake:545 (find_package_handle_standard_args)
CMakeLists.txt:20 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/rasmus/Desktop/cmake-openmp/build/CMakeFiles/CMakeOutput.log".
See also "/Users/rasmus/Desktop/cmake-openmp/build/CMakeFiles/CMakeError.log".
Seeing that OpenMP headers and libraries are in a nonstandard location, this is not surprising. So I'm thinking to just find the installation path on osx and inform cmake:
# attempt 2
cmake_minimum_required(VERSION 3.24)
project(openmp-bug)
execute_process(
COMMAND brew --prefix libomp
ERROR_QUIET
OUTPUT_VARIABLE OPENMP_PREFIX
RESULT_VARIABLE find-openmp-status
)
if (find-openmp-status EQUAL 0)
message(STATUS "OpenMP prefix: ${OPENMP_PREFIX}")
list(APPEND CMAKE_PREFIX_PATH ${OPENMP_PREFIX})
else ()
message(
FATAL_ERROR
"Could not find OpenMP prefix Status was ${find-qt-status}"
)
endif ()
find_package(OpenMP REQUIRED)
But this for some reason fails with the identical output:
> rm -rf * && cmake ..
-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- OpenMP prefix: /opt/homebrew/opt/libomp <--- !!!!!! note path is found here
CMake Error at /opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call Stack (most recent call first):
/opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/FindOpenMP.cmake:545 (find_package_handle_standard_args)
CMakeLists.txt:19 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/rasmus/Desktop/cmake-openmp/build/CMakeFiles/CMakeOutput.log".
See also "/Users/rasmus/Desktop/cmake-openmp/build/CMakeFiles/CMakeError.log".
Now if I hardcode the path, it works, even though the hardcoded path is identical to the computed one:
# attempt 3
cmake_minimum_required(VERSION 3.24)
project(openmp-bug)
list(APPEND CMAKE_PREFIX_PATH /opt/homebrew/opt/libomp)
find_package(OpenMP REQUIRED)
Is there some invisible quoting going on here or what could the issue be?