Skip to content

Commit 09c2ade

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 afe36b7 commit 09c2ade

File tree

8 files changed

+25
-26
lines changed

8 files changed

+25
-26
lines changed

CMakeLists.txt

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ project(dispatch
1313
VERSION 1.3
1414
LANGUAGES C CXX)
1515

16-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
16+
if(WIN32)
1717
include(CheckCSourceCompiles)
1818
include(CheckSymbolExists)
1919

@@ -132,7 +132,7 @@ set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
132132

133133
option(ENABLE_DTRACE "enable dtrace support" "")
134134

135-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
135+
if(APPLE OR BSD)
136136
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT OFF)
137137
else()
138138
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON)
@@ -176,7 +176,7 @@ if(__BUILTIN_TRAP)
176176
set(HAVE_NORETURN_BUILTIN_TRAP 1)
177177
endif()
178178

179-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Android)
179+
if(NOT ANDROID)
180180
find_package(LibRT)
181181
endif()
182182

@@ -231,12 +231,12 @@ if(HAVE_MACH)
231231
else()
232232
set(USE_MACH_SEM 0)
233233
endif()
234-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
234+
if(WIN32)
235235
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:USE_WIN32_SEM>)
236236
endif()
237237
check_library_exists(pthread sem_init "" USE_POSIX_SEM)
238238
# NOTE: android has not always provided a libpthread, but uses the pthreads API
239-
if(CMAKE_SYSTEM_NAME STREQUAL Android)
239+
if(ANDROID)
240240
set(USE_POSIX_SEM 1)
241241
endif()
242242

@@ -266,11 +266,11 @@ if (HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME)
266266
endif()
267267
check_symbol_exists(__printflike "bsd/sys/cdefs.h" HAVE_PRINTFLIKE)
268268

269-
if(CMAKE_SYSTEM_NAME STREQUAL Android)
269+
if(ANDROID)
270270
set(ENABLE_DTRACE_DEFAULT OFF)
271271
endif()
272272

273-
if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
273+
if(BSD)
274274
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:_WITH_DPRINTF>)
275275
endif()
276276

@@ -293,7 +293,7 @@ if(leaks_EXECUTABLE)
293293
endif()
294294

295295

296-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
296+
if(APPLE)
297297
add_compile_options($<:$<COMPILE_LANGUAGE:C,CXX>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/dispatch/darwin/module.modulemap>
298298
$<:$<COMPILE_LANGUAGE:C,CXX>:-fmodule-map-file=${PROJECT_SOURCE_DIR}/private/darwin/module.modulemap>)
299299
else()
@@ -308,7 +308,7 @@ add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:HAVE_CONFIG_H>)
308308

309309
if(ENABLE_SWIFT)
310310
if(NOT SWIFT_SYSTEM_NAME)
311-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
311+
if(APPLE)
312312
set(SWIFT_SYSTEM_NAME macosx)
313313
else()
314314
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")

cmake/modules/DispatchCompilerWarnings.cmake

+1-1
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

+1-1
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

dispatch/CMakeLists.txt

+1-1
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
elseif(BUILD_SHARED_LIBS)
55
set(DISPATCH_MODULE_MAP ${PROJECT_SOURCE_DIR}/dispatch/generic/module.modulemap)

src/BlocksRuntime/CMakeLists.txt

+1-1
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

+7-7
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
@@ -103,11 +103,11 @@ target_include_directories(dispatch PUBLIC
103103
target_include_directories(dispatch PRIVATE
104104
${PROJECT_SOURCE_DIR}/private)
105105

106-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
106+
if(WIN32)
107107
target_compile_definitions(dispatch PRIVATE
108108
_CRT_NONSTDC_NO_WARNINGS
109109
_CRT_SECURE_NO_WARNINGS)
110-
elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
110+
elseif(ANDROID)
111111
target_compile_options(dispatch PRIVATE
112112
-U_GNU_SOURCE)
113113
endif()
@@ -157,7 +157,7 @@ target_link_libraries(dispatch PRIVATE
157157
Threads::Threads)
158158
target_link_libraries(dispatch PUBLIC
159159
BlocksRuntime::BlocksRuntime)
160-
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
160+
if(WIN32)
161161
target_link_libraries(dispatch PRIVATE
162162
AdvAPI32
163163
ShLwApi
@@ -166,15 +166,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
166166
synchronization)
167167
endif()
168168

169-
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
169+
if(APPLE)
170170
set_property(TARGET dispatch APPEND_STRING PROPERTY LINK_FLAGS
171171
"-Xlinker -compatibility_version -Xlinker 1"
172172
"-Xlinker -current_version -Xlinker ${VERSION}"
173173
"-Xlinker -dead_strip"
174174
"-Xlinker -alias_list -Xlinker ${PROJECT_SOURCE_DIR}/xcodeconfig/libdispatch.aliases")
175175
endif()
176176

177-
if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
177+
if(NOT APPLE)
178178
set_target_properties(dispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
179179
endif()
180180

src/swift/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if(NOT BUILD_SHARED_LIBS)
4848
install(TARGETS DispatchStubs
4949
EXPORT dispatchExports
5050
DESTINATION ${INSTALL_TARGET_DIR})
51-
elseif(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows")
51+
elseif(NOT DARWIN AND NOT WIN32)
5252
target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
5353
set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
5454
endif()

tests/CMakeLists.txt

+4-5
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)