CMakeLists.txt 3.72 KB
Newer Older
1
#
2
# Use this to compile ACGL as a library. To include it statically compiled into
3
# your own project you can also just include the CMakeListsStaticInclude.txt:
4
# INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/CMakeListsStaticInclude.txt)
5
#
6
CMAKE_MINIMUM_REQUIRED (VERSION 3.0)
7

8 9 10 11
################################################################################
# Global Settings
################################################################################

12
# Name of the Project
13 14
PROJECT(ACGL)

15 16 17
# Link type
SET(ACGL_LINK_TYPE SHARED CACHE STRING "Library link types")

18
# OpenGL Support
19 20
IF(NOT DEFINED ACGL_OPENGL_SUPPORT)
    SET(ACGL_OPENGL_SUPPORT CORE_42 CACHE STRING "")
21
    SET_PROPERTY(CACHE ACGL_OPENGL_SUPPORT PROPERTY STRINGS CORE_32 CORE_33 CORE_40 CORE_41 CORE_42 CORE_43 CORE_42 FULL_21 FULL_30 FULL_31 FULL_32 FULL_33 FULL_40 FULL_41 FULL_42 FULL_43 ES_20)
22
ENDIF()
23

24 25 26 27 28
# Error Level
IF(NOT DEFINED ACGL_ERROR_LEVEL)
    SET(ACGL_ERROR_LEVEL EC0 CACHE STRING "")
    SET_PROPERTY(CACHE ACGL_ERROR_LEVEL PROPERTY STRINGS EC0 EC1 EC2 EC3)
ENDIF()
29

30 31 32
# Build Type (Debug, Release, Deploy, ...)
IF(NOT CMAKE_BUILD_TYPE)
    SET(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
33
ENDIF()
34
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Release Debug Deploy)
35 36 37 38

################################################################################
# Project Files
################################################################################
39

40 41 42 43 44 45 46 47 48 49
# Find all used files of certain file-types
FILE(GLOB_RECURSE SOURCE_FILES_C   "src/*.c")
FILE(GLOB_RECURSE SOURCE_FILES_CC  "src/*.cc")
FILE(GLOB_RECURSE SOURCE_FILES_CPP "src/*.cpp")
FILE(GLOB_RECURSE HEADER_FILES_H   "include/*.h")
FILE(GLOB_RECURSE HEADER_FILES_HH  "include/*.hh")
FILE(GLOB_RECURSE HEADER_FILES_HPP "include/*.hpp")

SET(ACGL_HEADER_FILES ${HEADER_FILES_H} ${HEADER_FILES_HH} ${HEADER_FILES_HPP})
SET(ACGL_SOURCE_FILES ${SOURCE_FILES_C} ${SOURCE_FILES_CC} ${SOURCE_FILES_CPP})
50

51
# Define the Project, add all required sources and dependencies to it
52
ADD_LIBRARY(ACGL ${ACGL_LINK_TYPE} ${ACGL_SOURCE_FILES} ${ACGL_HEADER_FILES})
53

54 55
# static linking for MSVC
IF(ACGL_STATIC_RUNTIME_ENV)
56
  if(MSVC)
57 58 59 60 61 62 63 64 65 66
        foreach(flag
                CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
                CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
            if(${flag} MATCHES "/MD")
                string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
            endif()
        endforeach()
    endif()
ENDIF()

67
################################################################################
68
# Target setup
69
################################################################################
70

71 72 73 74 75 76
# Include directories
target_include_directories(ACGL PUBLIC
  include/
)

# Compile flags
77
if(NOT MSVC)
78 79
target_compile_options(ACGL PUBLIC
  $<$<COMPILE_LANGUAGE:CXX>:-std=c++11> # C++11 for C++ files
80
  -Wno-strict-aliasing # Temporary fix for https://github.com/g-truc/glm/issues/473
81
)
82
endif()
83

84 85 86 87 88 89 90 91 92
# qt support
if (ACGL_COMPILE_WITH_QT)
    find_package(Qt5Core REQUIRED)
    find_package(Qt5OpenGL REQUIRED)
    target_link_libraries(ACGL PUBLIC ${Qt5Core_LIBRARIES} ${Qt5OpenGL_LIBRARIES})
    qt5_use_modules(ACGL OpenGL Network)
    target_compile_definitions(ACGL PUBLIC ACGL_COMPILE_WITH_QT)
endif()

93 94 95 96 97 98 99 100 101
# WIN32 define
IF(WIN32)
  target_compile_definitions(ACGL PUBLIC WIN32)
ENDIF(WIN32)

# DEBUG define
string(TOLOWER ${CMAKE_BUILD_TYPE} BuildTypeLower)
if(BuildTypeLower STREQUAL debug)
  target_compile_definitions(ACGL PUBLIC DEBUG)
102 103
endif()

104 105 106 107 108 109
# OpenGL define
if(${ACGL_OPENGL_SUPPORT} MATCHES "CORE_")
  target_compile_definitions(ACGL PUBLIC ACGL_OPENGL_PROFILE_CORE)
endif()
string(REGEX MATCH "([0-9]+)" ACGL_OPENGL_VERSION ${ACGL_OPENGL_SUPPORT})
target_compile_definitions(ACGL PUBLIC ACGL_OPENGL_VERSION_${ACGL_OPENGL_VERSION})