Am 27.07.2017 um 16:45 schrieb paul via Boost:
On Wed, 2017-07-26 at 22:48 -0400, Edward Diener via Boost wrote:
On 7/26/2017 3:42 PM, paul via Boost wrote:
[...]
For a compile/link test:
add_library(footest STATIC EXCLUDE_FROM_ALL footest.cpp) add_test(NAME footest COMMAND ${CMAKE_COMMAND} --build . --target footest -- config $<CONFIGURATION> WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Why am I adding a library when all I am trying to do is see whether source file(s) can be compiled to their object files successfully ( the compile test ) or whether source file(s) can be compiled to their object files successfully then linked as an executable without linking errors ( the link test ) ?
You have to add a target to be built, and then the test will invoke this target. Tests in cmake are just commands that can do anything, and in this case we instruct cmake to build a target. The reason its a library and not an executable is so that a `main` function is not needed.
Of course, this will test both compiling and linking together, as there is no separation for this in cmake.
CMake has support for "object-libraries", which are targets that just compile source-files into object-files I have not tried it but I would think the following would be possible to only test compilation without linking: ```cmake add_library(OBJECT footest EXCLUDE_FROM_ALL footest.cpp # ... further source-files can go here ... ) add_test(NAME footest COMMAND ${CMAKE_COMMAND} --build . --target footest --config $<CONFIGURATION> WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) ``` HTH, Deniz