|
| 1 | + |
| 2 | +# |
| 3 | +# CMake options |
| 4 | +# |
| 5 | + |
| 6 | +# CMake version |
| 7 | +cmake_minimum_required(VERSION 3.0 FATAL_ERROR) |
| 8 | + |
| 9 | +# |
| 10 | +# Configure CMake environment |
| 11 | +# |
| 12 | + |
| 13 | +# Register general cmake commands |
| 14 | +include(cmake/Custom.cmake) |
| 15 | + |
| 16 | +# Set policies |
| 17 | +set_policy(CMP0028 NEW) # ENABLE CMP0028: Double colon in target name means ALIAS or IMPORTED target. |
| 18 | +set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted. |
| 19 | +set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default. |
| 20 | +set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types. |
| 21 | + |
| 22 | +# Include cmake modules |
| 23 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 24 | + |
| 25 | +include(GenerateExportHeader) |
| 26 | + |
| 27 | +set(WriterCompilerDetectionHeaderFound NOTFOUND) |
| 28 | +# This module is only available with CMake >=3.1, so check whether it could be found |
| 29 | +# BUT in CMake 3.1 this module doesn't recognize AppleClang as compiler, so just use it as of CMake 3.2 |
| 30 | +if (${CMAKE_VERSION} VERSION_GREATER "3.2") |
| 31 | + include(WriteCompilerDetectionHeader OPTIONAL RESULT_VARIABLE WriterCompilerDetectionHeaderFound) |
| 32 | +endif() |
| 33 | + |
| 34 | +# Include custom cmake modules |
| 35 | +include(cmake/GetGitRevisionDescription.cmake) |
| 36 | +include(cmake/HealthCheck.cmake) |
| 37 | +include(cmake/GenerateTemplateExportHeader.cmake) |
| 38 | + |
| 39 | + |
| 40 | +# |
| 41 | +# Project description and (meta) information |
| 42 | +# |
| 43 | + |
| 44 | +# Get git revision |
| 45 | +get_git_head_revision(GIT_REFSPEC GIT_SHA1) |
| 46 | +string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV) |
| 47 | +if(NOT GIT_SHA1) |
| 48 | + set(GIT_REV "0") |
| 49 | +endif() |
| 50 | + |
| 51 | +# Meta information about the project |
| 52 | +set(META_PROJECT_NAME "glscbinding") |
| 53 | +set(META_PROJECT_DESCRIPTION "A C++ binding for the OpenGL SC API, generated using the gl.xml specification.") |
| 54 | +set(META_AUTHOR_ORGANIZATION "CG Internals GmbH") |
| 55 | +set(META_AUTHOR_DOMAIN "https://github.com/cginternals/glscbinding/") |
| 56 | +set(META_AUTHOR_MAINTAINER "[email protected]") |
| 57 | +set(META_VERSION_MAJOR "1") |
| 58 | +set(META_VERSION_MINOR "0") |
| 59 | +set(META_VERSION_PATCH "0") |
| 60 | +set(META_VERSION_REVISION "${GIT_REV}") |
| 61 | +set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}") |
| 62 | +set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})") |
| 63 | +set(META_CMAKE_INIT_SHA "6a6f30b38a1cee31ccac3f091816f28e0f6bce4b") |
| 64 | + |
| 65 | +string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID) |
| 66 | +string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID) |
| 67 | + |
| 68 | +# |
| 69 | +# Project configuration options |
| 70 | +# |
| 71 | + |
| 72 | +# Project options |
| 73 | +option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON) |
| 74 | +option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF) |
| 75 | +option(OPTION_BUILD_TESTS "Build tests." ON) |
| 76 | +option(OPTION_BUILD_GPU_TESTS "Build tests that require an OpenGL context." ON) |
| 77 | +option(OPTION_BUILD_DOCS "Build documentation." OFF) |
| 78 | +option(OPTION_BUILD_TOOLS "Build tools." ON) |
| 79 | +option(OPTION_BUILD_EXAMPLES "Build examples." OFF) |
| 80 | +option(OPTION_BUILD_WITH_BOOST_THREAD "Use boost::thread instead of std::thread." OFF) |
| 81 | + |
| 82 | + |
| 83 | +# |
| 84 | +# Declare project |
| 85 | +# |
| 86 | + |
| 87 | +# Generate folders for IDE targets (e.g., VisualStudio solutions) |
| 88 | +set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 89 | +set(IDE_FOLDER "") |
| 90 | + |
| 91 | +# Declare project |
| 92 | +project(${META_PROJECT_NAME} C CXX) |
| 93 | + |
| 94 | +# Set output directories |
| 95 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| 96 | +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| 97 | +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| 98 | + |
| 99 | +# Create version file |
| 100 | +file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}") |
| 101 | + |
| 102 | + |
| 103 | +# |
| 104 | +# Compiler settings and options |
| 105 | +# |
| 106 | + |
| 107 | +include(cmake/CompileOptions.cmake) |
| 108 | + |
| 109 | + |
| 110 | +# |
| 111 | +# Project Health Check Setup |
| 112 | +# |
| 113 | + |
| 114 | +# Add cmake-init template check cmake targets |
| 115 | +add_check_template_target(${META_CMAKE_INIT_SHA}) |
| 116 | + |
| 117 | +# Configure health check tools |
| 118 | +enable_cppcheck(On) |
| 119 | +enable_clang_tidy(On) |
| 120 | + |
| 121 | + |
| 122 | +# |
| 123 | +# Deployment/installation setup |
| 124 | +# |
| 125 | + |
| 126 | +# Get project name |
| 127 | +set(project ${META_PROJECT_NAME}) |
| 128 | + |
| 129 | +# Check for system dir install |
| 130 | +set(SYSTEM_DIR_INSTALL FALSE) |
| 131 | +if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr" OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local") |
| 132 | + set(SYSTEM_DIR_INSTALL TRUE) |
| 133 | +endif() |
| 134 | + |
| 135 | +# Installation paths |
| 136 | +if(UNIX AND SYSTEM_DIR_INSTALL) |
| 137 | + # Install into the system (/usr/bin or /usr/local/bin) |
| 138 | + set(INSTALL_ROOT "share/${project}") # /usr/[local]/share/<project> |
| 139 | + set(INSTALL_CMAKE "share/${project}/cmake") # /usr/[local]/share/<project>/cmake |
| 140 | + set(INSTALL_EXAMPLES "share/${project}") # /usr/[local]/share/<project> |
| 141 | + set(INSTALL_DATA "share/${project}") # /usr/[local]/share/<project> |
| 142 | + set(INSTALL_BIN "bin") # /usr/[local]/bin |
| 143 | + set(INSTALL_SHARED "lib") # /usr/[local]/lib |
| 144 | + set(INSTALL_LIB "lib") # /usr/[local]/lib |
| 145 | + set(INSTALL_INCLUDE "include") # /usr/[local]/include |
| 146 | + set(INSTALL_DOC "share/doc/${project}") # /usr/[local]/share/doc/<project> |
| 147 | + set(INSTALL_SHORTCUTS "share/applications") # /usr/[local]/share/applications |
| 148 | + set(INSTALL_ICONS "share/pixmaps") # /usr/[local]/share/pixmaps |
| 149 | + set(INSTALL_INIT "/etc/init") # /etc/init (upstart init scripts) |
| 150 | +else() |
| 151 | + # Install into local directory |
| 152 | + set(INSTALL_ROOT ".") # ./ |
| 153 | + set(INSTALL_CMAKE "cmake") # ./cmake |
| 154 | + set(INSTALL_EXAMPLES ".") # ./ |
| 155 | + set(INSTALL_DATA ".") # ./ |
| 156 | + set(INSTALL_BIN ".") # ./ |
| 157 | + set(INSTALL_SHARED "lib") # ./lib |
| 158 | + set(INSTALL_LIB "lib") # ./lib |
| 159 | + set(INSTALL_INCLUDE "include") # ./include |
| 160 | + set(INSTALL_DOC "doc") # ./doc |
| 161 | + set(INSTALL_SHORTCUTS "misc") # ./misc |
| 162 | + set(INSTALL_ICONS "misc") # ./misc |
| 163 | + set(INSTALL_INIT "misc") # ./misc |
| 164 | +endif() |
| 165 | + |
| 166 | +# Set runtime path |
| 167 | +set(CMAKE_SKIP_BUILD_RPATH FALSE) # Add absolute path to all dependencies for BUILD |
| 168 | +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Use CMAKE_INSTALL_RPATH for INSTALL |
| 169 | +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) # Do NOT add path to dependencies for INSTALL |
| 170 | + |
| 171 | +if(NOT SYSTEM_DIR_INSTALL) |
| 172 | + # Find libraries relative to binary |
| 173 | + if(APPLE) |
| 174 | + set(CMAKE_INSTALL_RPATH "@loader_path/../../../${INSTALL_LIB}") |
| 175 | + else() |
| 176 | + set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}") |
| 177 | + endif() |
| 178 | +endif() |
| 179 | + |
| 180 | + |
| 181 | +# |
| 182 | +# Project modules |
| 183 | +# |
| 184 | + |
| 185 | +add_subdirectory(source) |
| 186 | +add_subdirectory(docs) |
| 187 | +add_subdirectory(deploy) |
| 188 | + |
| 189 | + |
| 190 | +# |
| 191 | +# Deployment (global project files) |
| 192 | +# |
| 193 | + |
| 194 | +# Install version file |
| 195 | +install(FILES "${PROJECT_BINARY_DIR}/VERSION" DESTINATION ${INSTALL_ROOT} COMPONENT runtime) |
| 196 | + |
| 197 | +# Install cmake find script for the project |
| 198 | +install(FILES ${META_PROJECT_NAME}-config.cmake DESTINATION ${INSTALL_ROOT} COMPONENT dev) |
| 199 | + |
| 200 | +# Install the project meta files |
| 201 | +install(FILES AUTHORS DESTINATION ${INSTALL_ROOT} COMPONENT runtime) |
| 202 | +install(FILES LICENSE DESTINATION ${INSTALL_ROOT} COMPONENT runtime) |
| 203 | +install(FILES README.md DESTINATION ${INSTALL_ROOT} COMPONENT runtime) |
| 204 | + |
| 205 | +# Install runtime data |
| 206 | +if (TARGET cubescape OR TARGET cubescape-log OR TARGET cubescape-qt) |
| 207 | + install(DIRECTORY ${PROJECT_SOURCE_DIR}/data DESTINATION ${INSTALL_DATA} COMPONENT examples_data) |
| 208 | +endif() |
0 commit comments