forked from cginternals/globjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
169 lines (136 loc) · 6.89 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
cmake_minimum_required(VERSION 2.8.9 FATAL_ERROR)
# PROJECT DESCRIPTION
set(META_PROJECT_NAME "globjects")
set(META_VERSION_MAJOR "0")
set(META_VERSION_MINOR "3")
set(META_VERSION_PATCH "2")
set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}")
set(META_AUTHOR_ORGANIZATION "hpicgs group")
set(META_AUTHOR_DOMAIN "https://github.com/hpicgs/globjects/")
set(META_AUTHOR_MAINTAINER "[email protected]")
# OPTIONS
option(OPTION_LIMIT_CONFIGS "Generate limited configs (Release; Debug)" ON)
option(OPTION_PORTABLE_INSTALL "Install to a local directory instead of the system" OFF)
option(OPTION_BUILD_STATIC "Build static libraries" OFF)
option(OPTION_BUILD_TESTS "Build tests (if gmock and gtest are found)" ON)
option(OPTION_BUILD_EXAMPLES "Build examples (requires GLFW)" ON)
option(OPTION_ERRORS_AS_EXCEPTION "Throw exceptions" OFF)
if(OPTION_BUILD_STATIC)
set(BUILD_SHARED_LIBS OFF)
message("Note: ${META_PROJECT_NAME_UPPER}_STATIC needs to be defined for static linking.")
else()
set(BUILD_SHARED_LIBS ON)
endif()
#
# CMake configuration
#
# Include cmake modules from ./cmake
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Set configuration types
if(OPTION_LIMIT_CONFIGS)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Limited Configs" FORCE)
endif()
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: ${CMAKE_CONFIGURATION_TYPES}")
# Reorder CMAKE_CONFIGURATION_TYPES list so that the chosen CMAKE_BUILD_TYPE is the first element.
if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES "${CMAKE_BUILD_TYPE}")
list(INSERT CMAKE_CONFIGURATION_TYPES 0 "${CMAKE_BUILD_TYPE}")
endif()
# Project
project(${META_PROJECT_NAME} C CXX)
# Generate folders for IDE targets (e.g., VisualStudio solutions)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(IDE_FOLDER "") # Put projects in root folder by default
# Include custom cmake functions
include(cmake/Custom.cmake)
include(cmake/GitRevision.cmake)
#
# Platform and architecture
#
# Architecture (32/64 bit)
set(X64 OFF)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(X64 ON)
endif()
# This policy was introduced in 3.0.0 and does not allow for COMPILER_DEFINITIONS_<Config>,
# anymore, but instead requires generator expressions like $<CONFIG:Debug> ...
# For now the current compile-flag, -definitions, and linker-flags setup shall remain as is.
if(POLICY CMP0043)
cmake_policy(SET CMP0043 OLD)
endif()
# Setup platform specifics (compile flags, etc., ...)
if(MSVC)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/PlatformWindowsMSVC.cmake)
elseif(WIN32 AND CMAKE_COMPILER_IS_GNUCXX)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/PlatformWindowsGCC.cmake)
elseif(APPLE)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/PlatformMacOS.cmake)
elseif(UNIX)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/PlatformLinuxGCC.cmake)
else()
message(WARNING "Unsupported platform/compiler combination")
endif()
# Installation paths
set(project ${META_PROJECT_NAME})
if(WIN32)
set(INSTALL_ROOT ".") # C:\Programme\<project>
set(INSTALL_EXAMPLES "bin") # C:\Programme\<project>
set(INSTALL_DATA "bin") # C:\Programme\<project>
set(INSTALL_BIN "bin") # C:\Programme\<project>
set(INSTALL_SHARED ".") # C:\Programme\<project>
set(INSTALL_LIB "lib") # C:\Programme\<project>\lib
set(INSTALL_INCLUDE "include") # C:\Programme\<project>\include
set(INSTALL_DOC "doc") # C:\Programme\<project>\doc
set(INSTALL_SHORTCUTS ".") # Not available under Windows
set(INSTALL_ICONS ".") # Not available under Windows
set(INSTALL_INIT ".") # Not available under Windows
else()
set(INSTALL_ROOT "share/${project}") # /usr/[local]/share/<project>
set(INSTALL_EXAMPLES "share/${project}/examples") # /usr/[local]/share/<project>/examples
set(INSTALL_DATA "share/${project}/examples") # /usr/[local]/share/<project>
set(INSTALL_BIN "bin") # /usr/[local]/bin
set(INSTALL_SHARED "lib") # /usr/[local]/lib
set(INSTALL_LIB "lib") # /usr/[local]/lib
set(INSTALL_INCLUDE "include") # /usr/[local]/include
set(INSTALL_DOC "share/doc/${project}") # /usr/[local]/share/doc/<project>
set(INSTALL_SHORTCUTS "share/applications") # /usr/[local]/share/applications
set(INSTALL_ICONS "share/pixmaps") # /usr/[local]/share/pixmaps
set(INSTALL_INIT "/etc/init") # /etc/init (upstart init scripts)
# Adjust target paths for portable installs
if(OPTION_PORTABLE_INSTALL)
# Put binaries in root directory and keep data directory name
set(INSTALL_ROOT ".") # <INSTALL_PREFIX>/
set(INSTALL_EXAMPLES ".") # <INSTALL_PREFIX>/
set(INSTALL_DATA ".") # <INSTALL_PREFIX>/
set(INSTALL_BIN ".") # <INSTALL_PREFIX>/
# We have to change the RPATH of binaries to achieve a usable local install.
# [TODO] For binaries, "$ORIGIN/lib" is right, so that libraries are found in ./lib.
# However, I have not yet tested what happens when libraries use other libraries.
# In that case, they might need the rpath $ORIGIN instead ...
set(CMAKE_SKIP_BUILD_RPATH FALSE) # Use automatic rpath for build
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Use specific rpath for INSTALL
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) # NO automatic rpath for INSTALL
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Libraries are relative to binary
endif()
endif()
#
# Global deployment
#
# Project meta files
install(FILES globjects-config.cmake DESTINATION ${INSTALL_ROOT})
install(FILES AUTHORS DESTINATION ${INSTALL_ROOT})
install(FILES LICENSE DESTINATION ${INSTALL_ROOT})
# Add a revision file containing the git-head tag for cpack and install
create_revision_file(${CMAKE_BINARY_DIR}/revision ${INSTALL_ROOT})
# Data files
install(DIRECTORY ${CMAKE_SOURCE_DIR}/data DESTINATION ${INSTALL_DATA})
#
# Include projects
#
add_subdirectory(source)
add_subdirectory(docs)
add_subdirectory(packages)