1

我想检查我的代码是否编译。在我的 cMakeList.txt 我定义了我的 source_filesfile()

有没有机会将此变量传递给模块 CheckCXXSourceCompiles?

这就像做这样的测试:

check_cxx_source_compiles("int main() { return 0;}" DUMMY) 

但显然对所有人${source_files}

4

1 回答 1

3

Take a look at the try_compile command:

try_compile(COMPILE_SUCCEEDED ${CMAKE_BINARY_DIR}/compile_tests my_test_src.cpp)

if(COMPILE_SUCCEEDED)
  message("Success!")
endif()

Mind you that this is only really useful for compiling small test programs that check for a specific compiler feature. The quickest way to find out if your main codebase compiles is still to actually build it. There is really no need to worry about this during configure phase.

于 2013-11-07T08:47:26.387 回答