-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use modern CMake(>=3.5.2) features
Refactored the library build procedure into a more modular format using new cmake features.
- Loading branch information
Showing
63 changed files
with
1,411 additions
and
1,067 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,78 @@ | ||
CMAKE_MINIMUM_REQUIRED(VERSION 3.0) | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
OPTION(USE_HUNTER "Use Hunter cmake package handler" OFF) | ||
project(Forge VERSION 1.1.0 LANGUAGES C CXX) | ||
|
||
if(USE_HUNTER) | ||
include(${CMAKE_CURRENT_LIST_DIR}/CMakeModules/HunterGate.cmake) | ||
|
||
HunterGate( | ||
URL "https://github.com/ruslo/hunter/archive/v0.18.43.tar.gz" | ||
SHA1 "d2c8c42cd07f7cefe18fd9a9b9c13114b1a15a27" | ||
# LOCAL | ||
) | ||
endif() | ||
|
||
PROJECT(FORGE) | ||
|
||
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) | ||
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") | ||
INCLUDE(FGInstallDirs) | ||
INCLUDE(Version) | ||
|
||
|
||
############################## BEGIN - CMAKE OPTIONS ########################## | ||
OPTION(BUILD_DOCUMENTATION "Build Documentation" OFF) | ||
OPTION(BUILD_EXAMPLES "Build Examples" ON) | ||
OPTION(USE_FREEIMAGE "Use freeimage to allow saving of charts" ON) | ||
|
||
# Set a default build type if none was specified | ||
IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | ||
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) | ||
# Set the possible values of build type for cmake-gui | ||
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" | ||
"MinSizeRel" "RelWithDebInfo") | ||
ENDIF() | ||
############################## END - CMAKE OPTIONS ########################## | ||
|
||
|
||
############################## BEGIN - OS Definitions ######################### | ||
IF(UNIX) | ||
ADD_DEFINITIONS(-Wall -std=c++11 -fvisibility=hidden) | ||
ENDIF() | ||
set_property(GLOBAL PROPERTY USE_FOLDERS ON) | ||
|
||
IF(UNIX) | ||
IF(APPLE) | ||
ADD_DEFINITIONS(-DOS_MAC) | ||
SET(CMAKE_MACOSX_RPATH ON) | ||
SET(CMAKE_SKIP_BUILD_RPATH FALSE) | ||
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) | ||
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}") | ||
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) | ||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") | ||
set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}prefix;${CMAKE_PREFIX_PATH}") | ||
|
||
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}" isSystemDir) | ||
IF("${isSystemDir}" STREQUAL "-1") | ||
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}") | ||
ENDIF("${isSystemDir}" STREQUAL "-1") | ||
ELSE(APPLE) | ||
ADD_DEFINITIONS(-DOS_LNX) | ||
ENDIF(APPLE) | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") | ||
ELSE(UNIX) | ||
ADD_DEFINITIONS(-DOS_WIN -DNOMINMAX) | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | ||
ENDIF(UNIX) | ||
############################## END - OS Definitions ########################### | ||
include(BuildType) | ||
include(CMakeDependentOption) | ||
include(ConditionalDirectory) | ||
include(DependencyCheck) | ||
include(Version) | ||
include(FGInstallDirs) | ||
|
||
find_package(Doxygen QUIET) | ||
find_package(glbinding REQUIRED) | ||
find_package(glm REQUIRED) | ||
find_package(FreeType) | ||
find_package(FontConfig QUIET) | ||
find_package(X11 QUIET) | ||
find_package(FreeImage QUIET) | ||
find_package(Boost) | ||
|
||
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/include") | ||
option(BUILD_DOCS "Build Documentation" ${DOXYGEN_FOUND}) | ||
option(BUILD_EXAMPLES "Build Examples" ON) | ||
option(WITH_FREEIMAGE "Use FreeImage to add support for | ||
saving framebuffer to disk" ${FreeImage_FOUND}) | ||
|
||
## X11 libraries need to be explicitly linked on MacOS | ||
## This is required by both examples and the library itself | ||
## Hence, it is placed here. | ||
SET(X11_LIBS "") | ||
IF(APPLE) | ||
FIND_PACKAGE(X11 REQUIRED) | ||
INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR}) | ||
SET(X11_LIBS ${X11_LIBRARIES}) | ||
ENDIF(APPLE) | ||
if(Boost_FOUND AND NOT TARGET Boost::boost) | ||
add_library(Boost::boost INTERFACE IMPORTED) | ||
set_property(TARGET Boost::boost PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS}) | ||
endif(Boost_FOUND AND NOT TARGET Boost::boost) | ||
|
||
ADD_SUBDIRECTORY(src/backend) | ||
|
||
IF(BUILD_EXAMPLES) | ||
ADD_SUBDIRECTORY(examples) | ||
ENDIF() | ||
set(WINDOW_TOOLKIT "glfw3" CACHE STRING "Choose Window toolkit") | ||
set_property(CACHE WINDOW_TOOLKIT PROPERTY STRINGS "glfw3" "sdl2") | ||
|
||
# Generate documentation | ||
IF(BUILD_DOCUMENTATION) | ||
ADD_SUBDIRECTORY(docs) | ||
ENDIF(BUILD_DOCUMENTATION) | ||
|
||
#-------------------------------------------------------------------- | ||
# Create generated files | ||
#-------------------------------------------------------------------- | ||
INCLUDE(CMakePackageConfigHelpers) | ||
# Set a default build type if none was specified | ||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | ||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) | ||
# Set the possible values of build type for cmake-gui | ||
set_property(CACHE CMAKE_BUILD_TYPE | ||
PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") | ||
endif() | ||
|
||
configure_package_config_file("${PROJECT_SOURCE_DIR}/CMakeModules/ForgeConfig.cmake.in" | ||
"${CMAKE_CURRENT_BINARY_DIR}/ForgeConfig.cmake" | ||
INSTALL_DESTINATION ${FG_INSTALL_CMAKE_DIR} | ||
PATH_VARS CMAKE_INSTALL_PREFIX | ||
NO_CHECK_REQUIRED_COMPONENTS_MACRO) | ||
add_subdirectory(src/backend/common) | ||
add_subdirectory(src/backend/glsl_shaders) | ||
add_subdirectory(src/api/c) | ||
add_subdirectory(src/api/cpp) | ||
add_subdirectory(src/backend/opengl) | ||
|
||
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/ForgeConfigVersion.cmake" | ||
VERSION ${FG_VERSION} | ||
COMPATIBILITY SameMajorVersion) | ||
conditional_directory(BUILD_DOCS docs) | ||
conditional_directory(BUILD_EXAMPLES examples) | ||
|
||
#-------------------------------------------------------------------- | ||
# Install files other than the library, examples and docs | ||
# The library is installed by src/backend/*/CMakeLists.txt | ||
# Install include folder, docs, examples etc. | ||
#-------------------------------------------------------------------- | ||
INSTALL(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" DESTINATION "${FG_INSTALL_INC_DIR}" | ||
install(DIRECTORY include/ | ||
DESTINATION ${FG_INSTALL_INC_DIR} | ||
FILES_MATCHING | ||
PATTERN "*.h" | ||
PATTERN "*.hpp" | ||
PATTERN ".gitignore" EXCLUDE | ||
) | ||
|
||
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/ForgeConfig.cmake" | ||
"${CMAKE_CURRENT_BINARY_DIR}/ForgeConfigVersion.cmake" | ||
DESTINATION ${FG_INSTALL_CMAKE_DIR}) | ||
|
||
# We are only installing the source files for examples. | ||
# So this should not depend on the value of BUILD_EXAMPLES | ||
# These examples will be installed without building the executables for the examples | ||
INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/examples/" | ||
DESTINATION "${FG_INSTALL_EXAMPLE_DIR}" | ||
COMPONENT examples) | ||
) | ||
|
||
INSTALL(FILES | ||
"${PROJECT_SOURCE_DIR}/CMakeModules/FindOpenCL.cmake" | ||
DESTINATION "${FG_INSTALL_EXAMPLE_DIR}/CMakeModules/" | ||
COMPONENT examples) | ||
#-------------------------------------------------------------------- | ||
# Install examples | ||
#-------------------------------------------------------------------- | ||
# install the examples irrespective of the BUILD_EXAMPLES value | ||
# only the examples source files are installed, so the installation of these | ||
# source files does not depend on BUILD_EXAMPLES | ||
# when BUILD_EXAMPLES is OFF, the examples source is installed without | ||
# building the example executables | ||
install(DIRECTORY examples/ #NOTE The slash at the end is important | ||
DESTINATION ${FG_INSTALL_EXAMPLE_DIR} | ||
COMPONENT examples) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Created using code snippet at https://blog.kitware.com/cmake-and-the-default-build-type/ | ||
|
||
# Set a default build type if none was specified | ||
|
||
set(default_build_type "Release") | ||
if(EXISTS "${CMAKE_SOURCE_DIR}/.git") | ||
set(default_build_type "Debug") | ||
endif() | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
message(STATUS "Setting build type to '${default_build_type}' as none was specified.") | ||
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE | ||
STRING "Choose the type of build." FORCE) | ||
# Set the possible values of build type for cmake-gui | ||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" | ||
"MinSizeRel" "RelWithDebInfo") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Includes the directory if the variable is set | ||
function(conditional_directory variable directory) | ||
if(${variable}) | ||
add_subdirectory(${directory}) | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function(dependency_check VAR ERROR_MESSAGE) | ||
if(NOT ${VAR}) | ||
message(SEND_ERROR ${ERROR_MESSAGE}) | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,107 @@ | ||
#sourced from | ||
#https://github.com/rougier/freetype-gl/blob/master/CMakeModules/FindFontConfig.cmake | ||
|
||
# - Try to find Fontconfig | ||
# Once done this will define | ||
# FindFontConfig.cmake | ||
# Author: Pradeep Garigipati <pradeep@arrayfire.com> | ||
# | ||
# Finds the fontconfig libraries | ||
# | ||
# Sets the following variables: | ||
# FontConfig_FOUND | ||
# FontConfig_INCLUDE_DIR | ||
# FontConfig_DYNAMIC_LIBRARY | ||
# FontConfig_STATIC_LIBRARY | ||
# | ||
# Usage: | ||
# find_package(FontConfig) | ||
# if (FontConfig_FOUND) | ||
# target_link_libraries(mylib PRIVATE FontConfig::FontConfig) | ||
# endif (FontConfig_FOUND) | ||
# | ||
# FONTCONFIG_FOUND - system has Fontconfig | ||
# FONTCONFIG_INCLUDE_DIR - the Fontconfig include directory | ||
# FONTCONFIG_LIBRARY - Link these to use Fontconfig | ||
# Redistribution and use is allowed according to the terms of the BSD license. | ||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
# OR if you want to link against the static library: | ||
# | ||
# find_package(FontConfig) | ||
# if (FontConfig_FOUND) | ||
# target_link_libraries(mylib PRIVATE FontConfig::FontConfig_STATIC) | ||
# endif (FontConfig_FOUND) | ||
# | ||
# NOTE: You do not need to include the FontConfig include directories since they | ||
# will be included as part of the target_link_libraries command | ||
|
||
IF ( FONTCONFIG_INCLUDE_DIR AND FONTCONFIG_LIBRARY ) | ||
# in cache already | ||
SET(Fontconfig_FIND_QUIETLY TRUE) | ||
ENDIF ( FONTCONFIG_INCLUDE_DIR AND FONTCONFIG_LIBRARY ) | ||
set(PX ${CMAKE_STATIC_LIBRARY_PREFIX}) | ||
set(SX ${CMAKE_STATIC_LIBRARY_SUFFIX}) | ||
|
||
# use pkg-config to get the directories and then use these values | ||
# in the FIND_PATH() and FIND_LIBRARY() calls | ||
IF (NOT WIN32) | ||
FIND_PACKAGE(PkgConfig) | ||
# in the find_path() and find_library() calls | ||
if (NOT WIN32) | ||
find_package(PkgConfig) | ||
pkg_check_modules(FontConfigPkg QUIET fontconfig) | ||
endif (NOT WIN32) | ||
|
||
pkg_check_modules(FONTCONFIG_PKG QUIET fontconfig) | ||
ENDIF (NOT WIN32) | ||
|
||
FIND_PATH(FONTCONFIG_INCLUDE_DIR NAMES fontconfig/fontconfig.h | ||
find_path(FontConfig_INCLUDE_DIR | ||
NAMES fontconfig/fontconfig.h | ||
PATHS | ||
/usr/local/include | ||
/usr/X11/include | ||
/usr/include | ||
/usr/include | ||
/usr/local/include | ||
/sw/include | ||
/opt/local/include | ||
HINTS | ||
${FONTCONFIG_PKG_INCLUDE_DIRS} # Generated by pkg-config | ||
${FontConfigPkg_INCLUDE_DIRS} # Generated by pkg-config | ||
) | ||
|
||
IF (DEFINED FONTCONFIG_INCLUDE_DIR-NOTFOUND) | ||
MESSAGE(FATAL_ERROR "FontConfig header files not found") | ||
ENDIF (DEFINED FONTCONFIG_INCLUDE_DIR-NOTFOUND) | ||
find_library(FontConfig_DYNAMIC_LIBRARY | ||
NAMES FontConfig fontconfig ${FontConfigPkg_LIBRARY} | ||
PATHS | ||
/usr/local | ||
/usr/X11 | ||
/usr | ||
/sw | ||
/opt/local | ||
/usr/lib/x86_64-linux-gnu | ||
HINTS | ||
${FontConfigPkg_LIBRARY_DIRS} # Generated by pkg-config | ||
PATH_SUFFIXES | ||
lib64 | ||
lib | ||
) | ||
|
||
FIND_LIBRARY(FONTCONFIG_LIBRARY NAMES fontconfig ${FONTCONFIG_PKG_LIBRARY} | ||
find_library(FontConfig_STATIC_LIBRARY | ||
NAMES ${PX}fontconfig${SX} ${PX}FontConfig${SX} ${PX}${FontConfigPkg_LIBRARY}${SX} | ||
PATHS | ||
/usr/local | ||
/usr/X11 | ||
/usr | ||
/usr/local | ||
/usr/X11 | ||
/usr | ||
/sw | ||
/opt/local | ||
/usr/lib/x86_64-linux-gnu | ||
HINTS | ||
${FONTCONFIG_PKG_LIBRARY_DIRS} # Generated by pkg-config | ||
${FontConfigPkg_LIBRARY_DIRS} # Generated by pkg-config | ||
PATH_SUFFIXES | ||
lib64 | ||
lib | ||
lib64 | ||
lib | ||
) | ||
|
||
IF (DEFINED FONTCONFIG_LIBRARY-NOTFOUND) | ||
MESSAGE(FATAL_ERROR "FontConfig library files not found") | ||
ENDIF (DEFINED FONTCONFIG_LIBRARY-NOTFOUND) | ||
mark_as_advanced( | ||
FontConfig_INCLUDE_DIR | ||
FontConfig_DYNAMIC_LIBRARY | ||
FontConfig_STATIC_LIBRARY | ||
) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
|
||
find_package_handle_standard_args(FontConfig | ||
REQUIRED_VARS FontConfig_DYNAMIC_LIBRARY FontConfig_INCLUDE_DIR | ||
) | ||
|
||
INCLUDE(FindPackageHandleStandardArgs) | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Fontconfig DEFAULT_MSG FONTCONFIG_LIBRARY FONTCONFIG_INCLUDE_DIR) | ||
if (FontConfig_FOUND AND NOT TARGET FontConfig::FontConfig) | ||
add_library(FontConfig::FontConfig UNKNOWN IMPORTED) | ||
set_target_properties(FontConfig::FontConfig PROPERTIES | ||
IMPORTED_LINK_INTERFACE_LANGUAGE "C" | ||
IMPORTED_LOCATION ${FontConfig_DYNAMIC_LIBRARY} | ||
INTERFACE_INCLUDE_DIRECTORIES ${FontConfig_INCLUDE_DIR}) | ||
|
||
# show the FONTCONFIG_INCLUDE_DIR and FONTCONFIG_LIBRARY variables only in the advanced view | ||
MARK_AS_ADVANCED(FONTCONFIG_INCLUDE_DIR FONTCONFIG_LIBRARY) | ||
if (FontConfig_STATIC_LIBRARY) | ||
add_library(FontConfig::FontConfig_STATIC UNKNOWN IMPORTED) | ||
set_target_properties(FontConfig::FontConfig_STATIC PROPERTIES | ||
IMPORTED_LINK_INTERFACE_LANGUAGE "C" | ||
IMPORTED_LOCATION "${FontConfig_STATIC_LIBRARY}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${FontConfig_INCLUDE_DIR}") | ||
endif (FontConfig_STATIC_LIBRARY) | ||
endif () |
Oops, something went wrong.