Skip to content

Commit

Permalink
Use DJInteropConfig.cmake desired version is avalable or fall back to…
Browse files Browse the repository at this point in the history
… GitHub or Launchpad download
  • Loading branch information
daschuer committed Jul 9, 2023
1 parent 8d9adae commit cc808b7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 62 deletions.
134 changes: 73 additions & 61 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2066,69 +2066,81 @@ if(ENGINEPRIME)
# libdjinterop does not currently have a stable ABI, so we fetch sources for a specific tag, build here, and link
# statically. This situation should be reviewed once libdjinterop hits version 1.x.
set(LIBDJINTEROP_VERSION 0.16.1)

# On MacOS, Mixxx does not use system SQLite, so we will use libdjinterop's
# embedded SQLite in such a case.
if (APPLE AND NOT SQLite3_IS_STATIC)
message(STATUS "Building libdjinterop sources (with embedded SQLite) fetched from GitHub")
set(DJINTEROP_SYSTEM_SQLITE OFF)
# Look whether an existing installation of libdjinterop matches the required version.
find_package(DjInterop ${LIBDJINTEROP_VERSION} EXACT CONFIG)
if(NOT DjInterop_FOUND)
find_package(DjInterop ${LIBDJINTEROP_VERSION} EXACT MODULE)
endif()
if(DjInterop_FOUND)
# An existing installation of djinterop is available.
message(STATUS "STATIC link existing system installation of libdjinterop")
target_link_libraries(mixxx-lib PRIVATE DjInterop::DjInterop)
else()
message(STATUS "Building libdjinterop sources (with system SQLite) fetched from GitHub")
set(DJINTEROP_SYSTEM_SQLITE ON)
endif()

set(DJINTEROP_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/lib/libdjinterop-install")
set(DJINTEROP_LIBRARY "lib/${CMAKE_STATIC_LIBRARY_PREFIX}djinterop${CMAKE_STATIC_LIBRARY_SUFFIX}")

# CMake does not pass lists of paths properly to external projects.
# This is worked around by changing the list separator.
string(REPLACE ";" "|" PIPE_DELIMITED_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")

# For offline builds download the archive file from the URL and
# copy it into DOWNLOAD_DIR under DOWNLOAD_NAME prior to starting
# the configuration.
ExternalProject_Add(libdjinterop
URL "https://github.com/xsco/libdjinterop/archive/refs/tags/${LIBDJINTEROP_VERSION}.tar.gz"
URL_HASH SHA256=25461f5cc3ea80850d8400872f4fef08ad3730d9f2051719cccf2460f5ac15ad
DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/downloads"
DOWNLOAD_NAME "libdjinterop-${LIBDJINTEROP_VERSION}.tar.gz"
INSTALL_DIR ${DJINTEROP_INSTALL_DIR}
LIST_SEPARATOR "|"
CMAKE_ARGS
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_PREFIX_PATH=${PIPE_DELIMITED_CMAKE_PREFIX_PATH}
-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_INSTALL_LIBDIR:PATH=lib
-DCMAKE_MODULE_PATH:PATH=${CMAKE_MODULE_PATH}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT}
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
-DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DSYSTEM_SQLITE=${DJINTEROP_SYSTEM_SQLITE}
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target DjInterop
BUILD_BYPRODUCTS <INSTALL_DIR>/${DJINTEROP_LIBRARY}
EXCLUDE_FROM_ALL TRUE
)
# On MacOS, Mixxx does not use system SQLite, so we will use libdjinterop's
# embedded SQLite in such a case.
if (APPLE AND NOT SQLite3_IS_STATIC)
message(STATUS "Building libdjinterop sources (with embedded SQLite) fetched from GitHub")
set(DJINTEROP_SYSTEM_SQLITE OFF)
else()
message(STATUS "Building libdjinterop sources (with system SQLite) fetched from GitHub")
set(DJINTEROP_SYSTEM_SQLITE ON)
endif()

# Assemble a library based on the external project.
add_library(mixxx-libdjinterop STATIC IMPORTED)
add_dependencies(mixxx-libdjinterop libdjinterop)
set(DJINTEROP_INCLUDE_DIR "${DJINTEROP_INSTALL_DIR}/include")
set(DJINTEROP_LIBRARY_PATH "${DJINTEROP_INSTALL_DIR}/${DJINTEROP_LIBRARY}")
set_target_properties(mixxx-libdjinterop PROPERTIES IMPORTED_LOCATION "${DJINTEROP_LIBRARY_PATH}")
target_include_directories(mixxx-lib PUBLIC ${DJINTEROP_INCLUDE_DIR})
target_link_libraries(mixxx-lib PRIVATE mixxx-libdjinterop)

# Since we have built libdjinterop from sources as a static library, its
# transitive dependencies are not automatically recognised. libdjinterop
# depends on zlib and optionally sqlite3. If libdjinterop was configured
# to depend on system SQLite, Mixxx will already have the dependency.
# But it does not have zlib, so we explicitly add that here.
find_package(ZLIB 1.2.8 REQUIRED)
target_link_libraries(mixxx-lib PRIVATE ${ZLIB_LIBRARIES})
set(DJINTEROP_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/lib/libdjinterop-install")
set(DJINTEROP_LIBRARY "lib/${CMAKE_STATIC_LIBRARY_PREFIX}djinterop${CMAKE_STATIC_LIBRARY_SUFFIX}")

# CMake does not pass lists of paths properly to external projects.
# This is worked around by changing the list separator.
string(REPLACE ";" "|" PIPE_DELIMITED_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")

# For offline builds download the archive file from the URL and
# copy it into DOWNLOAD_DIR under DOWNLOAD_NAME prior to starting
# the configuration.
ExternalProject_Add(libdjinterop
URL
"https://github.com/xsco/libdjinterop/archive/refs/tags/${LIBDJINTEROP_VERSION}.tar.gz"
"https://launchpad.net/~xsco/+archive/ubuntu/djinterop/+sourcefiles/libdjinterop/${LIBDJINTEROP_VERSION}-0ubuntu1/libdjinterop_${LIBDJINTEROP_VERSION}.orig.tar.gz"
URL_HASH SHA256=25461f5cc3ea80850d8400872f4fef08ad3730d9f2051719cccf2460f5ac15ad
DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/downloads"
DOWNLOAD_NAME "libdjinterop-${LIBDJINTEROP_VERSION}.tar.gz"
INSTALL_DIR ${DJINTEROP_INSTALL_DIR}
LIST_SEPARATOR "|"
CMAKE_ARGS
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_PREFIX_PATH=${PIPE_DELIMITED_CMAKE_PREFIX_PATH}
-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_INSTALL_LIBDIR:PATH=lib
-DCMAKE_MODULE_PATH:PATH=${CMAKE_MODULE_PATH}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT}
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
-DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DSYSTEM_SQLITE=${DJINTEROP_SYSTEM_SQLITE}
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target DjInterop
BUILD_BYPRODUCTS <INSTALL_DIR>/${DJINTEROP_LIBRARY}
EXCLUDE_FROM_ALL TRUE
)

# Assemble a library based on the external project.
add_library(mixxx-libdjinterop STATIC IMPORTED)
add_dependencies(mixxx-libdjinterop libdjinterop)
set(DJINTEROP_INCLUDE_DIR "${DJINTEROP_INSTALL_DIR}/include")
set(DJINTEROP_LIBRARY_PATH "${DJINTEROP_INSTALL_DIR}/${DJINTEROP_LIBRARY}")
set_target_properties(mixxx-libdjinterop PROPERTIES IMPORTED_LOCATION "${DJINTEROP_LIBRARY_PATH}")
target_include_directories(mixxx-lib PUBLIC ${DJINTEROP_INCLUDE_DIR})
target_link_libraries(mixxx-lib PRIVATE mixxx-libdjinterop)

# Since we have built libdjinterop from sources as a static library, its
# transitive dependencies are not automatically recognised. libdjinterop
# depends on zlib and optionally sqlite3. If libdjinterop was configured
# to depend on system SQLite, Mixxx will already have the dependency.
# But it does not have zlib, so we explicitly add that here.
find_package(ZLIB 1.2.8 REQUIRED)
target_link_libraries(mixxx-lib PRIVATE ${ZLIB_LIBRARIES})
endif()

# Include conditional sources only required with Engine Prime export support.
target_sources(mixxx-lib PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/FindDjInterop.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
DjInterop
REQUIRED_VARS DjInterop_LIBRARY DjInterop_INCLUDE_DIR
REQUIRED_VARS DjInterop_LIBRARY DjInterop_INCLUDE_DIR DjInterop_VERSION
VERSION_VAR DjInterop_VERSION
)

Expand Down

0 comments on commit cc808b7

Please sign in to comment.