[CMake] Using try_compile before project() command
Carminati Federico
Federico.Carminati at cern.ch
Tue Jul 15 11:47:45 EDT 2008
Hello Yuri,
I posted a similar question some time ago. There seems to be no way
to chose the compiler within the CMakeList.txt, because you can do
very little before the Project command, and afterwards it is too late.
Anybody can help here? best, regards,
Federico Carminati
CERN-PH
1211 Geneva 23
Switzerland
Tel: +41 22 76 74959
Fax: +41 22 76 79480
Mobile: +41 76 487 4843
On 15 Jul 2008, at 15:56, Yuri Timenkov wrote:
> I want to tune initial compile and linker flags to put into cache.
> in main CMakeLists.txt:
>
> # Override default Compiler flags
> set(CMAKE_USER_MAKE_RULES_OVERRIDE MyCompilerFlags)
> project(MyProject)
>
> in MyCompilerFlags.cmake:
>
> check_cxx_linker_flag("-Wl,--warn-unresolved-symbols"
> HAVE_LD_WARN_UNRESOLVED_SYMBOLS)
>
> if(HAVE_LD_WARN_UNRESOLVED_SYMBOLS)
> set(CMAKE_SHARED_LINKER_FLAGS_INIT "$
> {CMAKE_SHARED_LINKER_FLAGS_INIT} -Wl,--warn-unresolved-symbols")
> endif(HAVE_LD_WARN_UNRESOLVED_SYMBOLS)
>
> This works fine for CMake 2.4:
> -- Performing Test -Wl,--warn-unresolved-symbols
> -- Performing Test -Wl,--warn-unresolved-symbols - Success
> -- Performing Test -Wl,--no-undefined
> -- Performing Test -Wl,--no-undefined - Success
> -- Check for working C compiler: /usr/bin/gcc32
> -- Check for working C compiler: /usr/bin/gcc32 -- works
> ...
>
> But for CMake 2.6 this code fails with error:
> -- The C compiler identification is GNU
> -- The CXX compiler identification is GNU
> -- Performing Test -Wl,--warn-unresolved-symbols
> CMake Error: Unknown extension ".cxx" for file "/vz/build/test/
> CMakeFiles/CMakeTmp/src.cxx". TRY_COMPILE only works for enabled
> languages.
> Currently enabled languages are: C CXX
> See PROJECT command for help enabling other languages.
> -- Performing Test -Wl,--warn-unresolved-symbols - Failed
> -- Performing Test -Wl,--no-undefined
> CMake Error: Unknown extension ".cxx" for file "/vz/build/test/
> CMakeFiles/CMakeTmp/src.cxx". TRY_COMPILE only works for enabled
> languages.
> Currently enabled languages are: C CXX
> See PROJECT command for help enabling other languages.
> -- Performing Test -Wl,--no-undefined - Failed
> -- Check for working C compiler: /usr/bin/gcc32
> -- Check for working C compiler: /usr/bin/gcc32 -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> ...
>
> where check_cxx_linker_flag macro looks line check_cxx_compiler_flag:
>
> file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/
> src.cxx"
> "int main() { return 0;}\n")
> message(STATUS "Performing Test ${_FLAG}")
> try_compile(${_RESULT}
> ${CMAKE_BINARY_DIR}
> "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx"
> CMAKE_FLAGS -DCMAKE_EXE_LINKER_FLAGS="${_FLAG}"
> OUTPUT_VARIABLE OUTPUT
> )
>
> Any suggestions?
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
More information about the CMake
mailing list