-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
192 lines (159 loc) · 6.02 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
cmake_minimum_required(VERSION 3.13...3.19)
if (VCPKG_LIBSNDFILE)
list(APPEND VCPKG_MANIFEST_FEATURES "vcpkg-libsndfile")
endif()
project(ZMusic
VERSION 1.1.14
LANGUAGES C CXX
)
if (VCPKG_TOOLCHAIN)
if(VCPKG_TARGET_TRIPLET MATCHES "-static$")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
option(VCPKG_LIBSNDFILE "Import libsndfile from vcpkg" OFF)
else()
set(VCPKG_MANIFEST_FEATURES)
endif()
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)
# This project is being built standalone
# Give user option to build shared or static
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
# 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()
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
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.")
endif()
if(NOT CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix" FORCE)
endif()
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")
endif()
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
string(REPLACE "/Ob1 " "/Ob2 " CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} )
# The CMake configurations set /GR by default, which conflict with our settings.
# CMake 3.20 fixes the need to do this
string(REPLACE " /GR" " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} )
else()
add_compile_options("-ffp-contract=off")
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# With standard Apple tools -stdlib=libc++ needs to be specified in order to get
# C++11 support using SDKs 10.7 and 10.8.
add_compile_options("-stdlib=libc++")
add_link_options("-stdlib=libc++")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# 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.
add_compile_options("-static-libgcc")
endif()
endif()
endif()
# Initialize our list of find_package dependencies for configure_package_config_file
set(ZMUSIC_PACKAGE_DEPENDENCIES "" CACHE INTERNAL "")
if (WIN32 AND MINGW)
add_compile_definitions(-D_UNICODE -DUNICODE)
add_compile_definitions(-D__USE_MINGW_ANSI_STDIO=1)
endif()
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
)
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()
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CPACK_PACKAGE_CONTACT "First Last <[email protected]>" 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")
endif()
include(CPack)
endif()