Skip to content

Commit 8c02f89

Browse files
authored
Merge pull request #867 from compnerd/update-requirements
build: update CMake requirements and simplify
2 parents 1bf870d + affa604 commit 8c02f89

10 files changed

+28
-44
lines changed

CMakeLists.txt

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11

2-
cmake_minimum_required(VERSION 3.15.1)
2+
cmake_minimum_required(VERSION 3.26...3.29)
33

44
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
55

6-
# NOTE(compnerd) enable CMP0091 - select MSVC runtime based on
7-
# CMAKE_MSVC_RUNTIME_LIBRARY. Requires CMake 3.15 or newer.
8-
if(POLICY CMP0091)
9-
cmake_policy(SET CMP0091 NEW)
10-
endif()
11-
126
project(dispatch
137
VERSION 1.3
148
LANGUAGES C CXX)
159

1610
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
1711

18-
if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
19-
include(ClangClCompileRules)
20-
endif()
21-
22-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
12+
if(WIN32)
2313
include(CheckCSourceCompiles)
2414
include(CheckSymbolExists)
2515

@@ -138,7 +128,7 @@ set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
138128

139129
option(ENABLE_DTRACE "enable dtrace support" "")
140130

141-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
131+
if(APPLE OR BSD)
142132
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT OFF)
143133
else()
144134
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON)
@@ -182,7 +172,7 @@ if(__BUILTIN_TRAP)
182172
set(HAVE_NORETURN_BUILTIN_TRAP 1)
183173
endif()
184174

185-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Android)
175+
if(NOT ANDROID)
186176
find_package(LibRT)
187177
endif()
188178

@@ -237,12 +227,12 @@ if(HAVE_MACH)
237227
else()
238228
set(USE_MACH_SEM 0)
239229
endif()
240-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
230+
if(WIN32)
241231
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:USE_WIN32_SEM>)
242232
endif()
243233
check_library_exists(pthread sem_init "" USE_POSIX_SEM)
244234
# NOTE: android has not always provided a libpthread, but uses the pthreads API
245-
if(CMAKE_SYSTEM_NAME STREQUAL Android)
235+
if(ANDROID)
246236
set(USE_POSIX_SEM 1)
247237
endif()
248238

@@ -272,11 +262,11 @@ if (HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME)
272262
endif()
273263
check_symbol_exists(__printflike "bsd/sys/cdefs.h" HAVE_PRINTFLIKE)
274264

275-
if(CMAKE_SYSTEM_NAME STREQUAL Android)
265+
if(ANDROID)
276266
set(ENABLE_DTRACE_DEFAULT OFF)
277267
endif()
278268

279-
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
269+
if(BSD)
280270
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:_WITH_DPRINTF>)
281271
endif()
282272

@@ -299,7 +289,7 @@ if(leaks_EXECUTABLE)
299289
endif()
300290

301291

302-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
292+
if(APPLE)
303293
add_compile_options($<:$<COMPILE_LANGUAGE:C,CXX>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap>
304294
$<:$<COMPILE_LANGUAGE:C,CXX>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/private/darwin/module.modulemap>)
305295
else()
@@ -314,7 +304,7 @@ add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:HAVE_CONFIG_H>)
314304

315305
if(ENABLE_SWIFT)
316306
if(NOT SWIFT_SYSTEM_NAME)
317-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
307+
if(APPLE)
318308
set(SWIFT_SYSTEM_NAME macosx)
319309
else()
320310
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")

cmake/modules/ClangClCompileRules.cmake

Lines changed: 0 additions & 5 deletions
This file was deleted.

cmake/modules/DispatchCompilerWarnings.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ else()
6969
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wno-void-pointer-to-int-cast>)
7070
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wno-vla>)
7171

72-
if(CMAKE_SYSTEM_NAME STREQUAL Android)
72+
if(ANDROID)
7373
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wno-incompatible-function-pointer-types>)
7474
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wno-implicit-function-declaration>)
7575
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-Wno-conversion>)

cmake/modules/DispatchSanitization.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set(DISPATCH_USE_SANITIZER "" CACHE STRING
33
"Define the sanitizer used to build binaries and tests.")
44

5-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND DISPATCH_USE_SANITIZER)
5+
if(APPLE AND DISPATCH_USE_SANITIZER)
66
message(FATAL_ERROR "building libdispatch with sanitization is not supported on Darwin")
77
endif()
88

cmake/modules/SwiftSupport.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function(get_swift_host_arch result_var_name)
1010
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
1111
set("${result_var_name}" "x86_64" PARENT_SCOPE)
1212
elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64|ARM64")
13-
if(CMAKE_SYSTEM_NAME MATCHES Darwin)
13+
if(APPLE)
1414
set("${result_var_name}" "arm64" PARENT_SCOPE)
1515
else()
1616
set("${result_var_name}" "aarch64" PARENT_SCOPE)
@@ -28,7 +28,7 @@ function(get_swift_host_arch result_var_name)
2828
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
2929
set("${result_var_name}" "armv7" PARENT_SCOPE)
3030
elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "amd64|AMD64")
31-
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
31+
if(WIN32)
3232
set("${result_var_name}" "x86_64" PARENT_SCOPE)
3333
else()
3434
set("${result_var_name}" "amd64" PARENT_SCOPE)

dispatch/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
2+
if(APPLE)
33
set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap)
44
else()
55
set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap)

src/BlocksRuntime/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
add_library(BlocksRuntime
33
data.c
44
runtime.c)
5-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
5+
if(WIN32)
66
target_sources(BlocksRuntime PRIVATE
77
BlocksRuntime.def)
88

src/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
2+
if(NOT APPLE)
33
add_subdirectory(BlocksRuntime)
44
endif()
55

@@ -57,7 +57,7 @@ add_library(dispatch
5757
shims/yield.c
5858
shims/yield.h)
5959

60-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
60+
if(WIN32)
6161
target_sources(dispatch PRIVATE
6262
shims/generic_sys_queue.h
6363
shims/generic_win_stubs.c
@@ -96,11 +96,11 @@ target_include_directories(dispatch PUBLIC
9696
target_include_directories(dispatch PRIVATE
9797
${PROJECT_SOURCE_DIR}/private)
9898

99-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
99+
if(WIN32)
100100
target_compile_definitions(dispatch PRIVATE
101101
_CRT_NONSTDC_NO_WARNINGS
102102
_CRT_SECURE_NO_WARNINGS)
103-
elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
103+
elseif(ANDROID)
104104
target_compile_options(dispatch PRIVATE
105105
-U_GNU_SOURCE)
106106
endif()
@@ -150,7 +150,7 @@ target_link_libraries(dispatch PRIVATE
150150
Threads::Threads)
151151
target_link_libraries(dispatch PUBLIC
152152
BlocksRuntime::BlocksRuntime)
153-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
153+
if(WIN32)
154154
target_link_libraries(dispatch PRIVATE
155155
AdvAPI32
156156
ShLwApi
@@ -159,15 +159,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
159159
synchronization)
160160
endif()
161161

162-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
162+
if(APPLE)
163163
set_property(TARGET dispatch APPEND_STRING PROPERTY LINK_FLAGS
164164
"-Xlinker -compatibility_version -Xlinker 1"
165165
"-Xlinker -current_version -Xlinker ${VERSION}"
166166
"-Xlinker -dead_strip"
167167
"-Xlinker -alias_list -Xlinker ${PROJECT_SOURCE_DIR}/xcodeconfig/libdispatch.aliases")
168168
endif()
169169

170-
if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
170+
if(NOT APPLE AND NOT WIN32)
171171
set_target_properties(dispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
172172
endif()
173173

src/swift/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ target_link_libraries(swiftDispatch PRIVATE
3131
BlocksRuntime::BlocksRuntime)
3232
target_link_libraries(swiftDispatch PUBLIC
3333
dispatch)
34-
if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
34+
if(NOT APPLE AND NOT WIN32)
3535
target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
3636
set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
3737
endif()

tests/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
2+
if(WIN32)
33
execute_process(COMMAND
44
"${CMAKE_COMMAND}" -E copy_directory "${PROJECT_SOURCE_DIR}/private"
55
"${CMAKE_CURRENT_BINARY_DIR}/dispatch")
@@ -15,7 +15,7 @@ else()
1515
"${CMAKE_CURRENT_BINARY_DIR}/leaks-wrapper")
1616
endif()
1717

18-
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
18+
if(LINUX)
1919
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lrt")
2020
endif()
2121

@@ -92,8 +92,7 @@ function(add_unit_test name)
9292
# fails with the multiple definition errors seen in android/ndk#176, so I
9393
# pulled in this workaround noted there. The tests build and run with this
9494
# flag applied.
95-
if(NOT BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL Android AND
96-
CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a)
95+
if(NOT BUILD_SHARED_LIBS AND ANDROID AND CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a)
9796
target_link_options(${name} PRIVATE "LINKER:--allow-multiple-definition")
9897
endif()
9998
target_link_libraries(${name}
@@ -162,7 +161,7 @@ if(EXTENDED_TEST_SUITE)
162161
endif()
163162

164163
# add C tests for platform-specific functionality when applicable
165-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
164+
if(APPLE)
166165
list(APPEND DISPATCH_C_TESTS
167166
deadname
168167
proc

0 commit comments

Comments
 (0)