-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
192 lines (151 loc) · 6.83 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.5)
set(PROJECT_SHORT_NAME "procalc")
set(PROJECT_LONG_NAME "Pro Office Calculator")
set(APP_TARGET_NAME "procalc")
set(LIB_TARGET_NAME "procalclib")
set(DATA_DIR "${CMAKE_SOURCE_DIR}/data")
set(VERSION_FILE "${CMAKE_SOURCE_DIR}/VERSION")
project(${PROJECT_SHORT_NAME})
file(STRINGS "${VERSION_FILE}" VERSION_STRINGS)
list(GET VERSION_STRINGS 0 PROJECT_VERSION)
message("============================================================")
message(" Configuring ${PROJECT_LONG_NAME} ${PROJECT_VERSION} - ${CMAKE_BUILD_TYPE} build")
message("============================================================")
if (UNIX AND NOT APPLE)
set(LINUX true)
endif()
if (WIN32)
set(QT_DIR "C:/Qt/5.10.1/msvc2017_64")
set(BUILD_SUBDIR "win64")
add_compile_options(-DWIN32)
elseif (APPLE)
set(QT_DIR "/usr/local/Cellar/qt/5.10.1")
set(BUILD_SUBDIR "osx")
else()
set(BUILD_SUBDIR "linux")
endif()
set(PROCALC_DEPENDENCIES_DIR "${CMAKE_SOURCE_DIR}/dependencies/build/${BUILD_SUBDIR}/dist")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${PROCALC_DEPENDENCIES_DIR}/lib/cmake")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${QT_DIR}/lib/cmake")
if (LINUX AND CMAKE_BUILD_TYPE MATCHES Debug)
add_subdirectory(tools)
add_subdirectory(tests)
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
if (USE_LOCAL_DEPS)
message("Using locally built dependencies")
set(TINYXML2_INCLUDE_DIRS "${PROCALC_DEPENDENCIES_DIR}/include")
file(
GLOB_RECURSE
TINYXML2_LIBRARIES
"${PROCALC_DEPENDENCIES_DIR}/lib"
"${CMAKE_SHARED_LIBRARY_PREFIX}tinyxml2${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
else()
find_package(TinyXml2 REQUIRED)
endif()
find_package(Qt5Core CONFIG REQUIRED)
find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5Gui CONFIG REQUIRED)
find_package(Qt5Multimedia CONFIG REQUIRED)
if (PROFILING_ON)
message("Profiling ON")
find_package(GooglePerfTools REQUIRED)
if (NOT DEFINED PROFILE_DURATION)
set(PROFILE_DURATION -1)
endif()
add_compile_options(-DSINGLE_THREAD -DPROFILING_ON)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-as-needed -lprofiler -Wl,--as-needed")
endif()
file(GLOB_RECURSE srcs "${CMAKE_SOURCE_DIR}/src/*.cpp")
list(REMOVE_ITEM srcs "${CMAKE_SOURCE_DIR}/src/main.cpp")
include_directories("${CMAKE_SOURCE_DIR}/src")
include_directories("${PROCALC_DEPENDENCIES_DIR}/include")
include_directories("${QT_DIR}/include")
include_directories("${TINYXML2_INCLUDE_DIRS}")
link_directories("${PROCALC_DEPENDENCIES_DIR}/bin")
link_directories("${QT_DIR}/bin")
if (WIN32)
add_compile_options(-O2)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
elseif (APPLE)
add_compile_options(-O3 -Wall -Wextra)
include_directories("/usr/local/opt/llvm/include")
link_directories("/usr/local/opt/llvm/lib")
else()
add_compile_options(-O3 -Wall -Wextra)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread")
endif()
if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
message("Release mode")
else()
message("Debug mode")
add_compile_options(-DDEBUG)
if (NOT WIN32)
add_compile_options(-g)
endif()
endif()
add_library(${LIB_TARGET_NAME} ${srcs})
target_link_libraries(${LIB_TARGET_NAME} ${TINYXML2_LIBRARIES})
target_link_libraries(${LIB_TARGET_NAME} Qt5::Core)
target_link_libraries(${LIB_TARGET_NAME} Qt5::Widgets)
target_link_libraries(${LIB_TARGET_NAME} Qt5::Gui)
target_link_libraries(${LIB_TARGET_NAME} Qt5::Multimedia)
if (APPLE)
set(ICON_FILE "${CMAKE_SOURCE_DIR}/icons/${PROJECT_SHORT_NAME}.icns")
set(MACOSX_BUNDLE true)
set(MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_LONG_NAME}")
set(MACOSX_BUNDLE_INFO_STRING "${PROJECT_LONG_NAME} ${PROJECT_VERSION}")
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_VERSION}")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}")
set(MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}")
set(MACOSX_BUNDLE_ICON_FILE "procalc.icns")
set_source_files_properties("${ICON_FILE}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_source_files_properties("${VERSION_FILE}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
add_executable(${APP_TARGET_NAME} MACOSX_BUNDLE
"${CMAKE_SOURCE_DIR}/src/main.cpp"
${DATA_FILES}
"${ICON_FILE}"
"${VERSION_FILE}")
else()
add_executable(${APP_TARGET_NAME} "${CMAKE_SOURCE_DIR}/src/main.cpp")
endif()
target_link_libraries(${APP_TARGET_NAME} ${LIB_TARGET_NAME})
file(COPY "${DATA_DIR}" DESTINATION "${CMAKE_BINARY_DIR}")
file(COPY "${VERSION_FILE}" DESTINATION "${CMAKE_BINARY_DIR}")
if (LINUX)
install(TARGETS ${PROJECT_SHORT_NAME} DESTINATION "bin")
install(DIRECTORY "${DATA_DIR}" DESTINATION "share/${PROJECT_SHORT_NAME}")
install(FILES "${VERSION_FILE}" DESTINATION "share/${PROJECT_SHORT_NAME}")
install(FILES "${CMAKE_SOURCE_DIR}/${PROJECT_SHORT_NAME}.desktop" DESTINATION "share/applications")
install(FILES "${CMAKE_SOURCE_DIR}/icons/${PROJECT_SHORT_NAME}.svg" DESTINATION "share/icons/hicolor/scalable/apps")
install(FILES "${CMAKE_SOURCE_DIR}/icons/16/${PROJECT_SHORT_NAME}.png" DESTINATION "share/icons/hicolor/16x16/apps")
install(FILES "${CMAKE_SOURCE_DIR}/icons/22/${PROJECT_SHORT_NAME}.png" DESTINATION "share/icons/hicolor/22x22/apps")
install(FILES "${CMAKE_SOURCE_DIR}/icons/32/${PROJECT_SHORT_NAME}.png" DESTINATION "share/icons/hicolor/32x32/apps")
install(FILES "${CMAKE_SOURCE_DIR}/icons/48/${PROJECT_SHORT_NAME}.png" DESTINATION "share/icons/hicolor/48x48/apps")
install(FILES "${CMAKE_SOURCE_DIR}/icons/64/${PROJECT_SHORT_NAME}.png" DESTINATION "share/icons/hicolor/64x64/apps")
install(FILES "${CMAKE_SOURCE_DIR}/icons/128/${PROJECT_SHORT_NAME}.png" DESTINATION "share/icons/hicolor/128x128/apps")
install(FILES "${CMAKE_SOURCE_DIR}/icons/256/${PROJECT_SHORT_NAME}.png" DESTINATION "share/icons/hicolor/256x256/apps")
install(FILES "${CMAKE_SOURCE_DIR}/${PROJECT_SHORT_NAME}.sh" DESTINATION "games" RENAME "${PROJECT_SHORT_NAME}")
elseif (WIN32)
set(MANIFEST_PATH "${CMAKE_SOURCE_DIR}/windows/dpi_unaware.manifest")
ADD_CUSTOM_COMMAND(
TARGET procalc
POST_BUILD
COMMAND "mt.exe" -manifest \"${MANIFEST_PATH}\" -inputresource:\"$<TARGET_FILE:procalc>\"\;\#1 -outputresource:\"$<TARGET_FILE:procalc>\"\;\#1)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".")
install(TARGETS ${PROJECT_SHORT_NAME} DESTINATION ".")
install(FILES "${PROCALC_DEPENDENCIES_DIR}/bin/tinyxml2.dll" DESTINATION ".")
install(DIRECTORY "${DATA_DIR}" DESTINATION ".")
install(FILES "${VERSION_FILE}" DESTINATION ".")
install(FILES "${CMAKE_SOURCE_DIR}/icons/${PROJECT_SHORT_NAME}.ico" DESTINATION ".")
elseif (APPLE)
install(CODE "set(QT_DIR \"${QT_DIR}\")")
install(CODE "set(DATA_DIR \"${DATA_DIR}\")")
install(SCRIPT "${CMAKE_MODULE_PATH}/osx_bundle.cmake")
endif()
include(InstallRequiredSystemLibraries)