我想检查我的代码是否编译。在我的 cMakeList.txt 我定义了我的 source_filesfile()
有没有机会将此变量传递给模块 CheckCXXSourceCompiles?
这就像做这样的测试:
check_cxx_source_compiles("int main() { return 0;}" DUMMY)
但显然对所有人${source_files}
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.