diff options
author | Brad King <brad.king@kitware.com> | 2014-11-14 00:26:36 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-11-17 14:36:42 (GMT) |
commit | 557aef0b94c86d13e802e6e8e34a491304d7be2f (patch) | |
tree | a05394a276ea8c490cee08c0e1d38d5b207f1b6e /Tests/CustomCommandByproducts | |
parent | e15a7075b58aef6fe7b6eb56f810d0f33bc31feb (diff) | |
download | CMake-557aef0b94c86d13e802e6e8e34a491304d7be2f.zip CMake-557aef0b94c86d13e802e6e8e34a491304d7be2f.tar.gz CMake-557aef0b94c86d13e802e6e8e34a491304d7be2f.tar.bz2 |
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')
4 files changed, 31 insertions, 0 deletions
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; } |