-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
149 lines (123 loc) · 3.61 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
cmake_minimum_required(VERSION 3.10) # For CXX_STANDARD 17 property on Visual Studio
# Project declaration
project(
MagicPlayer
VERSION 1.0.1
DESCRIPTION "The magic music player"
HOMEPAGE_URL "https://github.com/pinam45/MagicPlayer"
LANGUAGES CXX C
)
# By default build in Release mode
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type: Release, RelWithDebInfo or Debug" FORCE)
endif()
# CMake utilities
get_filename_component(CMUTILS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMutils/cmutils.cmake" ABSOLUTE)
if(EXISTS "${CMUTILS_PATH}")
include(${CMUTILS_PATH})
else()
message(FATAL_ERROR "CMutils is missing, maybe you didn't pull the git submodules")
endif()
# Global config
cmutils_disable_in_sources_build()
cmutils_enable_ide_folders()
cmutils_set_classic_output_folders()
# Libraries
include(cmake/opengl.cmake)
include(cmake/SFML.cmake)
include(cmake/imgui-sfml.cmake)
include(cmake/libmpg123.cmake)
include(cmake/spdlog.cmake)
include(cmake/IconFontCppHeaders.cmake)
include(cmake/utfcpp.cmake)
include(cmake/taglib.cmake)
include(cmake/json.cmake)
# Declare MagicPlayer
add_executable(MagicPlayer)
# Add sources
cmutils_target_sources_folders(
MagicPlayer PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src"
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
# Add includes
target_include_directories(
MagicPlayer PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
# Link dependencies
target_link_libraries(
MagicPlayer PRIVATE
OpenGL::GL
sfml-system
sfml-window
sfml-graphics
sfml-audio
imgui-sfml
libmpg123
spdlog
IconFontCppHeaders
utf8cpp
taglib
nlohmann_json
)
# Link threads library
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(MagicPlayer PRIVATE Threads::Threads)
# Link filesystem library for clang and gcc < 9.0
cmutils_define_compiler_variables()
if(COMPILER_CLANG OR (COMPILER_GCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)))
target_link_libraries(MagicPlayer PRIVATE stdc++fs)
endif()
# Configure compile options
cmutils_target_configure_compile_options(MagicPlayer)
# Enable cmutils default warnings
cmutils_target_enable_warnings(MagicPlayer)
# Build in C++17
cmutils_target_set_standard(MagicPlayer CXX 17)
# Set static runtime
cmutils_target_set_runtime(MagicPlayer STATIC)
# Enable sanitizers in debug
#cmutils_target_enable_sanitizers(
# MagicPlayer
# ADDRESS LEAK UNDEFINED MEMORY
# DEBUG
#)
# WinMain config
if(TARGET sfml-main)
target_link_libraries(MagicPlayer PRIVATE "sfml-main")
set_target_properties(MagicPlayer PROPERTIES WIN32_EXECUTABLE ON)
endif()
# Set target IDE folder
cmutils_target_set_ide_folder(MagicPlayer "MagicPlayer")
# Group sources for IDEs
cmutils_target_source_group(MagicPlayer "${CMAKE_CURRENT_SOURCE_DIR}")
# Visual studio config
get_target_property(magicplayer_binary_folder MagicPlayer RUNTIME_OUTPUT_DIRECTORY)
set_target_properties(
MagicPlayer PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${magicplayer_binary_folder}"
)
set_property(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR} PROPERTY
VS_STARTUP_PROJECT MagicPlayer
)
# Resources
cmutils_configure_folder(
"${CMAKE_CURRENT_SOURCE_DIR}/resources"
"${magicplayer_binary_folder}/resources"
COPYONLY
)
# Enable console log in debug
cmutils_target_add_compile_definition(MagicPlayer ENABLE_CONSOLE_LOG)
# Enable debug / trace logs
cmutils_target_add_compile_definition(MagicPlayer SPDLOG_DEBUG_ON RELWITHDEBINFO DEBUG)
#cmutils_target_add_compile_definition(MagicPlayer SPDLOG_TRACE_ON DEBUG)
# Use ccache
cmutils_target_use_ccache(MagicPlayer)
# Generate format target
cmutils_target_generate_clang_format(MagicPlayer)
# Verbose makefile
#set(CMAKE_VERBOSE_MAKEFILE ON)