Skip to content

build: improve cross-compilation for android #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ if(ENABLE_SWIFT)
${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)
Expand Down Expand Up @@ -166,10 +173,8 @@ check_include_files("libproc_internal.h" HAVE_LIBPROC_INTERNAL_H)
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)
Expand All @@ -188,11 +193,19 @@ check_include_files("sys/types.h" HAVE_SYS_TYPES_H)
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)
Expand All @@ -214,8 +227,15 @@ check_symbol_exists(VQ_VERYLOWDISK "sys/mount.h" HAVE_DECL_VQ_VERYLOWDISK)

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)
Expand Down
2 changes: 1 addition & 1 deletion cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions cmake/modules/DispatchCompilerWarnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,13 @@ else()
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()
5 changes: 4 additions & 1 deletion cmake/modules/SwiftSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(CMakeParseArguments)

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})
Expand All @@ -12,6 +12,9 @@ function(add_swift_library library)

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()
Expand Down
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ if(ENABLE_SWIFT)
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
Expand All @@ -106,7 +108,7 @@ if(ENABLE_SWIFT)
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)
Expand Down Expand Up @@ -140,6 +142,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows)
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
Expand Down