summaryrefslogtreecommitdiff
path: root/Tests/CustomCommandByproducts
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-11-13 19:26:36 -0500
committerBrad King <brad.king@kitware.com>2014-11-17 09:36:42 -0500
commit557aef0b94c86d13e802e6e8e34a491304d7be2f (patch)
treea05394a276ea8c490cee08c0e1d38d5b207f1b6e /Tests/CustomCommandByproducts
parente15a7075b58aef6fe7b6eb56f810d0f33bc31feb (diff)
downloadcmake-557aef0b94c86d13e802e6e8e34a491304d7be2f.tar.gz
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.
Diffstat (limited to 'Tests/CustomCommandByproducts')
-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
4 files changed, 31 insertions, 0 deletions
diff --git a/Tests/CustomCommandByproducts/CMakeLists.txt b/Tests/CustomCommandByproducts/CMakeLists.txt
index c39a5366a6..884f8c2316 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 d9db9e6f79..1916427b71 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 0000000000..feaa12ea4c
--- /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 0000000000..a1dacf0c16
--- /dev/null
+++ b/Tests/CustomCommandByproducts/External/ExternalLibrary.c
@@ -0,0 +1 @@
+int ExternalLibrary(void) { return 0; }