Skip to content

Commit 7ecec13

Browse files
committed
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.
1 parent 1d1b1b1 commit 7ecec13

File tree

9 files changed

+27
-28
lines changed

9 files changed

+27
-28
lines changed

CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ project(dispatch
99

1010
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
1111

12-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
12+
if(WIN32)
1313
include(CheckCSourceCompiles)
1414
include(CheckSymbolExists)
1515

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

129129
option(ENABLE_DTRACE "enable dtrace support" "")
130130

131-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
131+
if(APPLE OR BSD)
132132
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT OFF)
133133
else()
134134
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON)
@@ -172,7 +172,7 @@ if(__BUILTIN_TRAP)
172172
set(HAVE_NORETURN_BUILTIN_TRAP 1)
173173
endif()
174174

175-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Android)
175+
if(NOT ANDROID)
176176
find_package(LibRT)
177177
endif()
178178

@@ -227,12 +227,12 @@ if(HAVE_MACH)
227227
else()
228228
set(USE_MACH_SEM 0)
229229
endif()
230-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
230+
if(WIN32)
231231
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:USE_WIN32_SEM>)
232232
endif()
233233
check_library_exists(pthread sem_init "" USE_POSIX_SEM)
234234
# NOTE: android has not always provided a libpthread, but uses the pthreads API
235-
if(CMAKE_SYSTEM_NAME STREQUAL Android)
235+
if(ANDROID)
236236
set(USE_POSIX_SEM 1)
237237
endif()
238238

@@ -262,11 +262,11 @@ if (HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME)
262262
endif()
263263
check_symbol_exists(__printflike "bsd/sys/cdefs.h" HAVE_PRINTFLIKE)
264264

265-
if(CMAKE_SYSTEM_NAME STREQUAL Android)
265+
if(aNDROID)
266266
set(ENABLE_DTRACE_DEFAULT OFF)
267267
endif()
268268

269-
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
269+
if(BSD)
270270
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:_WITH_DPRINTF>)
271271
endif()
272272

@@ -289,7 +289,7 @@ if(leaks_EXECUTABLE)
289289
endif()
290290

291291

292-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
292+
if(APPLE)
293293
add_compile_options($<:$<COMPILE_LANGUAGE:C,CXX>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap>
294294
$<:$<COMPILE_LANGUAGE:C,CXX>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/private/darwin/module.modulemap>)
295295
else()
@@ -304,7 +304,7 @@ add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:HAVE_CONFIG_H>)
304304

305305
if(ENABLE_SWIFT)
306306
if(NOT SWIFT_SYSTEM_NAME)
307-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
307+
if(APPLE)
308308
set(SWIFT_SYSTEM_NAME macosx)
309309
else()
310310
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")

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)