Skip to content

Commit

Permalink
build: fix cross-compiled installation of libdispatch
Browse files Browse the repository at this point in the history
When building SourceKit for non-Darwin targets, we build libdispatch.  The
installation of libdispatch changes based on the target system name.  Ensure
that we get the location for the shared libraries correct.  Explicitly set
`BUILD_SHARED_LIBS` to `YES` rather than relying on the implicit behaviour.
  • Loading branch information
compnerd committed Dec 20, 2018
1 parent b697b2c commit e1eb883
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -898,14 +898,20 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
if(CMAKE_C_COMPILER_ID STREQUAL Clang AND
CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.8
OR LLVM_USE_SANITIZER)
set(SWIFT_LIBDISPATCH_C_COMPILER ${CMAKE_C_COMPILER})
set(SWIFT_LIBDISPATCH_CXX_COMPILER ${CMAKE_CXX_COMPILER})
elseif(${CMAKE_SYSTEM_NAME} STREQUAL ${CMAKE_HOST_SYSTEM_NAME})
set(SWIFT_LIBDISPATCH_C_COMPILER ${PATH_TO_CLANG_BUILD}/bin/clang)
set(SWIFT_LIBDISPATCH_CXX_COMPILER ${PATH_TO_CLANG_BUILD}/bin/clang++)
else()
message(SEND_ERROR "libdispatch requires a newer clang compiler (${CMAKE_C_COMPILER_VERSION} < 3.9)")
endif()
set(SWIFT_LIBDISPATCH_C_COMPILER ${CMAKE_C_COMPILER})
set(SWIFT_LIBDISPATCH_CXX_COMPILER ${CMAKE_CXX_COMPILER})
elseif(${CMAKE_SYSTEM_NAME} STREQUAL ${CMAKE_HOST_SYSTEM_NAME})
set(SWIFT_LIBDISPATCH_C_COMPILER ${PATH_TO_CLANG_BUILD}/bin/clang)
set(SWIFT_LIBDISPATCH_CXX_COMPILER ${PATH_TO_CLANG_BUILD}/bin/clang++)
else()
message(SEND_ERROR "libdispatch requires a newer clang compiler (${CMAKE_C_COMPILER_VERSION} < 3.9)")
endif()

if(SWIFT_HOST_VARIANT_SDK STREQUAL Windows)
set(SOURCEKIT_LIBDISPATCH_RUNTIME_DIR bin)
else()
set(SOURCEKIT_LIBDISPATCH_RUNTIME_DIR lib)
endif()

include(ExternalProject)
ExternalProject_Add(libdispatch
Expand All @@ -923,6 +929,7 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
-DCMAKE_LINKER=${CMAKE_LINKER}
-DCMAKE_RANLIB=${CMAKE_RANLIB}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DBUILD_SHARED_LIBS=YES
-DENABLE_SWIFT=NO
-DENABLE_TESTING=NO
INSTALL_COMMAND
Expand All @@ -933,9 +940,9 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
STEP_TARGETS
install
BUILD_BYPRODUCTS
<INSTALL_DIR>/lib/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
<INSTALL_DIR>/${SOURCEKIT_LIBDISPATCH_RUNTIME_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
<INSTALL_DIR>/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}dispatch${CMAKE_IMPORT_LIBRARY_SUFFIX}
<INSTALL_DIR>/lib/${CMAKE_SHARED_LIBRARY_PREFIX}BlocksRuntime${CMAKE_SHARED_LIBRARY_SUFFIX}
<INSTALL_DIR>/${SOURCEKIT_LIBDISPATCH_RUNTIME_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}BlocksRuntime${CMAKE_SHARED_LIBRARY_SUFFIX}
<INSTALL_DIR>/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}BlocksRuntime${CMAKE_IMPORT_LIBRARY_SUFFIX}
BUILD_ALWAYS
1)
Expand All @@ -951,7 +958,7 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
set_target_properties(dispatch
PROPERTIES
IMPORTED_LOCATION
${install_dir}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
${install_dir}/${SOURCEKIT_LIBDISPATCH_RUNTIME_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
IMPORTED_IMPLIB
${install_dir}/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}dispatch${CMAKE_IMPORT_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES
Expand All @@ -961,7 +968,7 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
set_target_properties(BlocksRuntime
PROPERTIES
IMPORTED_LOCATION
${install_dir}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}BlocksRuntime${CMAKE_SHARED_LIBRARY_SUFFIX}
${install_dir}/${SOURCEKIT_LIBDISPATCH_RUNTIME_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}BlocksRuntime${CMAKE_SHARED_LIBRARY_SUFFIX}
IMPORTED_IMPLIB
${install_dir}/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}BlocksRuntime${CMAKE_IMPORT_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES
Expand Down

0 comments on commit e1eb883

Please sign in to comment.