2021-01-08 21:49:44 +00:00
|
|
|
cmake_minimum_required(VERSION 3.13...3.19)
|
2023-08-16 04:36:07 +00:00
|
|
|
|
|
|
|
if (VCPKG_LIBSNDFILE)
|
|
|
|
list(APPEND VCPKG_MANIFEST_FEATURES "vcpkg-libsndfile")
|
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
project(ZMusic
|
2024-10-09 13:55:21 +00:00
|
|
|
VERSION 1.1.14
|
2021-01-08 21:49:44 +00:00
|
|
|
LANGUAGES C CXX
|
|
|
|
)
|
|
|
|
|
2023-08-15 21:36:20 +00:00
|
|
|
if (VCPKG_TOOLCHAIN)
|
|
|
|
if(VCPKG_TARGET_TRIPLET MATCHES "-static$")
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
|
|
endif()
|
2023-08-16 04:36:07 +00:00
|
|
|
|
|
|
|
option(VCPKG_LIBSNDFILE "Import libsndfile from vcpkg" OFF)
|
2023-08-18 18:43:08 +00:00
|
|
|
else()
|
|
|
|
set(VCPKG_MANIFEST_FEATURES)
|
2023-08-15 21:36:20 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
|
|
|
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
include(ZUtility)
|
|
|
|
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
|
|
|
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
2021-03-29 02:06:02 +00:00
|
|
|
# This project is being built standalone
|
|
|
|
|
|
|
|
# Give user option to build shared or static
|
2021-01-08 21:49:44 +00:00
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
2021-03-29 02:06:02 +00:00
|
|
|
|
|
|
|
# Enable install rules
|
|
|
|
set(ZMUSIC_INSTALL ON)
|
|
|
|
else()
|
|
|
|
# This project is being vendored by another project, set option default if
|
|
|
|
# the parent project doesn't provide them.
|
|
|
|
|
|
|
|
if(NOT DEFINED BUILD_SHARED_LIBS)
|
|
|
|
set(BUILD_SHARED_LIBS ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Although install rules can be avoided with EXCLUDE_FROM_ALL on
|
|
|
|
# add_subdirectory, the EXPORT rules may place certain usage requirements on
|
|
|
|
# targets shared between the two projects.
|
|
|
|
if(NOT DEFINED ZMUSIC_INSTALL)
|
|
|
|
set(ZMUSIC_INSTALL OFF)
|
|
|
|
endif()
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE Debug CACHE STRING
|
2020-01-02 16:52:30 +00:00
|
|
|
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
|
2021-01-08 21:49:44 +00:00
|
|
|
FORCE)
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
if(MSVC AND CMAKE_VERSION VERSION_LESS 3.15)
|
|
|
|
message(WARNING "Some things may be misconfigured. Please update to CMake >= 3.15 with Visual Studio.")
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|
2021-01-08 21:49:44 +00:00
|
|
|
if(NOT CMAKE_MSVC_RUNTIME_LIBRARY)
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
|
|
|
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE)
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
if(MSVC)
|
|
|
|
# optionally generate assembly output for checking crash locations.
|
|
|
|
option(ZMUSIC_GENERATE_ASM "Generate assembly output." OFF)
|
|
|
|
if(ZMUSIC_GENERATE_ASM)
|
|
|
|
add_compile_options("/FAcs")
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
add_compile_options(
|
|
|
|
"/GF" # String pooling
|
|
|
|
"/Gy" # Function-level linking
|
|
|
|
"/GR-" # Disable run-time type information
|
|
|
|
"/permissive-"
|
|
|
|
"/Oy" "/Oi" "/GS-"
|
|
|
|
|
|
|
|
# Disable warnings for unsecure CRT functions from VC8+
|
|
|
|
"/wd4996"
|
|
|
|
)
|
|
|
|
|
|
|
|
add_compile_definitions(
|
|
|
|
"UNICODE"
|
|
|
|
"_UNICODE"
|
|
|
|
"_WIN32_WINNT=0x0600"
|
|
|
|
# Debug allocations in debug builds
|
|
|
|
$<$<CONFIG:DEBUG>:_CRTDBG_MAP_ALLOC>
|
|
|
|
)
|
|
|
|
|
|
|
|
add_link_options(
|
|
|
|
"/opt:ref" # Eliminate unreferenced functions and data
|
|
|
|
"/opt:icf" # Perform identical COMDAT folding
|
|
|
|
"/nodefaultlib:msvcrt"
|
|
|
|
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:/TSAWARE>
|
|
|
|
"/LARGEADDRESSAWARE"
|
|
|
|
)
|
|
|
|
|
|
|
|
# RelWithDebInfo uses /Ob1 by default instead of Ob2 like Release
|
2020-01-02 16:52:30 +00:00
|
|
|
string(REPLACE "/Ob1 " "/Ob2 " CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} )
|
2021-01-08 21:49:44 +00:00
|
|
|
|
|
|
|
# The CMake configurations set /GR by default, which conflict with our settings.
|
|
|
|
# CMake 3.20 fixes the need to do this
|
2020-01-02 16:52:30 +00:00
|
|
|
string(REPLACE " /GR" " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} )
|
|
|
|
else()
|
2021-01-08 21:49:44 +00:00
|
|
|
add_compile_options("-ffp-contract=off")
|
|
|
|
|
|
|
|
if(APPLE)
|
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
2020-01-02 16:52:30 +00:00
|
|
|
# With standard Apple tools -stdlib=libc++ needs to be specified in order to get
|
|
|
|
# C++11 support using SDKs 10.7 and 10.8.
|
2021-01-08 21:49:44 +00:00
|
|
|
add_compile_options("-stdlib=libc++")
|
|
|
|
add_link_options("-stdlib=libc++")
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2020-01-02 16:52:30 +00:00
|
|
|
# If we're compiling with a custom GCC on the Mac (which we know since g++-4.2 doesn't support C++11) statically link libgcc.
|
2021-01-08 21:49:44 +00:00
|
|
|
add_compile_options("-static-libgcc")
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|
2021-01-08 21:49:44 +00:00
|
|
|
endif()
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
# Initialize our list of find_package dependencies for configure_package_config_file
|
|
|
|
set(ZMUSIC_PACKAGE_DEPENDENCIES "" CACHE INTERNAL "")
|
|
|
|
|
2024-09-28 18:20:40 +00:00
|
|
|
if (WIN32 AND MINGW)
|
|
|
|
add_compile_definitions(-D_UNICODE -DUNICODE)
|
|
|
|
add_compile_definitions(-D__USE_MINGW_ANSI_STDIO=1)
|
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
add_subdirectory(thirdparty)
|
|
|
|
add_subdirectory(source)
|
|
|
|
|
|
|
|
write_basic_package_version_file(
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/ZMusicConfigVersion.cmake
|
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
COMPATIBILITY SameMajorVersion
|
|
|
|
)
|
|
|
|
configure_package_config_file(
|
|
|
|
cmake/ZMusicConfig.cmake.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/ZMusicConfig.cmake
|
|
|
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
|
|
|
|
)
|
2021-03-29 02:06:02 +00:00
|
|
|
if(ZMUSIC_INSTALL)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ZMusicConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/ZMusicConfigVersion.cmake
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ZMusic
|
|
|
|
COMPONENT devel
|
|
|
|
)
|
|
|
|
endif()
|
2021-01-08 21:49:44 +00:00
|
|
|
|
|
|
|
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
|
|
set(CPACK_PACKAGE_CONTACT "First Last <example@example.com>" CACHE STRING "Contact info for archive maintainer.")
|
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "GZDoom's music system as a standalone library")
|
|
|
|
string(TOLOWER "${PROJECT_NAME}" CPACK_PACKAGE_NAME)
|
|
|
|
set(CPACK_PACKAGE_NAME "lib${CPACK_PACKAGE_NAME}")
|
|
|
|
# Use same prefix for packaging for consistency
|
|
|
|
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
|
|
|
set(CPACK_STRIP_FILES ON)
|
|
|
|
set(CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
|
|
|
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
|
|
|
|
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
|
|
|
|
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
|
|
|
|
|
|
|
|
set(CPACK_COMPONENT_DEVEL_DEPENDS Full Lite)
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
set(CPACK_GENERATOR "ZIP")
|
|
|
|
else()
|
|
|
|
set(CPACK_GENERATOR "DEB")
|
|
|
|
set(CPACK_DEB_COMPONENT_INSTALL ON)
|
|
|
|
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON)
|
|
|
|
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://zdoom.org")
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
|
|
|
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION ON)
|
|
|
|
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
|
|
|
|
|
|
|
|
set(CPACK_DEBIAN_FULL_PACKAGE_NAME "${CPACK_PACKAGE_NAME}${PROJECT_VERSION_MAJOR}")
|
|
|
|
set(CPACK_DEBIAN_LITE_PACKAGE_NAME "${CPACK_PACKAGE_NAME}lite${PROJECT_VERSION_MAJOR}")
|
|
|
|
|
|
|
|
set(CPACK_DEBIAN_DEVEL_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-dev")
|
|
|
|
set(CPACK_DEBIAN_DEVEL_PACKAGE_SECTION "libdevel")
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-08 21:49:44 +00:00
|
|
|
include(CPack)
|
2020-01-02 16:52:30 +00:00
|
|
|
endif()
|