【CMake-master】源码解析-BuildDepends

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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值