Eric Bush
Eric Bush

Reputation: 197

How do I get CMake to find OpenMP_C, OpenMP_CXX, etc.?

I am fairly new to working with the terminal and I am attempting to use cmake to configure a build for a project that involves public transportation routes. When I attempt to make the build I get the following response in the terminal:

$ cmake ..
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) 
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND) 
CMake Warning at CMakeLists.txt:33 (message):
  Configuring without OpenMP!


CMake Error at src/CMakeLists.txt:13 (add_subdirectory):
  The source directory

    /Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/src/cppgtfs

  does not contain a CMakeLists.txt file.


CMake Error at src/CMakeLists.txt:14 (add_subdirectory):
  The source directory

    /Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/src/configparser

  does not contain a CMakeLists.txt file.


-- Configuring incomplete, errors occurred!
See also "/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/build/CMakeFiles/CMakeOutput.log".
See also "/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/build/CMakeFiles/CMakeError.log".

Below is what I believe to be the relevant code from the CMakeLists.txt file:

find_package(OpenMP)

if (OPENMP_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()


# set compiler flags, see http://stackoverflow.com/questions/7724569/debug-vs-release-in-cmake
if(OPENMP_FOUND)
    set(CMAKE_CXX_FLAGS            "-fopenmp -Ofast -fno-signed-zeros -fno-trapping-math -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Wextra -Wno-implicit-fallthrough -pedantic")
else()
    message(WARNING "Configuring without OpenMP!")
    set(CMAKE_CXX_FLAGS            "-Ofast -fno-signed-zeros -fno-trapping-math -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Wextra -Wno-implicit-fallthrough -pedantic")
endif()
set(CMAKE_CXX_FLAGS_DEBUG          "-Og -g -DLOGLEVEL=3 -DPFAEDLE_DBG=1")
set(CMAKE_CXX_FLAGS_MINSIZEREL     "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
set(CMAKE_CXX_FLAGS_RELEASE        "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -g -DLOGLEVEL=3")

I have found some similar questions on this and other websites, but I am still struggling to understand the problem because I have never used cmake before and, as mentioned, I am somewhat new to working with the terminal. I would be extremely grateful for any information on what the error messages are actually telling me, or any suggestions on steps I could take/things I could try to solve the issue. I am working on a Mac, if anyone is wondering.

Upvotes: 10

Views: 17935

Answers (1)

Richard Barber
Richard Barber

Reputation: 6431

For the compiler to see OpenMP, you may need to set the following options in your cmake command (for dependencies located in /opt/local):

cmake .. \
-DOpenMP_C_FLAGS=-fopenmp=lomp \
-DOpenMP_CXX_FLAGS=-fopenmp=lomp \
-DOpenMP_C_LIB_NAMES="libomp" \
-DOpenMP_CXX_LIB_NAMES="libomp" \
-DOpenMP_libomp_LIBRARY="/opt/local/lib/libomp.dylib" \
-DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp /opt/local/lib/libomp.dylib -I/opt/local/include" \
-DOpenMP_CXX_LIB_NAMES="libomp" \
-DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp /opt/local/lib/libomp.dylib -I/opt/local/include"

The two missing CMakeLists.txt are located in git submodules within src/ To download the submodules, cd to the root phaedle directory and issue the following command:

git submodule update --init --recursive

Edit: this is now fixed in master.

Upvotes: 8

Related Questions