ExternalProject: Add options to specify BYPRODUCTS (#14963)
The external project's build process may generate byproducts on which other rules in the driving project's build later depend. Provide a way for the driving project to specify what byproducts it expects to be made available by the custom commands that drive the external project.
This commit is contained in:
parent
e15a7075b5
commit
557aef0b94
|
@ -132,6 +132,9 @@ Create custom targets to build projects in external trees
|
|||
Use source dir for build dir
|
||||
``BUILD_ALWAYS 1``
|
||||
No stamp file, build step always runs
|
||||
``BUILD_BYPRODUCTS <file>...``
|
||||
Files that will be generated by the build command but may or may
|
||||
not have their modification time updated by subsequent builds.
|
||||
|
||||
Install step options are:
|
||||
|
||||
|
@ -234,6 +237,9 @@ Create custom targets to build projects in external trees
|
|||
Steps that depend on this step
|
||||
``DEPENDS <file>...``
|
||||
Files on which this step depends
|
||||
``BYPRODUCTS <file>...``
|
||||
Files that will be generated by this step but may or may not
|
||||
have their modification time updated by subsequent builds.
|
||||
``ALWAYS 1``
|
||||
No stamp file, step always runs
|
||||
``EXCLUDE_FROM_MAIN 1``
|
||||
|
@ -1409,6 +1415,9 @@ function(ExternalProject_Add_Step name step)
|
|||
# Dependencies on files.
|
||||
get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS)
|
||||
|
||||
# Byproducts of the step.
|
||||
get_property(byproducts TARGET ${name} PROPERTY _EP_${step}_BYPRODUCTS)
|
||||
|
||||
# Dependencies on steps.
|
||||
get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES)
|
||||
foreach(dependee IN LISTS dependees)
|
||||
|
@ -1466,6 +1475,7 @@ function(ExternalProject_Add_Step name step)
|
|||
|
||||
add_custom_command(
|
||||
OUTPUT ${stamp_file}
|
||||
BYPRODUCTS ${byproducts}
|
||||
COMMENT ${comment}
|
||||
COMMAND ${command}
|
||||
COMMAND ${touch}
|
||||
|
@ -2139,8 +2149,11 @@ function(_ep_add_build_command name)
|
|||
set(always 0)
|
||||
endif()
|
||||
|
||||
get_property(build_byproducts TARGET ${name} PROPERTY _EP_BUILD_BYPRODUCTS)
|
||||
|
||||
ExternalProject_Add_Step(${name} build
|
||||
COMMAND ${cmd}
|
||||
BYPRODUCTS ${build_byproducts}
|
||||
WORKING_DIRECTORY ${binary_dir}
|
||||
DEPENDEES configure
|
||||
ALWAYS ${always}
|
||||
|
|
|
@ -79,6 +79,29 @@ add_custom_command(OUTPUT timestamp8.txt
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/byproduct8.c.in
|
||||
)
|
||||
|
||||
# Generate the library file of an imported target as a byproduct
|
||||
# of an external project.
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
set(cfg /${CMAKE_CFG_INTDIR})
|
||||
else()
|
||||
set(cfg)
|
||||
endif()
|
||||
set(ExternalLibrary_LIBRARY
|
||||
${CMAKE_CURRENT_BINARY_DIR}/External-build${cfg}/${CMAKE_STATIC_LIBRARY_PREFIX}ExternalLibrary${CMAKE_STATIC_LIBRARY_SUFFIX}
|
||||
)
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(ExternalTarget
|
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/External"
|
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/External-build"
|
||||
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/External-build/root"
|
||||
DOWNLOAD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
BUILD_BYPRODUCTS "${ExternalLibrary_LIBRARY}"
|
||||
)
|
||||
add_library(ExternalLibrary STATIC IMPORTED)
|
||||
set_property(TARGET ExternalLibrary PROPERTY IMPORTED_LOCATION ${ExternalLibrary_LIBRARY})
|
||||
add_dependencies(ExternalLibrary ExternalTarget)
|
||||
|
||||
# Add an executable consuming all the byproducts.
|
||||
add_executable(CustomCommandByproducts
|
||||
CustomCommandByproducts.c
|
||||
|
@ -94,6 +117,7 @@ add_executable(CustomCommandByproducts
|
|||
add_dependencies(CustomCommandByproducts Producer2)
|
||||
add_dependencies(CustomCommandByproducts Producer3_4)
|
||||
add_dependencies(CustomCommandByproducts ProducerExe)
|
||||
target_link_libraries(CustomCommandByproducts ExternalLibrary)
|
||||
|
||||
if(CMAKE_GENERATOR STREQUAL "Ninja")
|
||||
add_custom_target(CheckNinja ALL
|
||||
|
|
|
@ -6,6 +6,7 @@ extern int byproduct5(void);
|
|||
extern int byproduct6(void);
|
||||
extern int byproduct7(void);
|
||||
extern int byproduct8(void);
|
||||
extern int ExternalLibrary(void);
|
||||
int main(void)
|
||||
{
|
||||
return (
|
||||
|
@ -17,5 +18,6 @@ int main(void)
|
|||
byproduct6() +
|
||||
byproduct7() +
|
||||
byproduct8() +
|
||||
ExternalLibrary() +
|
||||
0);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.1)
|
||||
project(External C)
|
||||
|
||||
add_library(ExternalLibrary STATIC ExternalLibrary.c)
|
|
@ -0,0 +1 @@
|
|||
int ExternalLibrary(void) { return 0; }
|
Loading…
Reference in New Issue