try_compile
: Try compiling some code.try_compile(RESULT_VAR bindir srcdir
projectName <targetname> [CMAKE_FLAGS <Flags>]
[OUTPUT_VARIABLE var])
Try compiling a program. In this form, srcdir should contain a complete CMake project with a CMakeLists.txt file and all sources. The bindir and srcdir will not be deleted after this command is run. If <target name> is specified then build just that target otherwise the all or ALL_BUILD target is built.
try_compile(RESULT_VAR bindir srcfile
[CMAKE_FLAGS <Flags>]
[COMPILE_DEFINITIONS <flags> ...]
[OUTPUT_VARIABLE var]
[COPY_FILE <filename> )
Try compiling a srcfile. In this case, the user need only supply a source file. CMake will create the appropriate CMakeLists.txt file to build the source. If COPY_FILE is used, the compiled file will be copied to the given file.
In this version all files in bindir/CMakeFiles/CMakeTmp, will be cleaned automatically, for debugging a --debug-trycompile can be passed to cmake to avoid the clean. Some extra flags that can be included are, INCLUDE_DIRECTORIES, LINK_DIRECTORIES, and LINK_LIBRARIES. COMPILE_DEFINITIONS are -Ddefinition that will be passed to the compile line. try_compile creates a CMakeList.txt file on the fly that looks like this:
add_definitions( <expanded COMPILE_DEFINITIONS from calling cmake>)
include_directories(${INCLUDE_DIRECTORIES})
link_directories(${LINK_DIRECTORIES})
add_executable(cmTryCompileExec sources)
target_link_libraries(cmTryCompileExec ${LINK_LIBRARIES})
In both versions of the command, if OUTPUT_VARIABLE is specified, then the output from the build process is stored in the given variable. Return the success or failure in RESULT_VAR. CMAKE_FLAGS can be used to pass -DVAR:TYPE=VALUE flags to the cmake that is run during the build.