Using the following override file results in the try_compile failing for both the C compiler and the C++ compiler. The output shows that the override file is being processed multiple times. The first time it is processed, the variable PARAM is 'set' as specified on the CMake command line. However, subsequent processing of the file shows that PARAM is not 'set' and results in the 'bogus-option' being added to the compiler command line. This, of course, results in the try_compile's failing.
message(STATUS "Processing override_compiler_flags.cmake ...") if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) if(PARAM STREQUAL "set") message(AUTHOR_WARNING "PARAM is 'set' ...") add_definitions("-DPARAM=1") else() message(AUTHOR_WARNING "PARAM is not 'set' ...") add_definitions("--bogus-option") endif() endif() The CMake process is initiated with the following command line. $ cmake -DPARAM=set .. And, usage of the override file is set with the following before the project is defined. set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/override_compiler_flags.cmake) I have attached the output of the CMake run as well. Is this a bug in that subsequent processing of the override file is not using the cached value of PARAM? Or, is there something wrong with the override file itself? Thanks! Mike
$ cmake -DPARAM=set .. -- The C compiler identification is GNU 4.7.3 -- The CXX compiler identification is GNU 4.7.3 -- Processing override_compiler_flags.cmake ... CMake Warning (dev) at override_compiler_flags.cmake:5 (message): PARAM is 'set' ... Call Stack (most recent call first): /usr/local/share/cmake-3.6/Modules/CMakeCInformation.cmake:94 (include) CMakeLists.txt:7 (project) This warning is for project developers. Use -Wno-dev to suppress it. -- Check for working C compiler: /usr/bin/cc CMake Warning (dev) at /cmake-test/override_compiler_flags.cmake:8 (message): PARAM is not 'set' ... Call Stack (most recent call first): /usr/local/share/cmake-3.6/Modules/CMakeCInformation.cmake:94 (include) /cmake-test/test/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project) This warning is for project developers. Use -Wno-dev to suppress it. -- Check for working C compiler: /usr/bin/cc -- broken CMake Error at /usr/local/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message): The C compiler "/usr/bin/cc" is not able to compile a simple test program. It fails with the following output: Change Dir: /cmake-test/test/CMakeFiles/CMakeTmp Run Build Command:"/usr/bin/make" "cmTC_68ea8/fast" /usr/bin/make -f CMakeFiles/cmTC_68ea8.dir/build.make CMakeFiles/cmTC_68ea8.dir/build make[1]: Entering directory `/cmake-test/test/CMakeFiles/CMakeTmp' Building C object CMakeFiles/cmTC_68ea8.dir/testCCompiler.c.o /usr/bin/cc --bogus-option -o CMakeFiles/cmTC_68ea8.dir/testCCompiler.c.o -c /cmake-test/test/CMakeFiles/CMakeTmp/testCCompiler.c cc: error: unrecognized command line option ‘--bogus-option’ make[1]: *** [CMakeFiles/cmTC_68ea8.dir/testCCompiler.c.o] Error 1 make[1]: Leaving directory `/cmake-test/test/CMakeFiles/CMakeTmp' make: *** [cmTC_68ea8/fast] Error 2 CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:7 (project) -- Configuring incomplete, errors occurred! See also "/cmake-test/test/CMakeFiles/CMakeOutput.log". See also "/cmake-test/test/CMakeFiles/CMakeError.log".
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake