diff options
author | Chris Mahoney <chris.mahoney@kitware.com> | 2023-08-09 14:28:25 (GMT) |
---|---|---|
committer | Chris Mahoney <chris.mahoney@kitware.com> | 2023-08-15 12:21:30 (GMT) |
commit | bc43398e72be08b55d7df1f5195f0c3fc37506da (patch) | |
tree | 042e77e41a12cfeebf759b6aff2f09640c9177e4 /Tests | |
parent | 99be022428dcbf505cf889ff5d6f8de62821f652 (diff) | |
download | CMake-bc43398e72be08b55d7df1f5195f0c3fc37506da.zip CMake-bc43398e72be08b55d7df1f5195f0c3fc37506da.tar.gz CMake-bc43398e72be08b55d7df1f5195f0c3fc37506da.tar.bz2 |
ExternalProject: Enable Make Job Server with Explicit Build Command
Introduces `BUILD_JOB_SERVER_AWARE` option to `ExternalProject_Add` and
`JOB_SERVER_AWARE` to `ExternalProject_Add_Step`. When using an explicit
`BUILD_COMMAND` or `COMMAND`, the generated commands won't use `$(MAKE)`
thus failing to connect to the outer make's job server. These new
options enable explicit job server integration.
Co-authored-by: Brad King <brad.king@kitware.com>
Fixes: #16273
Diffstat (limited to 'Tests')
6 files changed, 71 insertions, 1 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 8562e2b..a4f6141 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -851,7 +851,7 @@ endif() if(CMake_TEST_RunCMake_ExternalProject_DOWNLOAD_SERVER_TIMEOUT) list(APPEND ExternalProject_ARGS -DDOWNLOAD_SERVER_TIMEOUT=${CMake_TEST_RunCMake_ExternalProject_DOWNLOAD_SERVER_TIMEOUT}) endif() -add_RunCMake_test(ExternalProject) +add_RunCMake_test(ExternalProject -DDETECT_JOBSERVER=$<TARGET_FILE:detect_jobserver>) add_RunCMake_test(FetchContent) add_RunCMake_test(FetchContent_find_package) set(CTestCommandLine_ARGS -DPython_EXECUTABLE=${Python_EXECUTABLE}) diff --git a/Tests/RunCMake/ExternalProject/DetectJobServer.cmake b/Tests/RunCMake/ExternalProject/DetectJobServer.cmake new file mode 100644 index 0000000..c6e1412 --- /dev/null +++ b/Tests/RunCMake/ExternalProject/DetectJobServer.cmake @@ -0,0 +1,16 @@ +include(ExternalProject) +ExternalProject_Add(Foo + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Foo + BUILD_COMMAND ${DETECT_JOBSERVER} "ep.txt" + BUILD_JOB_SERVER_AWARE 1 + INSTALL_COMMAND "" +) + +# Add a second step to test JOB_SERVER_AWARE +ExternalProject_Add_Step(Foo + second_step + COMMAND ${DETECT_JOBSERVER} "ep_second_step.txt" + DEPENDEES build + ALWAYS 1 + JOB_SERVER_AWARE 1 +) diff --git a/Tests/RunCMake/ExternalProject/Foo/CMakeLists.txt b/Tests/RunCMake/ExternalProject/Foo/CMakeLists.txt new file mode 100644 index 0000000..b38b173 --- /dev/null +++ b/Tests/RunCMake/ExternalProject/Foo/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.27) +project(Foo NONE) + +add_custom_target(drive ALL COMMAND ${CMAKE_COMMAND} -E true) diff --git a/Tests/RunCMake/ExternalProject/GNUMakeJobServerAware-check.cmake b/Tests/RunCMake/ExternalProject/GNUMakeJobServerAware-check.cmake new file mode 100644 index 0000000..55a9f0d --- /dev/null +++ b/Tests/RunCMake/ExternalProject/GNUMakeJobServerAware-check.cmake @@ -0,0 +1,16 @@ +set(BUILD_DIR "${RunCMake_BINARY_DIR}/GNUMakeJobServerAware-build") + +function(check target regex) + file(STRINGS ${BUILD_DIR}/${target} lines + REGEX ${regex} + ) + + list(LENGTH lines len) + if(len EQUAL 0) + message(FATAL_ERROR "Could not find matching lines '${regex}' in ${BUILD_DIR}/${target}") + endif() +endfunction() + +check("/CMakeFiles/Foo.dir/build.make" [[\+cd (/d )?"?.*"? && "?.*"? --build "?.*"?]]) +check("/CMakeFiles/Foo.dir/build.make" [[\+cd (/d )?"?.*"? && "?.*"? -E touch "?.*"?]]) +check("/CMakeFiles/Foo.dir/build.make" [[\+"?.*"? -E true]]) diff --git a/Tests/RunCMake/ExternalProject/GNUMakeJobServerAware.cmake b/Tests/RunCMake/ExternalProject/GNUMakeJobServerAware.cmake new file mode 100644 index 0000000..3f688ca --- /dev/null +++ b/Tests/RunCMake/ExternalProject/GNUMakeJobServerAware.cmake @@ -0,0 +1,16 @@ +include(ExternalProject) +ExternalProject_Add(Foo + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Foo + BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> + BUILD_JOB_SERVER_AWARE 1 + INSTALL_COMMAND "" +) + +# Add a second step to test JOB_SERVER_AWARE +ExternalProject_Add_Step(Foo + second_step + COMMAND ${CMAKE_COMMAND} -E true + DEPENDEES build + ALWAYS 1 + JOB_SERVER_AWARE 1 +) diff --git a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake index 4afdef8..ffaa46c 100644 --- a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake +++ b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake @@ -144,6 +144,24 @@ function(__ep_test_with_build_with_server testName) run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .) endfunction() +if(RunCMake_GENERATOR MATCHES "(MSYS|MinGW|Unix) Makefiles") + __ep_test_with_build(GNUMakeJobServerAware) +endif() + +function(__ep_test_jobserver) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/DetectJobServer-build) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake_with_options(DetectJobServer -DDETECT_JOBSERVER=${DETECT_JOBSERVER}) + run_cmake_command(DetectJobServer-clean ${CMAKE_COMMAND} --build . --target clean) + run_cmake_command(DetectJobServer-build ${CMAKE_COMMAND} --build . -j4) +endfunction() + +if(RunCMake_GENERATOR MATCHES "(MinGW|Unix) Makefiles") + __ep_test_jobserver() +endif() + __ep_test_with_build(MultiCommand) set(RunCMake_TEST_OUTPUT_MERGE 1) |