From 08cd7f6a02fcfb711f776a8083e53040b48aec8a Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 30 Jun 2019 20:50:08 -0700 Subject: Swift: support multithreaded compilation Query the number of logical CPUs available to enable parallel compilation for Swift. --- Help/manual/cmake-variables.7.rst | 1 + Help/variable/CMAKE_Swift_NUM_THREADS.rst | 8 ++++++++ Modules/CMakeSwiftInformation.cmake | 16 ++++++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 Help/variable/CMAKE_Swift_NUM_THREADS.rst diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index cc6a7d2..d4dbcca 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -98,6 +98,7 @@ Variables that Provide Information /variable/CMAKE_STATIC_LIBRARY_PREFIX /variable/CMAKE_STATIC_LIBRARY_SUFFIX /variable/CMAKE_Swift_MODULE_DIRECTORY + /variable/CMAKE_Swift_NUM_THREADS /variable/CMAKE_TOOLCHAIN_FILE /variable/CMAKE_TWEAK_VERSION /variable/CMAKE_VERBOSE_MAKEFILE diff --git a/Help/variable/CMAKE_Swift_NUM_THREADS.rst b/Help/variable/CMAKE_Swift_NUM_THREADS.rst new file mode 100644 index 0000000..cb33678 --- /dev/null +++ b/Help/variable/CMAKE_Swift_NUM_THREADS.rst @@ -0,0 +1,8 @@ +CMAKE_Swift_NUM_THREADS +----------------------- + +Number of threads for parallel compilation for Swift targets. + +This variable controls the number of parallel jobs that the swift driver creates +for building targets. If not specified, it will default to the number of +logical CPUs on the host. diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index f62f61b..0f84cce 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -49,11 +49,15 @@ if(NOT CMAKE_Swift_COMPILE_OBJECT) set(CMAKE_Swift_COMPILE_OBJECT ":") endif() +if(NOT CMAKE_Swift_NUM_THREADS MATCHES "^[0-9]+$") + cmake_host_system_information(RESULT CMAKE_Swift_NUM_THREADS QUERY NUMBER_OF_LOGICAL_CORES) +endif() + if(NOT CMAKE_Swift_CREATE_SHARED_LIBRARY) if(CMAKE_Swift_COMPILER_TARGET) - set(CMAKE_Swift_CREATE_SHARED_LIBRARY "${CMAKE_Swift_COMPILER} -target -output-file-map -incremental -emit-library -o -module-name -module-link-name -emit-module -emit-module-path -emit-dependencies ") + set(CMAKE_Swift_CREATE_SHARED_LIBRARY "${CMAKE_Swift_COMPILER} -target -output-file-map -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -o -module-name -module-link-name -emit-module -emit-module-path -emit-dependencies ") else() - set(CMAKE_Swift_CREATE_SHARED_LIBRARY "${CMAKE_Swift_COMPILER} -output-file-map -incremental -emit-library -o -module-name -module-link-name -emit-module -emit-module-path -emit-dependencies ") + set(CMAKE_Swift_CREATE_SHARED_LIBRARY "${CMAKE_Swift_COMPILER} -output-file-map -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -o -module-name -module-link-name -emit-module -emit-module-path -emit-dependencies ") endif() endif() @@ -63,17 +67,17 @@ endif() if(NOT CMAKE_Swift_LINK_EXECUTABLE) if(CMAKE_Swift_COMPILER_TARGET) - set(CMAKE_Swift_LINK_EXECUTABLE "${CMAKE_Swift_COMPILER} -target -output-file-map -incremental -emit-executable -o -emit-module -emit-module-path -emit-dependencies ") + set(CMAKE_Swift_LINK_EXECUTABLE "${CMAKE_Swift_COMPILER} -target -output-file-map -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-executable -o -emit-module -emit-module-path -emit-dependencies ") else() - set(CMAKE_Swift_LINK_EXECUTABLE "${CMAKE_Swift_COMPILER} -output-file-map -incremental -emit-executable -o -emit-module -emit-module-path -emit-dependencies ") + set(CMAKE_Swift_LINK_EXECUTABLE "${CMAKE_Swift_COMPILER} -output-file-map -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-executable -o -emit-module -emit-module-path -emit-dependencies ") endif() endif() if(NOT CMAKE_Swift_CREATE_STATIC_LIBRARY) if(CMAKE_Swift_COMPILER_TARGET) - set(CMAKE_Swift_CREATE_STATIC_LIBRARY "${CMAKE_Swift_COMPILER} -target -output-file-map -incremental -emit-library -static -o -module-name -module-link-name -emit-module -emit-module-path -emit-dependencies ") + set(CMAKE_Swift_CREATE_STATIC_LIBRARY "${CMAKE_Swift_COMPILER} -target -output-file-map -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o -module-name -module-link-name -emit-module -emit-module-path -emit-dependencies ") else() - set(CMAKE_Swift_CREATE_STATIC_LIBRARY "${CMAKE_Swift_COMPILER} -output-file-map -incremental -emit-library -static -o -module-name -module-link-name -emit-module -emit-module-path -emit-dependencies ") + set(CMAKE_Swift_CREATE_STATIC_LIBRARY "${CMAKE_Swift_COMPILER} -output-file-map -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o -module-name -module-link-name -emit-module -emit-module-path -emit-dependencies ") endif() set(CMAKE_Swift_ARCHIVE_CREATE " crs ") -- cgit v0.12