Merge pull request #312 from compnerd/android
build: improve cross-compilation for android
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 97d6a74..5b294bb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,6 +61,13 @@
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
+if(CMAKE_SYSTEM_NAME STREQUAL Android)
+ set(ENABLE_DTRACE_DEFAULT OFF)
+else()
+ set(ENABLE_DTRACE_DEFAULT ON)
+endif()
+option(ENABLE_DTRACE "enable dtrace support" ${ENABLE_DTRACE_DEFAULT})
+
option(BUILD_SHARED_LIBS "build shared libraries" ON)
option(ENABLE_TESTING "build libdispatch tests" ON)
@@ -166,10 +173,8 @@
check_include_files("mach/mach.h" HAVE_MACH)
if(HAVE_MACH)
set(__DARWIN_NON_CANCELABLE 1)
- set(USE_MACH_SEM 1)
else()
set(__DARWIN_NON_CANCELABLE 0)
- set(USE_MACH_SEM 0)
endif()
check_include_files("malloc/malloc.h" HAVE_MALLOC_MALLOC_H)
check_include_files("memory.h" HAVE_MEMORY_H)
@@ -188,11 +193,19 @@
check_include_files("unistd.h" HAVE_UNISTD_H)
check_include_files("objc/objc-internal.h" HAVE_OBJC)
-check_library_exists(pthread sem_init "" USE_POSIX_SEM)
+if(HAVE_MACH)
+ set(USE_MACH_SEM 1)
+else()
+ set(USE_MACH_SEM 0)
+endif()
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
- add_definitions(-DTARGET_OS_WIN32)
add_definitions(-DUSE_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)
+ set(USE_POSIX_SEM 1)
+endif()
check_symbol_exists(CLOCK_UPTIME "time.h" HAVE_DECL_CLOCK_UPTIME)
check_symbol_exists(CLOCK_UPTIME_FAST "time.h" HAVE_DECL_CLOCK_UPTIME_FAST)
@@ -214,8 +227,15 @@
check_symbol_exists(program_invocation_name "errno.h" HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME)
-find_program(dtrace_EXECUTABLE dtrace)
-if(dtrace_EXECUTABLE)
+if(CMAKE_SYSTEM_NAME STREQUAL Windows)
+ add_definitions(-DTARGET_OS_WIN32)
+endif()
+
+if(ENABLE_DTRACE)
+ find_program(dtrace_EXECUTABLE dtrace)
+ if(NOT dtrace_EXECUTABLE)
+ message(FATAL_ERROR "dtrace not found but explicitly requested")
+ endif()
add_definitions(-DDISPATCH_USE_DTRACE=1)
else()
add_definitions(-DDISPATCH_USE_DTRACE=0)
diff --git a/cmake/config.h.in b/cmake/config.h.in
index 97c94cc..a59737b 100644
--- a/cmake/config.h.in
+++ b/cmake/config.h.in
@@ -212,7 +212,7 @@
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
-#cmakedefine01 _GNU_SOURCE
+#cmakedefine _GNU_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
diff --git a/cmake/modules/DispatchCompilerWarnings.cmake b/cmake/modules/DispatchCompilerWarnings.cmake
index dcc074e..d5069c2 100644
--- a/cmake/modules/DispatchCompilerWarnings.cmake
+++ b/cmake/modules/DispatchCompilerWarnings.cmake
@@ -70,5 +70,13 @@
add_compile_options(-Wno-unused-macros)
add_compile_options(-Wno-used-but-marked-unused)
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)
+ endif()
endmacro()
endif()
diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake
index 64b7b36..b7a3e76 100644
--- a/cmake/modules/SwiftSupport.cmake
+++ b/cmake/modules/SwiftSupport.cmake
@@ -3,7 +3,7 @@
function(add_swift_library library)
set(options)
- set(single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT)
+ set(single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT;TARGET)
set(multiple_value_options SOURCES;SWIFT_FLAGS;CFLAGS)
cmake_parse_arguments(ASL "${options}" "${single_value_options}" "${multiple_value_options}" ${ARGN})
@@ -12,6 +12,9 @@
list(APPEND flags -emit-library)
+ if(ASL_TARGET)
+ list(APPEND FLAGS -target;${ASL_TARGET})
+ endif()
if(ASL_MODULE_NAME)
list(APPEND flags -module-name;${ASL_MODULE_NAME})
endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5c793dc..11c3a3d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -93,6 +93,8 @@
swift/Source.swift
swift/Time.swift
swift/Wrapper.swift
+ TARGET
+ ${CMAKE_C_COMPILER_TARGET}
CFLAGS
-fblocks
-fmodule-map-file=${CMAKE_SOURCE_DIR}/dispatch/module.modulemap
@@ -106,7 +108,7 @@
swift/DispatchStubs.cc
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o)
endif()
-if(dtrace_EXECUTABLE)
+if(ENABLE_DTRACE)
dtrace_usdt_probe(${CMAKE_CURRENT_SOURCE_DIR}/provider.d
OUTPUT_SOURCES
dispatch_dtrace_provider_headers)
@@ -140,6 +142,10 @@
target_compile_definitions(dispatch
PRIVATE
-D_CRT_SECURE_NO_WARNINGS)
+elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
+ target_compile_options(dispatch
+ PRIVATE
+ -U_GNU_SOURCE)
endif()
if(BSD_OVERLAY_FOUND)
target_compile_options(dispatch