Try building a project. Build success returns TRUE and build failure returns FALSE in .
In this form, should contain a complete CMake project with a CMakeLists.txt file and all sources. The and will not be deleted after this command is run. Specify to build a specific target instead of the all or ALL_BUILD target. See below for the meaning of other options.
message("Building project second time")
try_compile(RESULT
${BuildDepends_BINARY_DIR}/Project
${BuildDepends_SOURCE_DIR}/Project
testRebuild
CMAKE_FLAGS ${_cmake_options}
OUTPUT_VARIABLE OUTPUT)
LINK_DEPENDS
Additional files on which a target binary depends for linking.
Specifies a semicolon-separated list of full-paths to files on which the link rule for this target depends. The target binary will be linked if any of the named files is newer than it.
set_property(TARGET linkdep PROPERTY LINK_DEPENDS $<1:${TEST_LINK_DEPENDS}>)
add_custom_target
-P指定了要执行的CMake脚本文件;
-D传入的参数;
add_library(link_depends_no_shared_lib SHARED link_depends_no_shared_lib.c
${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_lib.h)
add_executable(link_depends_no_shared_exe link_depends_no_shared_exe.c
${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_exe.h)
target_link_libraries(link_depends_no_shared_exe link_depends_no_shared_lib)
set_property(TARGET link_depends_no_shared_exe PROPERTY LINK_DEPENDS_NO_SHARED 1)
add_custom_target(link_depends_no_shared_check ALL
COMMAND ${CMAKE_COMMAND}
-Dlib=$<TARGET_FILE:link_depends_no_shared_lib>
-Dexe=$<TARGET_FILE:link_depends_no_shared_exe>
-Dout=${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_check.txt
-P ${CMAKE_CURRENT_SOURCE_DIR}/link_depends_no_shared_check.cmake
)
add_dependencies(link_depends_no_shared_check link_depends_no_shared_exe)
OBJECT_DEPENDS
add_executable(object_depends object_depends.cxx)
set_property(SOURCE object_depends.cxx PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/object_depends.txt)
add_custom_target(object_depends_check ALL
COMMAND ${CMAKE_COMMAND}
-Dexe=$<TARGET_FILE:object_depends>
-Dout=${CMAKE_CURRENT_BINARY_DIR}/object_depends_check.txt
-Dtxt=${CMAKE_CURRENT_BINARY_DIR}/object_depends.txt
-P ${CMAKE_CURRENT_SOURCE_DIR}/object_depends_check.cmake
)
#add_dependencies(object_depends_check object_depends)
# 测试代码
if("${object_depends_check}" STREQUAL "1")
message(STATUS "object_depends exe is newer than object_depends.txt as expected.")
elseif(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
message(STATUS "Known limitation: OBJECT_DEPENDS does not work on ${CMAKE_GENERATOR}")
else()
message(SEND_ERROR "Project did not rebuild properly: object_depends exe is not newer than object_depends.txt.")
endif()