[CMake] Set C compiler flags but not linker flags

Roland Schulz roland at utk.edu
Fri Jul 13 01:10:04 EDT 2012


Hi,

if I set compiler flags using CMAKE_C_FLAGS these flags are also added
to the linker flags for C executables and libraries. How can I set
compiler flags without those same flags also appended to the linker
flags?

In this specific case I would like to add "-fopenmp" to the compiler
but do not want this flag to be added to the linker because I want the
openmp library to be linked statically.  For GCC this can be done with
"-Wl,-static -lgomp -lrt -Wl,-Bdynamic -lpthread" but only works if
"-fopenmp" is not also given as a linker flag. Thus it is important
that "-fopenmp" which is needed as compile time option is not appended
to the linker flags.

This is with GCC on Linux with "Unix Makesfiles" and cmake 2.8.8.

Roland
-- 
ORNL/UT Center for Molecular Biophysics cmb.ornl.gov
865-241-1537, ORNL PO BOX 2008 MS6309


More information about the CMake mailing list