简体   繁体   中英

cMake/cTest: Check if code compiles

I would like to check if my code compiles or not. In my cMakeList.txt I defined my source_files with file()

Is there any chance to pass this variable to the module CheckCXXSourceCompiles?

It is like doing a test like that:

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

but obviously for all ${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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM