forked from mmuman/OpenBoardView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
154 lines (137 loc) · 5.19 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
cmake_minimum_required(VERSION 3.0)
# We now use project() VERSION parameter
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()
# Targets with semicolon are imported targets
if(POLICY CMP0028)
cmake_policy(SET CMP0028 NEW)
endif()
# Set OSX target version, before calling project() (inside version.cmake). FORCE is needed when project() is called within an included file
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version" FORCE)
# According to CMake doc, project() must be called in the top-level file, not in an included file
# Also since CMake 3.0 version should be defined using project() too
# VERSION must be up to 4 groups of digits separated by a period.
# major.90 are alpha releases
project(OpenBoardView VERSION 8.95.1)
# Include our project variables
include("version.cmake")
# Colorized output. Checks TERM to exclude Windows command prompt
if(DEFINED ENV{TERM})
string(ASCII 27 Esc)
set(CGreenB "${Esc}[1;32m")
set(CReset "${Esc}[m")
endif()
# Build info
if (NOT DEFINED OBV_BUILD)
if(EXISTS "${PROJECT_SOURCE_DIR}/.git/")
execute_process(
COMMAND git rev-list HEAD --count
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git name-rev --name-only HEAD
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git config branch.${GIT_BRANCH}.remote
OUTPUT_VARIABLE GIT_REMOTE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git config remote.${GIT_REMOTE}.url
OUTPUT_VARIABLE GIT_URL
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE ".*/(.+)/.+$" "\\1" GIT_REPO "${GIT_URL}") # Extract the user from a Github repo URL
set(OBV_BUILD "R${GIT_REVISION} ${GIT_REPO}/${GIT_BRANCH}")
else()
set(OBV_BUILD "${PROJECT_VERSION}")
endif()
endif()
message("${PROJECT_NAME} release:${CGreenB} ${OBV_BUILD}${CReset}")
# GCC version check
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8")
message(FATAL_ERROR "GCC version needs to be >= 4.8")
endif()
endif()
# Extra CMake modules (Find*.cmake) are in CMakeModules/
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules)
set(INSTALL_RUNTIME_DIR bin)
set(INSTALL_ARCHIVE_DIR lib)
if(APPLE)
set(BUNDLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/src/openboardview/openboardview.app")
# set(LIBRARY_OUTPUT_PATH "${BUNDLE_OUTPUT_PATH}/Contents/MacOS") # We don't want to put static lib inside the bundle
set(INSTALL_LIBRARY_DIR "openboardview.app/Contents/MacOS")
set(INSTALL_BUNDLE_DIR .)
else()
set(INSTALL_LIBRARY_DIR lib)
endif()
# Warning with CMake 3.0 on OS X
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
if(NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Werror=format-security")
endif()
set(CMAKE_CXX_STANDARD 11)
# Inject variables into version.h
configure_file("${PROJECT_SOURCE_DIR}/src/openboardview/version.in.h"
"${PROJECT_BINARY_DIR}/include/version.h"
@ONLY ESCAPE_QUOTES)
include_directories("${PROJECT_BINARY_DIR}/include")
add_subdirectory(asset)
add_subdirectory(src)
set(CPACK_BUNDLE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
set(CPACK_PACKAGE_CONTACT "piernov <[email protected]>")
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}")
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
set(CPACK_STRIP_FILES 1)
endif()
if(APPLE)
set(CPACK_GENERATOR DragNDrop CACHE STRING "List of generators to build packages with")
set(CPACK_DMG_VOLUME_NAME "OpenBoardView")
# set(CPACK_DMG_FORMAT "UDRW") # Read-write DMG
set(CPACK_DMG_BACKGROUND_IMAGE ${CMAKE_CURRENT_SOURCE_DIR}/asset/screenshot.png)
set(CPACK_DMG_DS_STORE ${CMAKE_CURRENT_SOURCE_DIR}/asset/DMG.DS_Store)
set(DIRS "\${LIBRARY_OUTPUT_PATH};/Library/Frameworks")
INSTALL(CODE "
set(BU_CHMOD_BUNDLE_ITEMS ON)
file(GLOB_RECURSE LIBS
\"${BUNDLE_OUTPUT_PATH}/Contents/MacOS/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
include(BundleUtilities)
fixup_bundle(\"${BUNDLE_OUTPUT_PATH}\" \"\${LIBS}\" \"${DIRS}\")
")
elseif(UNIX)
set(CPACK_GENERATOR DEB RPM CACHE STRING "List of generators to build packages with")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "zlib1g, libgtk-3-0, sqlite3, libsdl2-2.0-0, libfontconfig1")
set(CPACK_DEBIAN_PACKAGE_SECTION "electronics")
set(CPACK_DEBIAN_PACKAGE_RELEASE 1)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_RPM_PACKAGE_GROUP "Applications/Engineering")
set(CPACK_RPM_PACKAGE_REQUIRES "gtk3") # Probably not working
set(CPACK_RPM_PACKAGE_LICENSE "${PROJECT_LICENSE}")
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
"/usr/share/appdata"
"/usr/share/applications"
"/usr/share/icons"
"/usr/share/icons/hicolor"
"/usr/share/icons/hicolor/scalable"
"/usr/share/icons/hicolor/scalable/apps"
"/usr/share/mime"
"/usr/share/mime/packages")
elseif(WIN32)
set(CPACK_GENERATOR ZIP CACHE STRING "List of generators to build packages with")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE)
endif()
INCLUDE(CPack)