Skip to content
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

macOS static build support #4163

Merged
merged 18 commits into from
Aug 5, 2021
Merged
Changes from 1 commit
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
29 changes: 10 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -82,6 +82,7 @@ include(CheckSymbolExists)
include(ExternalProject)
include(GNUInstallDirs)
include(DefaultOption)
include(IsStaticLibrary)

#######################################################################
# Compilers and toolchains
@@ -1796,8 +1797,8 @@ find_package(SQLite3)
if(NOT SQLite3_FOUND)
set(LOCALECOMPARE_DEFAULT OFF)
else()
get_target_property(SQLITE3_TYPE SQLite3::SQLite3 TYPE)
if(SQLITE3_TYPE STREQUAL "STATIC_LIBRARY" OR NOT APPLE)
is_static_library(SQLite3_IS_STATIC SQLite3::SQLite3)
if(SQLite3_IS_STATIC OR NOT APPLE)
set(LOCALECOMPARE_DEFAULT ON)
else()
set(LOCALECOMPARE_DEFAULT OFF)
@@ -1810,7 +1811,7 @@ if(LOCALECOMPARE)
endif()
target_compile_definitions(mixxx-lib PUBLIC __SQLITE3__)
target_link_libraries(mixxx-lib PRIVATE SQLite3::SQLite3)
elseif(SQLITE3_TYPE STREQUAL "STATIC_LIBRARY")
elseif(SQLite3_IS_STATIC)
# in the static case we need to link SQlite3 uncoditionally
daschuer marked this conversation as resolved.
Show resolved Hide resolved
target_link_libraries(mixxx-lib PRIVATE SQLite3::SQLite3)
endif()
@@ -1831,7 +1832,7 @@ if(ENGINEPRIME)

# 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_TYPE STREQUAL "STATIC_LIBRARY")
if (APPLE AND NOT SQLite3_IS_STATIC)
message(STATUS "Building libdjinterop sources (with embedded SQLite) fetched from GitHub")
set(DJINTEROP_SYSTEM_SQLITE OFF)
else()
@@ -2118,8 +2119,8 @@ target_link_libraries(mixxx-lib PUBLIC
Qt5::Widgets
Qt5::Xml)
target_compile_definitions(mixxx-lib PUBLIC QT_TABLET_SUPPORT QT_USE_QSTRINGBUILDER)
get_target_property(QT5_TYPE Qt5::Core TYPE)
if(QT5_TYPE STREQUAL "STATIC_LIBRARY")
is_static_library(Qt5_IS_STATIC Qt5::Core)
Be-ing marked this conversation as resolved.
Show resolved Hide resolved
if(Qt5_IS_STATIC)

# NOTE(rryan): If you are adding a plugin here, you must also
# update src/mixxxapplication.cpp to define a Q_IMPORT_PLUGIN
@@ -2161,17 +2162,7 @@ endif()


if(APPLE)
if(QT5_TYPE STREQUAL "STATIC_LIBRARY")
find_package(FFTW REQUIRED)
find_package(SndFile REQUIRED)
find_package(sord CONFIG REQUIRED)
find_library(SAMPLERATE_LIBRARY samplerate REQUIRED)
target_link_libraries(mixxx-lib PRIVATE
FFTW::FFTW
SndFile::sndfile
sord::sord
${SAMPLERATE_LIBRARY}
)
if(Qt5_IS_STATIC)
target_link_libraries(mixxx-lib PRIVATE
"-weak_framework Accelerate"
"-weak_framework AppKit"
@@ -2204,7 +2195,7 @@ elseif(UNIX)
Qt5::DBus
)
elseif(WIN32)
if(QT5_TYPE STREQUAL "STATIC_LIBRARY")
if(Qt5_IS_STATIC)
target_link_libraries(mixxx-lib PRIVATE
# Pulled from qt-4.8.2-source\mkspecs\win32-msvc2010\qmake.conf
# QtCore
@@ -2918,7 +2909,7 @@ set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/packaging/CPackConfig.cmake"
include(CPack)

if(APPLE AND MACOS_BUNDLE)
if(NOT QT5_TYPE STREQUAL "STATIC_LIBRARY")
if(NOT Qt5_IS_STATIC)
macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var _prefix)
get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
if(EXISTS "${_qt_plugin_path}")
6 changes: 4 additions & 2 deletions cmake/modules/FindChromaprint.cmake
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ The following cache variables may also be set:

#]=======================================================================]

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_Chromaprint QUIET libchromaprint)
@@ -83,8 +85,8 @@ if(Chromaprint_FOUND)
INTERFACE_COMPILE_OPTIONS "${PC_Chromaprint_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Chromaprint_INCLUDE_DIR}"
)
get_target_property(CHROMAPRINT_TYPE Chromaprint::Chromaprint TYPE)
if(CHROMAPRINT_TYPE STREQUAL "STATIC_LIBRARY")
is_static_library(Chromaprint_IS_STATIC Chromaprint::Chromaprint)
if(Chromaprint_IS_STATIC)
if(WIN32)
# used in chomaprint.h to set dllexport for Windows
set_property(TARGET Chromaprint::Chromaprint APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS
6 changes: 4 additions & 2 deletions cmake/modules/FindFLAC.cmake
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ The following cache variables may also be set:

#]=======================================================================]

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_FLAC QUIET flac)
@@ -82,8 +84,8 @@ if(FLAC_FOUND)
INTERFACE_COMPILE_OPTIONS "${PC_FLAC_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${FLAC_INCLUDE_DIR}"
)
get_target_property(FLAC_TYPE FLAC::FLAC TYPE)
if(FLAC_TYPE STREQUAL "STATIC_LIBRARY")
is_static_library(FLAC_IS_STATIC FLAC::FLAC)
if(FLAC_IS_STATIC)
if(WIN32)
set_property(TARGET FLAC::FLAC APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS
FLAC__NO_DLL
6 changes: 4 additions & 2 deletions cmake/modules/FindKeyFinder.cmake
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ The following cache variables may also be set:

#]=======================================================================]

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_KeyFinder QUIET libKeyFinder>=2.0)
@@ -82,8 +84,8 @@ if(KeyFinder_FOUND)
INTERFACE_COMPILE_OPTIONS "${PC_KeyFinder_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${KeyFinder_INCLUDE_DIR}"
)
get_target_property(KEYFINDER_TYPE KeyFinder::KeyFinder TYPE)
if(KEYFINDER_TYPE STREQUAL "STATIC_LIBRARY")
is_static_library(KeyFinder_IS_STATIC KeyFinder::KeyFinder)
if(KeyFinder_IS_STATIC)
find_package(FFTW REQUIRED)
set_property(TARGET Chromaprint::Chromaprint APPEND PROPERTY INTERFACE_LINK_LIBRARIES
daschuer marked this conversation as resolved.
Show resolved Hide resolved
FFTW::FFTW
16 changes: 9 additions & 7 deletions cmake/modules/FindOpusFile.cmake
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@ The following cache variables may also be set:

#]=======================================================================]

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_OpusFile QUIET opusfile)
@@ -79,12 +81,12 @@ if(OpusFile_FOUND)
INTERFACE_COMPILE_OPTIONS "${OpusFile_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${OpusFile_INCLUDE_DIRS}"
)
get_target_property(OPUSFILE_TYPE OpusFile::OpusFile TYPE)
if(OPUSFILE_TYPE STREQUAL "STATIC_LIBRARY")
find_package(Opus REQUIRED)
set_property(TARGET OpusFile::OpusFile APPEND PROPERTY INTERFACE_LINK_LIBRARIES
Opus::Opus
)
endif()
is_static_library(OpusFile_IS_STATIC OpusFile::OpusFile)
#if(OpusFile_IS_STATIC)
# find_package(Opus REQUIRED)
# set_property(TARGET OpusFile::OpusFile APPEND PROPERTY INTERFACE_LINK_LIBRARIES
# Opus::Opus
# )
#endif()
Be-ing marked this conversation as resolved.
Show resolved Hide resolved
Be-ing marked this conversation as resolved.
Show resolved Hide resolved
endif()
endif()
6 changes: 4 additions & 2 deletions cmake/modules/FindTagLib.cmake
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ The following cache variables may also be set:

#]=======================================================================]

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_TagLib QUIET taglib)
@@ -83,8 +85,8 @@ if(TagLib_FOUND)
INTERFACE_COMPILE_OPTIONS "${PC_TagLib_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${TagLib_INCLUDE_DIR}"
)
get_target_property(TAGLIB_TYPE TagLib::TagLib TYPE)
if(TAGLIB_TYPE STREQUAL "STATIC_LIBRARY")
is_static_library(Taglib_IS_STATIC TagLib::TagLib)
if(Taglib_IS_STATIC)
if(WIN32)
set_property(TARGET TagLib::TagLib APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS
TAGLIB_STATIC
11 changes: 5 additions & 6 deletions cmake/modules/Findlilv.cmake
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ The following cache variables may also be set:

#]=======================================================================]

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_lilv QUIET lilv-0)
@@ -84,14 +86,11 @@ if(lilv_FOUND)
INTERFACE_COMPILE_OPTIONS "${PC_lilv_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${lilv_INCLUDE_DIR}"
)
get_target_property(LILV_TYPE lilv::lilv TYPE)
if(LILV_TYPE STREQUAL "STATIC_LIBRARY")
find_package(lv2 CONFIG REQUIRED)
find_package(serd CONFIG REQUIRED)
is_static_library(lilv_IS_STATIC lilv::lilv)
if(lilv_IS_STATIC)
find_package(sord CONFIG REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
find_package(sord CONFIG REQUIRED)
find_package(sord REQUIRED)

Copy link
Member Author

@daschuer daschuer Aug 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As already mentioned, this is how it is called in the lilv CMakeList.txt both place need to be use the same method.
See: https://github.com/microsoft/vcpkg/blob/261c458af6e3eed5d099144aff95d2b5035f656b/ports/lilv/CMakeLists.txt#L6

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means this CMake module can only work with vcpkg because the upstream library does not ship a CMake config module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Holzhaus what are your thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @Holzhaus, this is all that is left on this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context here is different. This module might be copied into another application which doesn't use vcpkg and has its own Findsord.cmake module. Hardcoding CONFIG would break that. I don't think there's a good reason to make this code less flexible by doing that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care about writing the module to use it in other applications, sorry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more about the general principle not to hardcode unnecessary assumptions. Anyway I am done bikeshedding this. If anyone really needs to change it, it would simply be deleting a single word.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_package(sratom CONFIG REQUIRED)
set_property(TARGET lilv::lilv APPEND PROPERTY INTERFACE_LINK_LIBRARIES
lv2::lv2 serd::serd sord::sord sratom::sratom
sord::sord
)
endif()
endif()
9 changes: 9 additions & 0 deletions cmake/modules/Findrubberband.cmake
Original file line number Diff line number Diff line change
@@ -82,5 +82,14 @@ if(rubberband_FOUND)
INTERFACE_COMPILE_OPTIONS "${PC_rubberband_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${rubberband_INCLUDE_DIR}"
)
is_static_library(rubberband_IS_STATIC Chromaprint::Chromaprint)
if(rubberband_IS_STATIC)
find_package(FFTW REQUIRED)
find_library(SAMPLERATE_LIBRARY samplerate REQUIRED)
set_property(TARGET rubberband::rubberband APPEND PROPERTY INTERFACE_LINK_LIBRARIES
FFTW::FFTW
${SAMPLERATE_LIBRARY}
)
endif()
endif()
endif()
41 changes: 41 additions & 0 deletions cmake/modules/IsStaticLibrary.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#[=======================================================================[.rst:
IsStaticLibrary
Be-ing marked this conversation as resolved.
Show resolved Hide resolved
-------------

Macros to set a given variable to true or false whether the library is static

Usage:

.. code-block:: cmake

is_static_library(<VAR> target)

Where ``<VAR>`` is set to TRUE if the target is a static library

Example invocation:

.. code-block:: cmake

is_static_library(LIB_IS_STATIC Lib::Lib)

#]=======================================================================]

macro(IS_STATIC_LIBRARY var target)
get_target_property(_target_type ${target} TYPE)
if(${_target_type} STREQUAL "STATIC_LIBRARY")
set(${var} TRUE)
elseif(${_target_type} STREQUAL "UNKNOWN_LIBRARY")
get_target_property(_target_location ${target} LOCATION)
get_filename_component(_target_extension ${_target_location} EXT)
if(${_target_extension} STREQUAL ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(${var} TRUE)
else()
set(${var} FALSE)
endif()
unset(_target_location)
unset(_target_extension)
else()
set(${var} FALSE)
endif()
unset(_target_type)
endmacro()