[CMake] CMake flags to TRY_RUN
James Bigler
bigler at cs.utah.edu
Tue May 22 14:48:23 EDT 2007
I have a some code that I need to test and I need to feed it a default
set of compiler flags. I'm trying to set CMAKE_C_FLAGS via the -D
system to override the default ones CMake provides.
SET(COMPILE_TEST_SOURCE ${CMAKE_BINARY_DIR}/test/compile-test.c)
FILE(WRITE ${COMPILE_TEST_SOURCE} "int main() { return 0; }\n")\
SET(ARCH "i686")
MESSAGE("Testing ARCH = ${ARCH}")
SET(ARCH_FLAG "-march=${ARCH} -mtune=${ARCH}")
SET(COMPILER_ARGS "${ARCH_FLAG} ${C_FLAGS_RELEASE} ${C_FLAGS}")
TRY_RUN(RUN_RESULT_VAR COMPILE_RESULT_VAR
${CMAKE_BINARY_DIR}/test ${COMPILE_TEST_SOURCE}
CMAKE_FLAGS "-DCMAKE_C_FLAGS:STRING=${COMPILER_FLAGS}"
OUTPUT_VARIABLE OUTPUT
)
MESSAGE("RUN_RESULT_VAR = ${RUN_RESULT_VAR}")
MESSAGE("COMPILE_RESULT_VAR = ${COMPILE_RESULT_VAR}")
MESSAGE("OUTPUT = ${OUTPUT}")
This builds and runs the code, but it has two problems.
1. My flags don't get passed in.
2. CMake later complains about my temporary file:
CMake Error: File
/home/scinew/bigler/manta/trunk/opt-4.0.2/test/compile-test.c is written
by WRITE_FILE (or FILE WRITE) command and should not be used as input to
CMake. Please use CONFIGURE_FILE to be safe. Refer to the note next to
FILE WRITE command.
I'm using cmake 2.4.6 and 2.2.3.
James
More information about the CMake
mailing list