-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathCMakeLists.txt
208 lines (174 loc) · 6.29 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
cmake_minimum_required(VERSION 3.15)
project(puNES)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
string(TIMESTAMP COMPILED_TIMESTAMP "%m%d%Y%H%M%S")
#variable_watch(ENABLE_WIN_STATIC_QT560)
# Options
option(ENABLE_GIT_INFO "Include Git info" OFF)
option(ENABLE_RELEASE "Build release version" ON)
option(ENABLE_FFMPEG "Enable FFMPEG support" ON)
option(ENABLE_OPENGL "Use OpenGL support instead of Direct3D 9 (only for Windows)" ON)
option(ENABLE_OPENGL_CG "Enable OpenGL nVidia Cg Toolkit support" OFF)
option(ENABLE_FULLSCREEN_RESFREQ "Enable Fullscreen resolution and auto frequency" ON)
option(ENABLE_QT6_LIBS "Enable support for QT6 libraries" OFF)
option(ENABLE_WIN_STATIC_QT "Use precompiled Qt static library (only for Windows)" OFF)
option(ENABLE_WIN_STATIC_QT560 "Use precompiled Qt 5.6.3 static library (only for Windows)" OFF)
option(DISABLE_PORTABLE_MODE "Disable compiling portable mode management (useful in sandbox environments like Flatpak)" OFF)
if (ENABLE_GIT_INFO)
find_package(Git)
if(Git_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_LAST_COMMIT
ERROR_VARIABLE git_describe_error
RESULT_VARIABLE git_describe_result
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_LAST_COMMIT_HASH
ERROR_VARIABLE git_describe_error
RESULT_VARIABLE git_describe_result
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COUNT_COMMITS
ERROR_VARIABLE git_describe_error
RESULT_VARIABLE git_describe_result
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
endif()
# For installation targets
include(GNUInstallDirs)
# sizeof checking for xdelta config.h generation
include(CheckTypeSize)
check_type_size("size_t" SIZEOF_SIZE_T)
check_type_size("unsigned int" SIZEOF_UNSIGNED_INT)
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
configure_file(xdelta_config.h.in config.h)
configure_file(compiled.h.in compiled.h)
include(TargetArch)
target_architecture(HOST_CPU)
# handling external dependencies
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC_SEARCH_PATHS gui/designer)
set(QT_LIBS_USED "")
set(WIN_LIBS_USED "")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(ALSA REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(UDEV REQUIRED IMPORTED_TARGET libudev)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
find_package(Sndio REQUIRED)
find_package(UsbHid REQUIRED)
set(ENABLE_OPENGL_CG OFF)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(ENABLE_FULLSCREEN_RESFREQ)
find_package(X11 REQUIRED)
endif()
# No alternatives, force selection
set(ENABLE_OPENGL ON)
if(ENABLE_OPENGL_CG)
find_package(Cg REQUIRED)
endif()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(ENABLE_WIN_STATIC_QT560)
set(ENABLE_WIN_STATIC_QT ON)
endif()
# No alternatives, force selection
set(ENABLE_OPENGL_CG ${ENABLE_OPENGL})
set(ENABLE_FULLSCREEN_RESFREQ ON)
else()
set(ENABLE_WIN_STATIC_QT OFF)
set(ENABLE_WIN_STATIC_QT560 OFF)
endif()
# OpenGL is required for Qt, even in the case of D3D9.
if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND (NOT OpenGL_GL_PREFERENCE))
# See CMP0072 for more details (cmake --help-policy CMP0072)
set(OpenGL_GL_PREFERENCE "GLVND")
endif()
find_package(OpenGL REQUIRED)
if(ENABLE_QT6_LIBS)
find_package(Qt6 6.0.0 COMPONENTS Core LinguistTools Widgets Network Svg Gui OpenGLWidgets REQUIRED)
set(QT_VERSION ${Qt6_VERSION})
else()
find_package(Qt5 5.6.3 COMPONENTS Core LinguistTools Widgets Network Svg Gui REQUIRED)
set(QT_VERSION ${Qt5_VERSION})
endif()
message(STATUS "Found Qt: ${QT_VERSION}")
if(${QT_VERSION} VERSION_LESS "5.15.0")
macro(qt_add_translation)
qt5_add_translation(${ARGN})
endmacro()
macro(qt_add_resources)
qt5_add_resources(${ARGN})
endmacro()
endif()
if(ENABLE_WIN_STATIC_QT)
include(WinStaticQt)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(ENABLE_FFMPEG)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
libavformat
libavcodec
libswresample
libswscale
libavutil
)
endif()
if(${QT_VERSION} VERSION_LESS "5.15.0")
set(QT_LIBS_USED ${QT_LIBS_USED} Qt5::Core)
set(QT_LIBS_USED ${QT_LIBS_USED} Qt5::Network)
set(QT_LIBS_USED ${QT_LIBS_USED} Qt5::Widgets)
set(QT_LIBS_USED ${QT_LIBS_USED} Qt5::Svg)
set(QT_LIBS_USED ${QT_LIBS_USED} Qt5::Gui)
else()
set(QT_LIBS_USED ${QT_LIBS_USED} Qt::Core)
set(QT_LIBS_USED ${QT_LIBS_USED} Qt::Network)
set(QT_LIBS_USED ${QT_LIBS_USED} Qt::Widgets)
set(QT_LIBS_USED ${QT_LIBS_USED} Qt::Svg)
set(QT_LIBS_USED ${QT_LIBS_USED} Qt::Gui)
if(${QT_VERSION} VERSION_GREATER_EQUAL "6.0.0")
set(QT_LIBS_USED ${QT_LIBS_USED} Qt::OpenGLWidgets)
endif()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(WIN_LIBS_USED ${WIN_LIBS_USED} ws2_32)
set(WIN_LIBS_USED ${WIN_LIBS_USED} imm32)
set(WIN_LIBS_USED ${WIN_LIBS_USED} cg)
if(ENABLE_OPENGL)
if(ENABLE_OPENGL_CG)
set(WIN_LIBS_USED ${WIN_LIBS_USED} cgGL)
endif()
else()
set(WIN_LIBS_USED ${WIN_LIBS_USED} cgD3D9)
set(WIN_LIBS_USED ${WIN_LIBS_USED} d3d9)
endif()
endif()
add_subdirectory(src)
# Install misc files
install(FILES misc/io.github.punesemu.puNES.desktop.in
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications RENAME io.github.punesemu.puNES.desktop)
foreach(SIZE "16" "22" "24" "32" "48" "64" "256" "512")
install(FILES misc/hicolor_apps_${SIZE}x${SIZE}_io.github.punesemu.puNES.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${SIZE}x${SIZE}/apps RENAME io.github.punesemu.puNES.png)
endforeach()
install(FILES misc/io.github.punesemu.puNES.metainfo.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo)
install(FILES misc/nes20db.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/puNES)
install(FILES misc/dip.cfg DESTINATION ${CMAKE_INSTALL_DATADIR}/puNES)
install(FILES README.md ChangeLog DESTINATION ${CMAKE_INSTALL_DOCDIR})