Skip to content

build: explicitly link tests to swiftCore swiftOnoneSupport #307

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 4, 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
27 changes: 26 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,32 @@ dispatch_common_warnings()
option(ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON)
set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})

# TODO(compnerd) swift options
option(ENABLE_SWIFT "enable libdispatch swift overlay" OFF)
if(ENABLE_SWIFT)
if(NOT CMAKE_SWIFT_COMPILER)
message(FATAL_ERROR "CMAKE_SWIFT_COMPILER must be defined to enable swift")
endif()

get_filename_component(SWIFT_TOOLCHAIN ${CMAKE_SWIFT_COMPILER} DIRECTORY)
get_filename_component(SWIFT_TOOLCHAIN ${SWIFT_TOOLCHAIN} DIRECTORY)

string(TOLOWER ${CMAKE_SYSTEM_NAME} SWIFT_OS)
set(SWIFT_RUNTIME_LIBDIR ${SWIFT_TOOLCHAIN}/lib/swift/${SWIFT_OS}/${CMAKE_SYSTEM_PROCESSOR})

add_library(swiftCore
SHARED IMPORTED GLOBAL)
set_target_properties(swiftCore
PROPERTIES
IMPORTED_LOCATION
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})

add_library(swiftSwiftOnoneSupport
SHARED IMPORTED GLOBAL)
set_target_properties(swiftSwiftOnoneSupport
PROPERTIES
IMPORTED_LOCATION
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

option(BUILD_SHARED_LIBS "build shared libraries" ON)

Expand Down
7 changes: 4 additions & 3 deletions dispatch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ install(FILES
source.h
time.h
DESTINATION
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch/)
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch)
if(ENABLE_SWIFT)
get_filename_component(MODULE_MAP module.modulemap REALPATH)
install(FILES
module.modulemap
${MODULE_MAP}
DESTINATION
${CMAKE_INSTALL_FULL_INCLUEDIR}/dispatch/)
${CMAKE_INSTALL_FULL_INCLUDEDIR}/dispatch)
endif()

9 changes: 8 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if(HAVE_OBJC)
data.m
object.m)
endif()
if(CMAKE_SWIFT_COMPILER)
if(ENABLE_SWIFT)
set(swift_optimization_flags)
if(CMAKE_BUILD_TYPE MATCHES Release)
set(swift_optimization_flags -O)
Expand Down Expand Up @@ -203,4 +203,11 @@ install(TARGETS
dispatch
DESTINATION
"${CMAKE_INSTALL_FULL_LIBDIR}")
if(ENABLE_SWIFT)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc
DESTINATION
"${CMAKE_INSTALL_FULL_LIBDIR}/swift/${SWIFT_OS}/${CMAKE_SYSTEM_PROCESSOR}")
endif()

22 changes: 5 additions & 17 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_SOURCE_DIR}/private" "${CMAKE_CURRENT_BINARY_DIR}/dispatch")
execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/leaks-wrapper.sh" "${CMAKE_CURRENT_BINARY_DIR}/leaks-wrapper")

# TODO(compnerd) hoist this out of the test directory
if(SWIFT_RUNTIME_LIBDIR)
add_library(swiftCore SHARED IMPORTED)
set_target_properties(swiftCore
PROPERTIES
IMPORTED_LOCATION ${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})

add_library(swiftSwiftOnoneSupport SHARED IMPORTED)
set_target_properties(swiftSwiftOnoneSupport
PROPERTIES
IMPORTED_LOCATION ${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()

add_library(bsdtests
STATIC
bsdtests.c
Expand Down Expand Up @@ -74,10 +61,11 @@ function(add_unit_test name)
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR})
if(CMAKE_SWIFT_COMPILER)
# For testing in swift.org CI system; make deadlines lenient by default
# to reduce probability of test failures due to machine load.
target_compile_options(${name} PRIVATE -DLENIENT_DEADLINES=1)
if(ENABLE_SWIFT)
# For testing in swift.org CI system; make deadlines lenient by default
# to reduce probability of test failures due to machine load.
target_compile_options(${name} PRIVATE -DLENIENT_DEADLINES=1)
target_link_libraries(${name} PRIVATE swiftCore swiftSwiftOnoneSupport)
endif()
if(WITH_BLOCKS_RUNTIME)
target_include_directories(${name}
Expand Down