Take a look at the standard features of the CMake module CheckCXXSourceCompiles and CheckCSourceCompiles . Both functions check whether the given (embedded) source code compiles correctly and if the links are correct. To check if the header is self-sufficient, the source code should consist of an include statement, which includes a header file for checking and the main function:
include (CheckCXXSourceCompiles) set (CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}") check_cxx_source_compiles( "#include \"file.h\" int main() { return 0;}" File_H_IsSelfContained) message ("File_H_IsSelfContained: ${File_H_IsSelfContained}")
Both check_cxx_source_compiles and check_c_source_compiles can only work on CMake setup time, which is probably not the way you want.
Since both functions use the basic CMake try_compile , which is not scriptable, it is not possible to use the functions in the generated CMake script, which runs as a custom target at build time.
sakra source share