[CMake] TRY_COMPILE and CMAKE_C_FLAGS

Gregor Jasny gjasny at googlemail.com
Sat Oct 21 06:47:30 EDT 2006


Hi,

I want to test if the current GNU compiler accept the -fopenmp flag.
In my cmake module I have the following test:

TRY_COMPILE( OPENMP_COMPILED
        ${CMAKE_BINARY_DIR}
        ${CMAKE_SOURCE_DIR}/cmake/Modules/CheckForOpenMP.c
        CMAKE_FLAGS -DCMAKE_C_FLAGS:STRING="-fopenmp"
        OUTPUT_VARIABLE OUTPUT
)

But the CMAKE_C_FLAGS setting is not propagated to the generated makefile:
[...]
/usr/bin/gcc   -o
CMakeFiles/cmTryCompileExec.dir/home/gjasny/src/parallel/cmake/Modules/CheckForOpenMP.o
  -c /home/gjasny/src/parallel/cmake/Modules/CheckForOpenMP.c
[...]
/usr/bin/gcc        -fPIC
"CMakeFiles/cmTryCompileExec.dir/home/gjasny/src/parallel/cmake/Modules/CheckForOpenMP.o"
  -o cmTryCompileExec -rdynamic

I can set the CMAKE_C_FLAGS before the TRY_COMPILE but that seems a
little bit weird to me.

I've got three other questions:
1. Is it possible to change the C compiler and CFLAGS for a target? I
want to provide a macro like OPENMP_ADD_EXECUTABLE which sets the
compiler and cflags only for the target.

2. Is there a list of allowed / uses PROPERITES?

3. Is it possible to check the return value of a program executed by TRY_RUN?

Thanks for your support,
Gregor


More information about the CMake mailing list