[CMake] Using try_compile before project() command
Bill Hoffman
bill.hoffman at kitware.com
Tue Jul 15 12:01:52 EDT 2008
Carminati Federico wrote:
> 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,
>
That is a very different question, and no, you can not change the
compiler from within a CMakeLists.txt file. It must be picked with CC
or CXX environment variables before running CMake.
> 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?
Looks like a bug. Please file a bug report with a small example that
is easy to reproduce.
Thanks.
-Bill
More information about the CMake
mailing list