ExternalProject: support SOURCE_SUBDIR for BUILD_IN_SOURCE

This commit is contained in:
Ben Boeckel 2019-01-17 13:34:45 -05:00
parent 68e20f674a
commit c09ec79981
5 changed files with 49 additions and 2 deletions

View File

@ -0,0 +1,7 @@
ExternalProject-non-cmake-source-subdir
---------------------------------------
* The :module:`ExternalProject` module's ``ExternalProject_Add`` command
learned to apply ``SOURCE_SUBDIR`` when ``BUILD_IN_SOURCE`` is also used.
The ``BUILD_COMMAND`` is run in the given ``SOURCE_SUBDIR`` of the
``SOURCE_DIR``.

View File

@ -425,7 +425,9 @@ External Project Definition
can be used to point to an alternative directory within the source tree
to use as the top of the CMake source tree instead. This must be a
relative path and it will be interpreted as being relative to
``SOURCE_DIR``.
``SOURCE_DIR``. When ``BUILD_IN_SOURCE 1`` is specified, the
``BUILD_COMMAND`` is used to point to an alternative directory within the
source tree.
**Build Step Options:**
If the configure step assumed the external project uses CMake as its build
@ -1676,8 +1678,12 @@ function(_ep_set_directories name)
endif()
if(build_in_source)
get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
if(source_subdir)
set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}/${source_subdir}")
else()
set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}")
endif()
endif()
# Make the directories at CMake configure time *and* add a custom command
# to make them at build time. They need to exist at makefile generation

View File

@ -1635,6 +1635,18 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectSourceSubdir")
add_test(NAME ExternalProjectSourceSubdirNotCMake
COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/ExternalProjectSourceSubdirNotCMake"
"${CMake_BINARY_DIR}/Tests/ExternalProjectSourceSubdirNotCMake"
${build_generator_args}
--build-project ExternalProjectSourceSubdirNotCMake
--force-new-ctest-process
--build-options ${build_options}
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectSourceSubdirNotCMake")
add_test(ExternalProjectLocal ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/ExternalProjectLocal"

View File

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.6)
project(ExternalProjectSourceSubdirNotCMake NONE)
include(ExternalProject)
find_program(MAKE_EXECUTABLE
NAMES gmake make)
if (NOT MAKE_EXECUTABLE)
message("No `make` executable found; skipping")
return ()
endif ()
ExternalProject_Add(Example
SOURCE_SUBDIR subdir
BUILD_IN_SOURCE 1
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Example
CONFIGURE_COMMAND ""
BUILD_COMMAND "${MAKE_EXECUTABLE}"
INSTALL_COMMAND ""
)

View File

@ -0,0 +1,2 @@
all:
echo "complete"