From 2d705801ed3fa83be2e7292a49785a73a6bf3c39 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 12 Mar 2025 14:59:53 -0700 Subject: [PATCH 1/9] build: remove cross-compilation support These can be controlled by the user external to the project. Remove this to simplify the rules. --- CMakeLists.txt | 9 --- cmake/modules/DispatchWindowsSupport.cmake | 74 ---------------------- 2 files changed, 83 deletions(-) delete mode 100644 cmake/modules/DispatchWindowsSupport.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ca03e573a..a690b39f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,15 +18,6 @@ if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") endif() if(CMAKE_SYSTEM_NAME STREQUAL Windows) - if(NOT MINGW) - include(DispatchWindowsSupport) - dispatch_windows_arch_spelling(${CMAKE_SYSTEM_PROCESSOR} DISPATCH_MSVC_ARCH) - dispatch_windows_include_for_arch(${DISPATCH_MSVC_ARCH} DISPATCH_INCLUDES) - include_directories(BEFORE SYSTEM ${DISPATCH_INCLUDES}) - dispatch_windows_lib_for_arch(${CMAKE_SYSTEM_PROCESSOR} DISPATCH_LIBDIR) - link_directories(${DISPATCH_LIBDIR}) - endif() - include(CheckCSourceCompiles) include(CheckSymbolExists) diff --git a/cmake/modules/DispatchWindowsSupport.cmake b/cmake/modules/DispatchWindowsSupport.cmake deleted file mode 100644 index 750b3be11..000000000 --- a/cmake/modules/DispatchWindowsSupport.cmake +++ /dev/null @@ -1,74 +0,0 @@ - -function(dispatch_windows_arch_spelling arch var) - if(${arch} STREQUAL i686) - set(${var} x86 PARENT_SCOPE) - elseif(${arch} STREQUAL x86_64 OR ${arch} STREQUAL AMD64) - set(${var} x64 PARENT_SCOPE) - elseif(${arch} STREQUAL armv7) - set(${var} arm PARENT_SCOPE) - elseif(${arch} STREQUAL aarch64 OR ${arch} STREQUAL ARM64) - set(${var} arm64 PARENT_SCOPE) - else() - message(FATAL_ERROR "do not know MSVC spelling for ARCH: `${arch}`") - endif() -endfunction() - -function(dispatch_verify_windows_environment_variables) - set(VCToolsInstallDir $ENV{VCToolsInstallDir}) - set(UniversalCRTSdkDir $ENV{UniversalCRTSdkDir}) - set(UCRTVersion $ENV{UCRTVersion}) - - if("${VCToolsInstallDir}" STREQUAL "") - message(SEND_ERROR "VCToolsInstallDir environment variable must be set") - endif() - if("${UniversalCRTSdkDir}" STREQUAL "") - message(SEND_ERROR "UniversalCRTSdkDir environment variable must be set") - endif() - if("${UCRTVersion}" STREQUAL "") - message(SEND_ERROR "UCRTVersion environment variable must be set") - endif() -endfunction() - -function(dispatch_windows_include_for_arch arch var) - dispatch_verify_windows_environment_variables() - - set(paths - "$ENV{VCToolsInstallDir}/include" - "$ENV{UniversalCRTSdkDir}/Include/$ENV{UCRTVersion}/ucrt" - "$ENV{UniversalCRTSdkDir}/Include/$ENV{UCRTVersion}/shared" - "$ENV{UniversalCRTSdkDir}/Include/$ENV{UCRTVersion}/um") - set(${var} ${paths} PARENT_SCOPE) -endfunction() - -function(dispatch_windows_lib_for_arch arch var) - dispatch_verify_windows_environment_variables() - dispatch_windows_arch_spelling(${arch} ARCH) - - set(paths) - if(${ARCH} STREQUAL x86) - list(APPEND paths "$ENV{VCToolsInstallDir}/Lib") - else() - list(APPEND paths "$ENV{VCToolsInstallDir}/Lib/${ARCH}") - endif() - list(APPEND paths - "$ENV{UniversalCRTSdkDir}/Lib/$ENV{UCRTVersion}/ucrt/${ARCH}" - "$ENV{UniversalCRTSdkDir}/Lib/$ENV{UCRTVersion}/um/${ARCH}") - set(${var} ${paths} PARENT_SCOPE) -endfunction() - -function(dispatch_windows_generate_sdk_vfs_overlay flags) - dispatch_verify_windows_environment_variables() - - get_filename_component(VCToolsInstallDir $ENV{VCToolsInstallDir} ABSOLUTE) - get_filename_component(UniversalCRTSdkDir $ENV{UniversalCRTSdkDir} ABSOLUTE) - set(UCRTVersion $ENV{UCRTVersion}) - - # TODO(compnerd) use a target to avoid re-creating this file all the time - configure_file("${PROJECT_SOURCE_DIR}/utils/WindowsSDKVFSOverlay.yaml.in" - "${PROJECT_BINARY_DIR}/windows-sdk-vfs-overlay.yaml" - @ONLY) - - set(${flags} - -ivfsoverlay;"${PROJECT_BINARY_DIR}/windows-sdk-vfs-overlay.yaml" - PARENT_SCOPE) -endfunction() From 31d3ff1f492cd744367590db2f0635c79a9738f9 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 12 Mar 2025 15:06:50 -0700 Subject: [PATCH 2/9] build: bump CMake minimum requirement and drop workaround CMake 3.19.0 fixed the compiler invocation requiring the local workaround. Match the runtimes CMake version requirement and drop the workaround. --- CMakeLists.txt | 6 +----- cmake/modules/ClangClCompileRules.cmake | 5 ----- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 cmake/modules/ClangClCompileRules.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a690b39f9..51b56ff4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.15.1) +cmake_minimum_required(VERSION 3.26...3.29) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) @@ -13,10 +13,6 @@ project(dispatch VERSION 1.3 LANGUAGES C CXX) -if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") - include(ClangClCompileRules) -endif() - if(CMAKE_SYSTEM_NAME STREQUAL Windows) include(CheckCSourceCompiles) include(CheckSymbolExists) diff --git a/cmake/modules/ClangClCompileRules.cmake b/cmake/modules/ClangClCompileRules.cmake deleted file mode 100644 index 0265d5ea7..000000000 --- a/cmake/modules/ClangClCompileRules.cmake +++ /dev/null @@ -1,5 +0,0 @@ - -# clang-cl interprets paths starting with /U as macro undefines, so we need to -# put a -- before the input file path to force it to be treated as a path. -string(REPLACE "-c " "-c -- " CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}") -string(REPLACE "-c " "-c -- " CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT}") From dab742db118d9cdb3edaebdf62a2238fca35991d Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 12 Mar 2025 15:13:06 -0700 Subject: [PATCH 3/9] build: simplify option handling slightly Reduce the verbosity in the generator expression to apply the compile flags to C or C++ code only. --- CMakeLists.txt | 20 +-- cmake/modules/DispatchCompilerWarnings.cmake | 138 +++++++++---------- 2 files changed, 79 insertions(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51b56ff4a..f01a50fa8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,7 +232,7 @@ else() set(USE_MACH_SEM 0) endif() if(CMAKE_SYSTEM_NAME STREQUAL Windows) - add_compile_definitions($<$,$>:USE_WIN32_SEM>) + add_compile_definitions($<$:USE_WIN32_SEM>) endif() check_library_exists(pthread sem_init "" USE_POSIX_SEM) # NOTE: android has not always provided a libpthread, but uses the pthreads API @@ -262,7 +262,7 @@ check_symbol_exists(VQ_FREE_SPACE_CHANGE "sys/mount.h" HAVE_DECL_VQ_FREE_SPACE_C check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY) check_symbol_exists(program_invocation_name "errno.h" HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME) if (HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME) - add_compile_definitions($<$,$>:_GNU_SOURCE=1>) + add_compile_definitions($<$:_GNU_SOURCE=1>) endif() check_symbol_exists(__printflike "bsd/sys/cdefs.h" HAVE_PRINTFLIKE) @@ -271,7 +271,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Android) endif() if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - add_compile_definitions($<$,$>:_WITH_DPRINTF>) + add_compile_definitions($<$:_WITH_DPRINTF>) endif() if(ENABLE_DTRACE) @@ -282,9 +282,9 @@ if(ENABLE_DTRACE) endif() if(dtrace_EXECUTABLE) - add_compile_definitions($<$,$>:DISPATCH_USE_DTRACE=1>) + add_compile_definitions($<$:DISPATCH_USE_DTRACE=1>) else() - add_compile_definitions($<$,$>:DISPATCH_USE_DTRACE=0>) + add_compile_definitions($<$:DISPATCH_USE_DTRACE=0>) endif() find_program(leaks_EXECUTABLE leaks) @@ -294,16 +294,16 @@ endif() if(CMAKE_SYSTEM_NAME STREQUAL Darwin) - add_compile_options($<$,$>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap> - $<$,$>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/private/darwin/module.modulemap>) + add_compile_options($<:$:-fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap> + $<:$:-fmodule-map-file=${PROJECT_SOURCE_DIR}/private/darwin/module.modulemap>) else() - add_compile_options($<$,$>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap> - $<$,$>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/private/generic/module.modulemap>) + add_compile_options($<$:-fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap> + $<$:-fmodule-map-file=${PROJECT_SOURCE_DIR}/private/generic/module.modulemap>) endif() configure_file("${PROJECT_SOURCE_DIR}/cmake/config.h.in" "${PROJECT_BINARY_DIR}/config/config_ac.h") -add_compile_definitions($<$,$>:HAVE_CONFIG_H>) +add_compile_definitions($<$:HAVE_CONFIG_H>) if(ENABLE_SWIFT) diff --git a/cmake/modules/DispatchCompilerWarnings.cmake b/cmake/modules/DispatchCompilerWarnings.cmake index cd71f36e5..3fd1b3ddf 100644 --- a/cmake/modules/DispatchCompilerWarnings.cmake +++ b/cmake/modules/DispatchCompilerWarnings.cmake @@ -4,81 +4,81 @@ if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") elseif(WIN32) # Tareting Windows but using a non-MSVC compiler. Set -fms-extensions # so that we can use __popcnt64 - add_compile_options($<$,$>:-fms-extensions>) + add_compile_options($<$:-fms-extensions>) else() - add_compile_options($<$,$>:-Werror>) - add_compile_options($<$,$>:-Wall>) - add_compile_options($<$,$>:-Wextra>) + add_compile_options($<$:-Werror>) + add_compile_options($<$:-Wall>) + add_compile_options($<$:-Wextra>) - add_compile_options($<$,$>:-Warray-bounds-pointer-arithmetic>) - add_compile_options($<$,$>:-Wassign-enum>) - add_compile_options($<$,$>:-Watomic-properties>) - add_compile_options($<$,$>:-Wcomma>) - add_compile_options($<$,$>:-Wconditional-uninitialized>) - add_compile_options($<$,$>:-Wconversion>) - add_compile_options($<$,$>:-Wcovered-switch-default>) - add_compile_options($<$,$>:-Wdate-time>) - add_compile_options($<$,$>:-Wdeprecated>) - add_compile_options($<$,$>:-Wdocumentation>) - add_compile_options($<$,$>:-Wdouble-promotion>) - add_compile_options($<$,$>:-Wduplicate-enum>) - add_compile_options($<$,$>:-Wexpansion-to-defined>) - add_compile_options($<$,$>:-Wfloat-equal>) - add_compile_options($<$,$>:-Widiomatic-parentheses>) - add_compile_options($<$,$>:-Winfinite-recursion>) - add_compile_options($<$,$>:-Wmissing-prototypes>) - add_compile_options($<$,$>:-Wnewline-eof>) - add_compile_options($<$,$>:-Wnullable-to-nonnull-conversion>) - add_compile_options($<$,$>:-Wobjc-interface-ivars>) - add_compile_options($<$,$>:-Wover-aligned>) - add_compile_options($<$,$>:-Wpacked>) - add_compile_options($<$,$>:-Wpointer-arith>) - add_compile_options($<$,$>:-Wselector>) - add_compile_options($<$,$>:-Wshadow>) - add_compile_options($<$,$>:-Wshorten-64-to-32>) - add_compile_options($<$,$>:-Wsign-conversion>) - add_compile_options($<$,$>:-Wstatic-in-inline>) - add_compile_options($<$,$>:-Wsuper-class-method-mismatch>) - add_compile_options($<$,$>:-Wswitch>) - add_compile_options($<$,$>:-Wunguarded-availability>) - add_compile_options($<$,$>:-Wunreachable-code>) - add_compile_options($<$,$>:-Wunused>) + add_compile_options($<$:-Warray-bounds-pointer-arithmetic>) + add_compile_options($<$:-Wassign-enum>) + add_compile_options($<$:-Watomic-properties>) + add_compile_options($<$:-Wcomma>) + add_compile_options($<$:-Wconditional-uninitialized>) + add_compile_options($<$:-Wconversion>) + add_compile_options($<$:-Wcovered-switch-default>) + add_compile_options($<$:-Wdate-time>) + add_compile_options($<$:-Wdeprecated>) + add_compile_options($<$:-Wdocumentation>) + add_compile_options($<$:-Wdouble-promotion>) + add_compile_options($<$:-Wduplicate-enum>) + add_compile_options($<$:-Wexpansion-to-defined>) + add_compile_options($<$:-Wfloat-equal>) + add_compile_options($<$:-Widiomatic-parentheses>) + add_compile_options($<$:-Winfinite-recursion>) + add_compile_options($<$:-Wmissing-prototypes>) + add_compile_options($<$:-Wnewline-eof>) + add_compile_options($<$:-Wnullable-to-nonnull-conversion>) + add_compile_options($<$:-Wobjc-interface-ivars>) + add_compile_options($<$:-Wover-aligned>) + add_compile_options($<$:-Wpacked>) + add_compile_options($<$:-Wpointer-arith>) + add_compile_options($<$:-Wselector>) + add_compile_options($<$:-Wshadow>) + add_compile_options($<$:-Wshorten-64-to-32>) + add_compile_options($<$:-Wsign-conversion>) + add_compile_options($<$:-Wstatic-in-inline>) + add_compile_options($<$:-Wsuper-class-method-mismatch>) + add_compile_options($<$:-Wswitch>) + add_compile_options($<$:-Wunguarded-availability>) + add_compile_options($<$:-Wunreachable-code>) + add_compile_options($<$:-Wunused>) - add_compile_options($<$,$>:-Wno-unknown-warning-option>) - add_compile_options($<$,$>:-Wno-trigraphs>) - add_compile_options($<$,$>:-Wno-four-char-constants>) - add_compile_options($<$,$>:-Wno-disabled-macro-expansion>) - add_compile_options($<$,$>:-Wno-pedantic>) - add_compile_options($<$,$>:-Wno-bad-function-cast>) - add_compile_options($<$,$>:-Wno-c++-compat>) - add_compile_options($<$,$>:-Wno-c++98-compat>) - add_compile_options($<$,$>:-Wno-c++98-compat-pedantic>) - add_compile_options($<$,$>:-Wno-cast-align>) - add_compile_options($<$,$>:-Wno-cast-qual>) - add_compile_options($<$,$>:-Wno-documentation-unknown-command>) - add_compile_options($<$,$>:-Wno-format-nonliteral>) - add_compile_options($<$,$>:-Wno-missing-variable-declarations>) - add_compile_options($<$,$>:-Wno-old-style-cast>) - add_compile_options($<$,$>:-Wno-padded>) - add_compile_options($<$,$>:-Wno-reserved-id-macro>) - add_compile_options($<$,$>:-Wno-shift-sign-overflow>) - add_compile_options($<$,$>:-Wno-undef>) - add_compile_options($<$,$>:-Wno-unreachable-code-aggressive>) - add_compile_options($<$,$>:-Wno-unused-macros>) - add_compile_options($<$,$>:-Wno-used-but-marked-unused>) - add_compile_options($<$,$>:-Wno-void-pointer-to-int-cast>) - add_compile_options($<$,$>:-Wno-vla>) + add_compile_options($<$:-Wno-unknown-warning-option>) + add_compile_options($<$:-Wno-trigraphs>) + add_compile_options($<$:-Wno-four-char-constants>) + add_compile_options($<$:-Wno-disabled-macro-expansion>) + add_compile_options($<$:-Wno-pedantic>) + add_compile_options($<$:-Wno-bad-function-cast>) + add_compile_options($<$:-Wno-c++-compat>) + add_compile_options($<$:-Wno-c++98-compat>) + add_compile_options($<$:-Wno-c++98-compat-pedantic>) + add_compile_options($<$:-Wno-cast-align>) + add_compile_options($<$:-Wno-cast-qual>) + add_compile_options($<$:-Wno-documentation-unknown-command>) + add_compile_options($<$:-Wno-format-nonliteral>) + add_compile_options($<$:-Wno-missing-variable-declarations>) + add_compile_options($<$:-Wno-old-style-cast>) + add_compile_options($<$:-Wno-padded>) + add_compile_options($<$:-Wno-reserved-id-macro>) + add_compile_options($<$:-Wno-shift-sign-overflow>) + add_compile_options($<$:-Wno-undef>) + add_compile_options($<$:-Wno-unreachable-code-aggressive>) + add_compile_options($<$:-Wno-unused-macros>) + add_compile_options($<$:-Wno-used-but-marked-unused>) + add_compile_options($<$:-Wno-void-pointer-to-int-cast>) + add_compile_options($<$:-Wno-vla>) if(CMAKE_SYSTEM_NAME STREQUAL Android) - add_compile_options($<$,$>:-Wno-incompatible-function-pointer-types>) - add_compile_options($<$,$>:-Wno-implicit-function-declaration>) - add_compile_options($<$,$>:-Wno-conversion>) - add_compile_options($<$,$>:-Wno-int-conversion>) - add_compile_options($<$,$>:-Wno-shorten-64-to-32>) + add_compile_options($<$:-Wno-incompatible-function-pointer-types>) + add_compile_options($<$:-Wno-implicit-function-declaration>) + add_compile_options($<$:-Wno-conversion>) + add_compile_options($<$:-Wno-int-conversion>) + add_compile_options($<$:-Wno-shorten-64-to-32>) endif() - add_compile_options($<$,$>:-Wno-error=assign-enum>) + add_compile_options($<$:-Wno-error=assign-enum>) # Should re-enable after rdar://133498289 is fixed (ie. fixing the one mismatched cast in apply.c) - add_compile_options($<$,$>:-Wno-cast-function-type-mismatch>) - add_compile_options($<$,$>:-Wno-error=unknown-warning-option>) + add_compile_options($<$:-Wno-cast-function-type-mismatch>) + add_compile_options($<$:-Wno-error=unknown-warning-option>) endif() From afe36b71647c3cf6cfb191b2e72504ccf2302223 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 12 Mar 2025 15:16:51 -0700 Subject: [PATCH 4/9] build: bring `config.h.in` into sync with checked in copy `HAVE_STRLCPY` was added to the static configuration but not the dynamic configuration. Update the template for this. --- cmake/config.h.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/config.h.in b/cmake/config.h.in index 2896a2083..27737c991 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -257,3 +257,6 @@ /* Define if using Darwin $NOCANCEL */ #cmakedefine __DARWIN_NON_CANCELABLE + +/* Define to 1 if you have the `strlcpy` function. */ +#cmakedefine01 HAVE_STRLCPY From 09c2adecd86ab85991b1a9196d11f5386c66691b Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 12 Mar 2025 15:37:25 -0700 Subject: [PATCH 5/9] build: simplify system checks (NFC) CMake 3.25 introduced a more consistent way to check what system is being built for. Adopt that uniformly through the build to make it easier to understand. --- CMakeLists.txt | 18 +++++++++--------- cmake/modules/DispatchCompilerWarnings.cmake | 2 +- cmake/modules/DispatchSanitization.cmake | 2 +- dispatch/CMakeLists.txt | 2 +- src/BlocksRuntime/CMakeLists.txt | 2 +- src/CMakeLists.txt | 14 +++++++------- src/swift/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 9 ++++----- 8 files changed, 25 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f01a50fa8..b5e77707f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ project(dispatch VERSION 1.3 LANGUAGES C CXX) -if(CMAKE_SYSTEM_NAME STREQUAL Windows) +if(WIN32) include(CheckCSourceCompiles) include(CheckSymbolExists) @@ -132,7 +132,7 @@ set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR}) option(ENABLE_DTRACE "enable dtrace support" "") -if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD) +if(APPLE OR BSD) set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT OFF) else() set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON) @@ -176,7 +176,7 @@ if(__BUILTIN_TRAP) set(HAVE_NORETURN_BUILTIN_TRAP 1) endif() -if(NOT CMAKE_SYSTEM_NAME STREQUAL Android) +if(NOT ANDROID) find_package(LibRT) endif() @@ -231,12 +231,12 @@ if(HAVE_MACH) else() set(USE_MACH_SEM 0) endif() -if(CMAKE_SYSTEM_NAME STREQUAL Windows) +if(WIN32) add_compile_definitions($<$:USE_WIN32_SEM>) endif() check_library_exists(pthread sem_init "" USE_POSIX_SEM) # NOTE: android has not always provided a libpthread, but uses the pthreads API -if(CMAKE_SYSTEM_NAME STREQUAL Android) +if(ANDROID) set(USE_POSIX_SEM 1) endif() @@ -266,11 +266,11 @@ if (HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME) endif() check_symbol_exists(__printflike "bsd/sys/cdefs.h" HAVE_PRINTFLIKE) -if(CMAKE_SYSTEM_NAME STREQUAL Android) +if(ANDROID) set(ENABLE_DTRACE_DEFAULT OFF) endif() -if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) +if(BSD) add_compile_definitions($<$:_WITH_DPRINTF>) endif() @@ -293,7 +293,7 @@ if(leaks_EXECUTABLE) endif() -if(CMAKE_SYSTEM_NAME STREQUAL Darwin) +if(APPLE) add_compile_options($<:$:-fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap> $<:$:-fmodule-map-file=${PROJECT_SOURCE_DIR}/private/darwin/module.modulemap>) else() @@ -308,7 +308,7 @@ add_compile_definitions($<$:HAVE_CONFIG_H>) if(ENABLE_SWIFT) if(NOT SWIFT_SYSTEM_NAME) - if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + if(APPLE) set(SWIFT_SYSTEM_NAME macosx) else() set(SWIFT_SYSTEM_NAME "$") diff --git a/cmake/modules/DispatchCompilerWarnings.cmake b/cmake/modules/DispatchCompilerWarnings.cmake index 3fd1b3ddf..b10644410 100644 --- a/cmake/modules/DispatchCompilerWarnings.cmake +++ b/cmake/modules/DispatchCompilerWarnings.cmake @@ -69,7 +69,7 @@ else() add_compile_options($<$:-Wno-void-pointer-to-int-cast>) add_compile_options($<$:-Wno-vla>) - if(CMAKE_SYSTEM_NAME STREQUAL Android) + if(ANDROID) add_compile_options($<$:-Wno-incompatible-function-pointer-types>) add_compile_options($<$:-Wno-implicit-function-declaration>) add_compile_options($<$:-Wno-conversion>) diff --git a/cmake/modules/DispatchSanitization.cmake b/cmake/modules/DispatchSanitization.cmake index a0641f524..b5c6ee64f 100644 --- a/cmake/modules/DispatchSanitization.cmake +++ b/cmake/modules/DispatchSanitization.cmake @@ -2,7 +2,7 @@ set(DISPATCH_USE_SANITIZER "" CACHE STRING "Define the sanitizer used to build binaries and tests.") -if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND DISPATCH_USE_SANITIZER) +if(APPLE AND DISPATCH_USE_SANITIZER) message(FATAL_ERROR "building libdispatch with sanitization is not supported on Darwin") endif() diff --git a/dispatch/CMakeLists.txt b/dispatch/CMakeLists.txt index a7f5fc306..49258cea1 100644 --- a/dispatch/CMakeLists.txt +++ b/dispatch/CMakeLists.txt @@ -1,5 +1,5 @@ -if(CMAKE_SYSTEM_NAME STREQUAL Darwin) +if(APPLE) set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap) elseif(BUILD_SHARED_LIBS) set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap) diff --git a/src/BlocksRuntime/CMakeLists.txt b/src/BlocksRuntime/CMakeLists.txt index 945e87a7e..2e509ff4e 100644 --- a/src/BlocksRuntime/CMakeLists.txt +++ b/src/BlocksRuntime/CMakeLists.txt @@ -2,7 +2,7 @@ add_library(BlocksRuntime data.c runtime.c) -if(CMAKE_SYSTEM_NAME STREQUAL Windows) +if(WIN32) target_sources(BlocksRuntime PRIVATE BlocksRuntime.def) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 320b6fcdc..48ef6cbb0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ -if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) +if(NOT APPLE) add_subdirectory(BlocksRuntime) endif() @@ -57,7 +57,7 @@ add_library(dispatch shims/yield.c shims/yield.h) -if(CMAKE_SYSTEM_NAME STREQUAL Windows) +if(WIN32) target_sources(dispatch PRIVATE shims/generic_sys_queue.h shims/generic_win_stubs.c @@ -103,11 +103,11 @@ target_include_directories(dispatch PUBLIC target_include_directories(dispatch PRIVATE ${PROJECT_SOURCE_DIR}/private) -if(CMAKE_SYSTEM_NAME STREQUAL Windows) +if(WIN32) target_compile_definitions(dispatch PRIVATE _CRT_NONSTDC_NO_WARNINGS _CRT_SECURE_NO_WARNINGS) -elseif(CMAKE_SYSTEM_NAME STREQUAL Android) +elseif(ANDROID) target_compile_options(dispatch PRIVATE -U_GNU_SOURCE) endif() @@ -157,7 +157,7 @@ target_link_libraries(dispatch PRIVATE Threads::Threads) target_link_libraries(dispatch PUBLIC BlocksRuntime::BlocksRuntime) -if(CMAKE_SYSTEM_NAME STREQUAL Windows) +if(WIN32) target_link_libraries(dispatch PRIVATE AdvAPI32 ShLwApi @@ -166,7 +166,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows) synchronization) endif() -if(CMAKE_SYSTEM_NAME STREQUAL Darwin) +if(APPLE) set_property(TARGET dispatch APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker -compatibility_version -Xlinker 1" "-Xlinker -current_version -Xlinker ${VERSION}" @@ -174,7 +174,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin) "-Xlinker -alias_list -Xlinker ${PROJECT_SOURCE_DIR}/xcodeconfig/libdispatch.aliases") endif() -if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows") +if(NOT APPLE) set_target_properties(dispatch PROPERTIES INSTALL_RPATH "$ORIGIN") endif() diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt index 4fffc84a4..0280f3811 100644 --- a/src/swift/CMakeLists.txt +++ b/src/swift/CMakeLists.txt @@ -48,7 +48,7 @@ if(NOT BUILD_SHARED_LIBS) install(TARGETS DispatchStubs EXPORT dispatchExports DESTINATION ${INSTALL_TARGET_DIR}) -elseif(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows") +elseif(NOT DARWIN AND NOT WIN32) target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath") set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN") endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0176a062b..e6dcf943f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ -if(CMAKE_SYSTEM_NAME STREQUAL Windows) +if(WIN32) execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_directory "${PROJECT_SOURCE_DIR}/private" "${CMAKE_CURRENT_BINARY_DIR}/dispatch") @@ -15,7 +15,7 @@ else() "${CMAKE_CURRENT_BINARY_DIR}/leaks-wrapper") endif() -if(CMAKE_SYSTEM_NAME STREQUAL Linux) +if(LINUX) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lrt") endif() @@ -92,8 +92,7 @@ function(add_unit_test name) # fails with the multiple definition errors seen in android/ndk#176, so I # pulled in this workaround noted there. The tests build and run with this # flag applied. - if(NOT BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL Android AND - CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a) + if(NOT BUILD_SHARED_LIBS AND ANDROID AND CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a) target_link_options(${name} PRIVATE "LINKER:--allow-multiple-definition") endif() target_link_libraries(${name} @@ -162,7 +161,7 @@ if(EXTENDED_TEST_SUITE) endif() # add C tests for platform-specific functionality when applicable -if(CMAKE_SYSTEM_NAME STREQUAL Darwin) +if(APPLE) list(APPEND DISPATCH_C_TESTS deadname proc From 78285e059805ce034047276dee686fc8f5633db3 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 12 Mar 2025 16:27:03 -0700 Subject: [PATCH 6/9] build: adopt current best practices for installing modules This introduces the new option to control installation to a nested subdirectory. It also converts the current installation into a thick module format. --- CMakeLists.txt | 19 ++++++------- cmake/modules/PlatformInfo.cmake | 48 ++++++++++++++++++++++++++++++++ cmake/modules/SwiftSupport.cmake | 41 --------------------------- src/BlocksRuntime/CMakeLists.txt | 4 +-- src/CMakeLists.txt | 4 +-- src/swift/CMakeLists.txt | 35 ++++++++++++++--------- 6 files changed, 82 insertions(+), 69 deletions(-) create mode 100644 cmake/modules/PlatformInfo.cmake delete mode 100644 cmake/modules/SwiftSupport.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b5e77707f..475ebd896 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,7 +118,6 @@ include(DispatchAppleOptions) include(DispatchSanitization) include(DispatchCompilerWarnings) include(DTrace) -include(SwiftSupport) # NOTE(abdulras) this is the CMake supported way to control whether we generate # shared or static libraries. This impacts the behaviour of `add_library` in @@ -157,6 +156,14 @@ option(INSTALL_PRIVATE_HEADERS "installs private headers in the same location as option(ENABLE_SWIFT "enable libdispatch swift overlay" OFF) if(ENABLE_SWIFT) enable_language(Swift) + + include(PlatformInfo) + + option(Dispatch_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" NO) + set(Dispatch_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${Dispatch_PLATFORM_SUBDIR}$<$:/${Dispatch_ARCH_SUBDIR}>") + set(Dispatch_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${Dispatch_PLATFORM_SUBDIR}$<$:/${Dispatch_ARCH_SUBDIR}>") +else() + set(Dispatch_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}) endif() option(ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via _Thread_local" ON) @@ -307,20 +314,10 @@ add_compile_definitions($<$:HAVE_CONFIG_H>) if(ENABLE_SWIFT) - if(NOT SWIFT_SYSTEM_NAME) - if(APPLE) - set(SWIFT_SYSTEM_NAME macosx) - else() - set(SWIFT_SYSTEM_NAME "$") - endif() - endif() - - set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${SWIFT_SYSTEM_NAME}" CACHE PATH "Path where the libraries will be installed") set(INSTALL_DISPATCH_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch") set(INSTALL_BLOCK_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime") set(INSTALL_OS_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/os" CACHE PATH "Path where the os/ headers will be installed") else() - set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Path where the libraries will be installed") set(INSTALL_DISPATCH_HEADERS_DIR "include/dispatch" CACHE PATH "Path where the headers will be installed") set(INSTALL_BLOCK_HEADERS_DIR "include" CACHE PATH "Path where the headers will be installed for the blocks runtime") set(INSTALL_OS_HEADERS_DIR "include/os" CACHE PATH "Path where the headers will be installed") diff --git a/cmake/modules/PlatformInfo.cmake b/cmake/modules/PlatformInfo.cmake new file mode 100644 index 000000000..f007b7fa4 --- /dev/null +++ b/cmake/modules/PlatformInfo.cmake @@ -0,0 +1,48 @@ +# This source file is part of the Swift.org open source project +# +# Copyright (c) 2025 Apple Inc. and the Swift project authors +# Licensed under Apache License v2.0 with Runtime Library Exception +# +# See http://swift.org/LICENSE.txt for license information +# See http://swift.org/CONTRIBUTORS.txt for Swift project authors + +set(print_target_info_invocation "${CMAKE_Swift_COMPILER}" -print-target-info) +if(CMAKE_Swift_COMPILER_TARGET) + list(APPEND print_target_info_invocation -target ${CMAKE_Swift_COMPILER_TARGET}) +endif() +execute_process(COMMAND ${print_target_info_invocation} OUTPUT_VARIABLE target_info_json) +message(CONFIGURE_LOG "Swift Target Info: ${print_target_info_invocation}\n" +"${target_info_json}") + +if(NOT Dispatch_MODULE_TRIPLE) + string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple") + set(Dispatch_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used for installed swift{doc,module,interface} files") + mark_as_advanced(Dispatch_MODULE_TRIPLE) + + message(CONFIGURE_LOG "Swift Module Triple: ${module_triple}") +endif() + +if(NOT Dispatch_PLATFORM_SUBDIR) + string(JSON platform GET "${target_info_json}" "target" "platform") + if(NOT platform) + if(NOT SWIFT_SYSTEM_NAME) + if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(platform macosx) + else() + set(platform $) + endif() + endif() + endif() + set(Dispatch_PLATFORM_SUBDIR "${platform}" CACHE STRING "Platform name used for installed swift{doc,module,interface} files") + mark_as_advanced(Dispatch_PLATFORM_SUBDIR) + + message(CONFIGURE_LOG "Swift Platform: ${platform}") +endif() + +if(NOT Dispatch_ARCH_SUBDIR) + string(JSON arch GET "${target_info_json}" "target" "arch") + set(Dispatch_ARCH_SUBDIR "${arch}" CACHE STRING "Architecture used for setting the architecture subdirectory") + mark_as_advanced(Dispatch_ARCH_SUBDIR) + + message(CONFIGURE_LOG "Swift Architecture: ${arch}") +endif() diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake deleted file mode 100644 index a42b61e40..000000000 --- a/cmake/modules/SwiftSupport.cmake +++ /dev/null @@ -1,41 +0,0 @@ - -# Returns the current achitecture name in a variable -# -# Usage: -# get_swift_host_arch(result_var_name) -# -# If the current architecture is supported by Swift, sets ${result_var_name} -# with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR. -function(get_swift_host_arch result_var_name) - if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") - set("${result_var_name}" "x86_64" PARENT_SCOPE) - elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64|ARM64") - if(CMAKE_SYSTEM_NAME MATCHES Darwin) - set("${result_var_name}" "arm64" PARENT_SCOPE) - else() - set("${result_var_name}" "aarch64" PARENT_SCOPE) - endif() - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64") - set("${result_var_name}" "powerpc64" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le") - set("${result_var_name}" "powerpc64le" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x") - set("${result_var_name}" "s390x" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l") - set("${result_var_name}" "armv6" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a") - set("${result_var_name}" "armv7" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l") - set("${result_var_name}" "armv7" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") - set("${result_var_name}" "x86_64" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64") - set("${result_var_name}" "itanium" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86") - set("${result_var_name}" "i686" PARENT_SCOPE) - elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686") - set("${result_var_name}" "i686" PARENT_SCOPE) - else() - message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}") - endif() -endfunction() diff --git a/src/BlocksRuntime/CMakeLists.txt b/src/BlocksRuntime/CMakeLists.txt index 2e509ff4e..5308fe14f 100644 --- a/src/BlocksRuntime/CMakeLists.txt +++ b/src/BlocksRuntime/CMakeLists.txt @@ -37,6 +37,6 @@ endif() set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS BlocksRuntime) install(TARGETS BlocksRuntime EXPORT dispatchExports - ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} - LIBRARY DESTINATION ${INSTALL_TARGET_DIR} + ARCHIVE DESTINATION ${Dispatch_INSTALL_LIBDIR} + LIBRARY DESTINATION ${Dispatch_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 48ef6cbb0..27980e92d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -189,6 +189,6 @@ endif() set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS dispatch) install(TARGETS dispatch EXPORT dispatchExports - ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} - LIBRARY DESTINATION ${INSTALL_TARGET_DIR} + ARCHIVE DESTINATION ${Dispatch_INSTALL_LIBDIR} + LIBRARY DESTINATION ${Dispatch_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt index 0280f3811..6c9bb1445 100644 --- a/src/swift/CMakeLists.txt +++ b/src/swift/CMakeLists.txt @@ -31,24 +31,33 @@ target_link_libraries(swiftDispatch PRIVATE BlocksRuntime::BlocksRuntime) target_link_libraries(swiftDispatch PUBLIC dispatch) +if(NOT DARWIN AND NOT WIN32) + target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath") + set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN") +endif() -get_swift_host_arch(swift_arch) -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule - ${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc - DESTINATION ${INSTALL_TARGET_DIR}/${swift_arch}) -set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch) install(TARGETS swiftDispatch EXPORT dispatchExports - ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} - LIBRARY DESTINATION ${INSTALL_TARGET_DIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + ARCHIVE DESTINATION "${Dispatch_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${Dispatch_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +INSTALL(FILES $/$.swiftdoc + DESTINATION ${Dispatch_INSTALL_SWIFTMODULEDIR}/$.swiftmodule + RENAME ${Dispatch_MODULE_TRIPLE}.swiftdoc) +# INSTALL(FILES $/$.swiftinterface +# DESTINATION ${Dispatch_INSTALL_SWIFTMODULEDIR}/$.swiftmodule +# RENAME ${Dispach_MODULE_TRIPLE}.swiftinterface) +INSTALL(FILES $/$.swiftmodule + DESTINATION ${Dispatch_INSTALL_SWIFTMODULEDIR}/$.swiftmodule + RENAME ${Dispatch_MODULE_TRIPLE}.swiftmodule) +INSTALL(FILES $/$.swiftsourceinfo + DESTINATION ${Dispatch_INSTALL_SWIFTMODULEDIR}/$.swiftmodule + RENAME ${Dispatch_MODULE_TRIPLE}.swiftsourceinfo) if(NOT BUILD_SHARED_LIBS) set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS DispatchStubs) install(TARGETS DispatchStubs EXPORT dispatchExports - DESTINATION ${INSTALL_TARGET_DIR}) -elseif(NOT DARWIN AND NOT WIN32) - target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath") - set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN") + DESTINATION ${Dispatch_INSTALL_LIBDIR}) endif() + +set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch) From ec9bb3457a583f6599b73b2b42e2e9d2d7b71f64 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 12 Mar 2025 22:16:02 -0700 Subject: [PATCH 7/9] build: remove outdated TODO, limit build, install The DispatchStubs are now used only for the ObjC codepath and no longer need to be included in the regular build. Simply remove the extra library unless Objective-C support is enabled. --- dispatch/generic_static/module.modulemap | 1 - src/CMakeLists.txt | 3 --- src/swift/CMakeLists.txt | 22 ++++++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/dispatch/generic_static/module.modulemap b/dispatch/generic_static/module.modulemap index d5d64d2d1..f7fdaae76 100644 --- a/dispatch/generic_static/module.modulemap +++ b/dispatch/generic_static/module.modulemap @@ -3,7 +3,6 @@ module Dispatch { export * link "dispatch" link "BlocksRuntime" - link "DispatchStubs" } module DispatchIntrospection [system] [extern_c] { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 27980e92d..99da6165e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -82,9 +82,6 @@ if(ENABLE_DTRACE) endif() if(HAVE_OBJC) - # TODO(compnerd) split DispatchStubs.cc into a separate component for the ObjC - # registration and a separate component for the swift compiler's emission of a - # call to the ObjC autorelease elision entry point. target_sources(dispatch PRIVATE data.m object.m diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt index 6c9bb1445..bc09e9a97 100644 --- a/src/swift/CMakeLists.txt +++ b/src/swift/CMakeLists.txt @@ -1,9 +1,11 @@ -add_library(DispatchStubs STATIC - DispatchStubs.cc) -target_include_directories(DispatchStubs PRIVATE - ${PROJECT_SOURCE_DIR}) -set_target_properties(DispatchStubs PROPERTIES - POSITION_INDEPENDENT_CODE YES) +if(HAVE_OBJC) + add_library(DispatchStubs STATIC + DispatchStubs.cc) + target_include_directories(DispatchStubs PRIVATE + ${PROJECT_SOURCE_DIR}) + set_target_properties(DispatchStubs PROPERTIES + POSITION_INDEPENDENT_CODE YES) +endif() add_library(swiftDispatch Block.swift @@ -27,7 +29,7 @@ set_target_properties(swiftDispatch PROPERTIES Swift_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/swift INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/swift) target_link_libraries(swiftDispatch PRIVATE - DispatchStubs + $<$:DispatchStubs> BlocksRuntime::BlocksRuntime) target_link_libraries(swiftDispatch PUBLIC dispatch) @@ -36,6 +38,7 @@ if(NOT DARWIN AND NOT WIN32) set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN") endif() +set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch) install(TARGETS swiftDispatch EXPORT dispatchExports ARCHIVE DESTINATION "${Dispatch_INSTALL_LIBDIR}" @@ -53,11 +56,10 @@ INSTALL(FILES $/$/$.swiftsourceinfo DESTINATION ${Dispatch_INSTALL_SWIFTMODULEDIR}/$.swiftmodule RENAME ${Dispatch_MODULE_TRIPLE}.swiftsourceinfo) -if(NOT BUILD_SHARED_LIBS) + +if(NOT BUILD_SHARED_LIBS AND HAVE_OBJC) set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS DispatchStubs) install(TARGETS DispatchStubs EXPORT dispatchExports DESTINATION ${Dispatch_INSTALL_LIBDIR}) endif() - -set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch) From a7657b1cd06f970a84d359b331ef3aa9dbd03086 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 12 Mar 2025 22:20:03 -0700 Subject: [PATCH 8/9] build: remove unnecessary policy adjustment This should now be enabled due to the required version specification being updated. --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 475ebd896..5d44a9979 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,6 @@ cmake_minimum_required(VERSION 3.26...3.29) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) -# NOTE(compnerd) enable CMP0091 - select MSVC runtime based on -# CMAKE_MSVC_RUNTIME_LIBRARY. Requires CMake 3.15 or newer. -if(POLICY CMP0091) - cmake_policy(SET CMP0091 NEW) -endif() - project(dispatch VERSION 1.3 LANGUAGES C CXX) From 4d6b44956e7ce126513c6ed286c676320708633d Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 12 Mar 2025 22:24:23 -0700 Subject: [PATCH 9/9] build: use more global properties Specify RPATH and POSITION_INDEPENDENT globally rather than on a per-target basis. --- CMakeLists.txt | 5 +++++ src/CMakeLists.txt | 8 -------- src/swift/CMakeLists.txt | 3 --- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d44a9979..881019203 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,11 @@ set(CMAKE_C_VISIBILITY_INLINES_HIDDEN YES) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) +set(CMAKE_POSITION_INDEPENDENT_CODE YES) +if(NOT APPLE) + set(CMAKE_INSTALL_RPATH "$ORIGIN") +endif() + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) if(ANDROID) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 99da6165e..e1ef169a8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,10 +88,6 @@ if(HAVE_OBJC) swift/DispatchStubs.cc) endif() - -set_target_properties(dispatch PROPERTIES - POSITION_INDEPENDENT_CODE YES) - target_include_directories(dispatch PUBLIC ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} @@ -171,10 +167,6 @@ if(APPLE) "-Xlinker -alias_list -Xlinker ${PROJECT_SOURCE_DIR}/xcodeconfig/libdispatch.aliases") endif() -if(NOT APPLE) - set_target_properties(dispatch PROPERTIES INSTALL_RPATH "$ORIGIN") -endif() - if(LINKER_SUPPORTS_BUILD_ID) target_link_options(dispatch PRIVATE "LINKER:--build-id=sha1") endif() diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt index bc09e9a97..62d1ef68e 100644 --- a/src/swift/CMakeLists.txt +++ b/src/swift/CMakeLists.txt @@ -3,8 +3,6 @@ if(HAVE_OBJC) DispatchStubs.cc) target_include_directories(DispatchStubs PRIVATE ${PROJECT_SOURCE_DIR}) - set_target_properties(DispatchStubs PROPERTIES - POSITION_INDEPENDENT_CODE YES) endif() add_library(swiftDispatch @@ -35,7 +33,6 @@ target_link_libraries(swiftDispatch PUBLIC dispatch) if(NOT DARWIN AND NOT WIN32) target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath") - set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN") endif() set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch)