[CMake] set_target_properties to target openmp flag on an executable

Caner Candan caner at candan.fr
Fri Mar 18 09:38:30 EDT 2011


Hi all,

Since I have several targets to compile, I was looking for a way to
set some specific flags to one target among all others. In my example
I would like to set the openmp flag to the target test and I got an
error with the code below:

----------------------------------------------------------------------------------------------
PROJECT(test CXX)
ADD_EXECUTABLE(test test.cpp)
SET_TARGET_PROPERTIES(test PROPERTIES COMPILE_FLAGS "-fopenmp")
----------------------------------------------------------------------------------------------

Error:
----------------------------------------------------------------------------------------------
[100%] Building CXX object CMakeFiles/test.dir/test.cpp.o
Linking CXX executable test
CMakeFiles/test.dir/test.cpp.o: In function `main':
test.cpp:(.text+0x29): undefined reference to `GOMP_parallel_start'
test.cpp:(.text+0x3a): undefined reference to `GOMP_parallel_end'
collect2: ld returned 1 exit status
make[2]: *** [test] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
----------------------------------------------------------------------------------------------

But when I am using:
----------------------------------------------------------------------------------------------
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
----------------------------------------------------------------------------------------------

instead of "set_target_properties" then it works but as we know the
flag is affected to all targets and this isn't what I wish.

Anyway, if this is not the good way to use I am open to your
suggestions and advices.

Thanks in advance,
Caner Candan


More information about the CMake mailing list