ExternalProject: Add option to always run the build step

Teach ExternalProject_Add a new BUILD_ALWAYS option to skip using
the build step stamp file and execute the step on every build.

Extend the BuildDepends test with a case to cover this option.
This commit is contained in:
Brad King 2014-02-21 10:59:06 -05:00
parent c0bbefbfe7
commit 73e5c6aead
4 changed files with 65 additions and 0 deletions

View File

@ -54,6 +54,7 @@
# [BINARY_DIR dir] # Specify build dir location # [BINARY_DIR dir] # Specify build dir location
# [BUILD_COMMAND cmd...] # Command to drive the native build # [BUILD_COMMAND cmd...] # Command to drive the native build
# [BUILD_IN_SOURCE 1] # Use source dir for build dir # [BUILD_IN_SOURCE 1] # Use source dir for build dir
# [BUILD_ALWAYS 1] # No stamp file, build step always runs
# #--Install step--------------- # #--Install step---------------
# [INSTALL_DIR dir] # Installation prefix # [INSTALL_DIR dir] # Installation prefix
# [INSTALL_COMMAND cmd...] # Command to drive install after build # [INSTALL_COMMAND cmd...] # Command to drive install after build
@ -1716,10 +1717,18 @@ function(_ep_add_build_command name)
set(log "") set(log "")
endif() endif()
get_property(build_always TARGET ${name} PROPERTY _EP_BUILD_ALWAYS)
if(build_always)
set(always 1)
else()
set(always 0)
endif()
ExternalProject_Add_Step(${name} build ExternalProject_Add_Step(${name} build
COMMAND ${cmd} COMMAND ${cmd}
WORKING_DIRECTORY ${binary_dir} WORKING_DIRECTORY ${binary_dir}
DEPENDEES configure DEPENDEES configure
ALWAYS ${always}
${log} ${log}
) )
endfunction() endfunction()

View File

@ -68,6 +68,8 @@ file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_exe.h
"#define link_depends_no_shared_exe_value 0\n") "#define link_depends_no_shared_exe_value 0\n")
set(link_depends_no_shared_check_txt ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_check.txt) set(link_depends_no_shared_check_txt ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_check.txt)
file(WRITE ${BuildDepends_BINARY_DIR}/Project/external.in "external original\n")
help_xcode_depends() help_xcode_depends()
message("Building project first time") message("Building project first time")
@ -166,6 +168,19 @@ else()
"Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.") "Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.")
endif() endif()
if(EXISTS ${BuildDepends_BINARY_DIR}/Project/external.out)
file(STRINGS ${BuildDepends_BINARY_DIR}/Project/external.out external_out)
if("${external_out}" STREQUAL "external original")
message(STATUS "external.out contains '${external_out}'")
else()
message(SEND_ERROR "Project did not initially build properly: "
"external.out contains '${external_out}'")
endif()
else()
message(SEND_ERROR "Project did not initially build properly: "
"external.out is missing")
endif()
message("Waiting 3 seconds...") message("Waiting 3 seconds...")
# any additional argument will cause ${bar} to wait forever # any additional argument will cause ${bar} to wait forever
execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out) execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out)
@ -191,6 +206,8 @@ if(TEST_LINK_DEPENDS)
file(WRITE ${TEST_LINK_DEPENDS} "2") file(WRITE ${TEST_LINK_DEPENDS} "2")
endif() endif()
file(WRITE ${BuildDepends_BINARY_DIR}/Project/external.in "external changed\n")
help_xcode_depends() help_xcode_depends()
message("Building project second time") message("Building project second time")
@ -294,3 +311,16 @@ else()
message(SEND_ERROR "Project did not rebuild properly. " message(SEND_ERROR "Project did not rebuild properly. "
"Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.") "Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.")
endif() endif()
if(EXISTS ${BuildDepends_BINARY_DIR}/Project/external.out)
file(STRINGS ${BuildDepends_BINARY_DIR}/Project/external.out external_out)
if("${external_out}" STREQUAL "external changed")
message(STATUS "external.out contains '${external_out}'")
else()
message(SEND_ERROR "Project did not rebuild properly: "
"external.out contains '${external_out}'")
endif()
else()
message(SEND_ERROR "Project did not rebuild properly: "
"external.out is missing")
endif()

View File

@ -139,3 +139,15 @@ add_custom_target(header_tgt DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/dir/header.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(ninjadep ninjadep.cpp) add_executable(ninjadep ninjadep.cpp)
add_dependencies(ninjadep header_tgt) add_dependencies(ninjadep header_tgt)
include(ExternalProject)
ExternalProject_Add(ExternalBuild
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/External
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/External
STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/External/Stamp
BUILD_ALWAYS 1
CMAKE_ARGS
-Dexternal_in=${CMAKE_CURRENT_BINARY_DIR}/external.in
-Dexternal_out=${CMAKE_CURRENT_BINARY_DIR}/external.out
INSTALL_COMMAND ""
)

View File

@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.0)
project(BuildDependsExternal NONE)
if(NOT DEFINED external_in)
message(FATAL_ERROR "Define external_in")
endif()
if(NOT DEFINED external_out)
message(FATAL_ERROR "Define external_out")
endif()
add_custom_command(
OUTPUT ${external_out}
COMMAND ${CMAKE_COMMAND} -E copy ${external_in} ${external_out}
DEPENDS ${external_in}
)
add_custom_target(drive ALL DEPENDS ${external_out})