@@ -44,38 +44,32 @@ dispatch_common_warnings()
4444option (ENABLE_DISPATCH_INIT_CONSTRUCTOR "enable libdispatch_init as a constructor" ON )
4545set (USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR} )
4646
47+ # NOTE(abdulras) this is the CMake supported way to control whether we generate
48+ # shared or static libraries. This impacts the behaviour of `add_library` in
49+ # what type of library it generates.
50+ option (BUILD_SHARED_LIBS "build shared libraries" ON )
51+
4752option (ENABLE_SWIFT "enable libdispatch swift overlay" OFF )
4853if (ENABLE_SWIFT)
4954 if (NOT CMAKE_SWIFT_COMPILER)
5055 message (FATAL_ERROR "CMAKE_SWIFT_COMPILER must be defined to enable swift" )
5156 endif ()
5257
53- get_filename_component (SWIFT_TOOLCHAIN ${CMAKE_SWIFT_COMPILER} DIRECTORY )
54- get_filename_component (SWIFT_TOOLCHAIN ${SWIFT_TOOLCHAIN} DIRECTORY )
55-
56- string (TOLOWER ${CMAKE_SYSTEM_NAME} SWIFT_OS)
57- get_swift_host_arch(SWIFT_HOST_ARCH)
58+ find_package (Swift REQUIRED CONFIG)
5859
59- set (SWIFT_RUNTIME_LIBDIR ${SWIFT_TOOLCHAIN} /${SWIFT_LIBDIR} /swift/${SWIFT_OS} /${SWIFT_HOST_ARCH} )
60-
61- add_library (swiftCore
62- SHARED IMPORTED GLOBAL )
63- set_target_properties (swiftCore
64- PROPERTIES
65- IMPORTED_LOCATION
66- ${SWIFT_RUNTIME_LIBDIR} /${CMAKE_SHARED_LIBRARY_PREFIX} swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX} )
60+ string (TOLOWER ${CMAKE_SYSTEM_NAME} swift_os)
61+ get_swift_host_arch(swift_arch)
6762
68- add_library (swiftSwiftOnoneSupport
69- SHARED IMPORTED GLOBAL )
70- set_target_properties (swiftSwiftOnoneSupport
71- PROPERTIES
72- IMPORTED_LOCATION
73- ${SWIFT_RUNTIME_LIBDIR} /${CMAKE_SHARED_LIBRARY_PREFIX} swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX} )
63+ if (BUILD_SHARED_LIBS )
64+ set (swift_dir swift)
65+ else ()
66+ set (swift_dir swift_static)
67+ endif ()
7468
75- set (INSTALL_TARGET_DIR "${INSTALL_LIBDIR} /swift /${SWIFT_OS } " CACHE PATH "Path where the libraries will be installed" )
76- set (INSTALL_DISPATCH_HEADERS_DIR "${INSTALL_LIBDIR} /swift /dispatch" CACHE PATH "Path where the headers will be installed for libdispatch" )
77- set (INSTALL_BLOCK_HEADERS_DIR "${INSTALL_LIBDIR} /swift /Block" CACHE PATH "Path where the headers will be installed for the blocks runtime" )
78- set (INSTALL_OS_HEADERS_DIR "${INSTALL_LIBDIR} /swift /os" CACHE PATH "Path where the os/ headers will be installed" )
69+ set (INSTALL_TARGET_DIR "${INSTALL_LIBDIR} /${swift_dir} /${swift_os } " CACHE PATH "Path where the libraries will be installed" )
70+ set (INSTALL_DISPATCH_HEADERS_DIR "${INSTALL_LIBDIR} /${swift_dir} /dispatch" CACHE PATH "Path where the headers will be installed for libdispatch" )
71+ set (INSTALL_BLOCK_HEADERS_DIR "${INSTALL_LIBDIR} /${swift_dir} /Block" CACHE PATH "Path where the headers will be installed for the blocks runtime" )
72+ set (INSTALL_OS_HEADERS_DIR "${INSTALL_LIBDIR} /${swift_dir} /os" CACHE PATH "Path where the os/ headers will be installed" )
7973endif ()
8074
8175if (NOT ENABLE_SWIFT)
@@ -87,11 +81,6 @@ endif()
8781
8882option (ENABLE_DTRACE "enable dtrace support" "" )
8983
90- # NOTE(abdulras) this is the CMake supported way to control whether we generate
91- # shared or static libraries. This impacts the behaviour of `add_library` in
92- # what type of library it generates.
93- option (BUILD_SHARED_LIBS "build shared libraries" ON )
94-
9584option (ENABLE_TESTING "build libdispatch tests" ON )
9685
9786option (USE_LLD_LINKER "use the lld linker" FALSE )
0 commit comments