summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/ExternalProject.cmake13
-rw-r--r--Tests/CustomCommandByproducts/CMakeLists.txt24
-rw-r--r--Tests/CustomCommandByproducts/CustomCommandByproducts.c2
-rw-r--r--Tests/CustomCommandByproducts/External/CMakeLists.txt4
-rw-r--r--Tests/CustomCommandByproducts/External/ExternalLibrary.c1
5 files changed, 44 insertions, 0 deletions
diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index 32f6d2c..e5616b1 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -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}
diff --git a/Tests/CustomCommandByproducts/CMakeLists.txt b/Tests/CustomCommandByproducts/CMakeLists.txt
index c39a536..884f8c2 100644
--- a/Tests/CustomCommandByproducts/CMakeLists.txt
+++ b/Tests/CustomCommandByproducts/CMakeLists.txt
@@ -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
diff --git a/Tests/CustomCommandByproducts/CustomCommandByproducts.c b/Tests/CustomCommandByproducts/CustomCommandByproducts.c
index d9db9e6..1916427 100644
--- a/Tests/CustomCommandByproducts/CustomCommandByproducts.c
+++ b/Tests/CustomCommandByproducts/CustomCommandByproducts.c
@@ -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);
}
diff --git a/Tests/CustomCommandByproducts/External/CMakeLists.txt b/Tests/CustomCommandByproducts/External/CMakeLists.txt
new file mode 100644
index 0000000..feaa12e
--- /dev/null
+++ b/Tests/CustomCommandByproducts/External/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.1)
+project(External C)
+
+add_library(ExternalLibrary STATIC ExternalLibrary.c)
diff --git a/Tests/CustomCommandByproducts/External/ExternalLibrary.c b/Tests/CustomCommandByproducts/External/ExternalLibrary.c
new file mode 100644
index 0000000..a1dacf0
--- /dev/null
+++ b/Tests/CustomCommandByproducts/External/ExternalLibrary.c
@@ -0,0 +1 @@
+int ExternalLibrary(void) { return 0; }