-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
109 lines (93 loc) · 3.85 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
cmake_minimum_required(VERSION 3.12)
project(
libbr
DESCRIPTION "A terrible C++ library with ugly code and useless features."
VERSION 0.0.1
LANGUAGES C CXX
)
#===============================================================================
# CMake
#===============================================================================
set(
CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
${CMAKE_MODULE_PATH}
)
#===============================================================================
# Options
#===============================================================================
include(CMakeDependentOption)
option(LIBBR_ENABLE_SHARED "Build libbr as a shared library." ON)
option(LIBBR_ENABLE_STATIC "Build libbr as a static library." ON)
option(LIBBR_BUILD_TESTS "Build the tests (requires gtest)." ON)
option(LIBBR_BUILD_DOCUMENTATION "Build the libbr documentation." OFF)
option(LIBBR_BUILD_32_BITS "Build 32 bit libbr." OFF)
set(LIBBR_CXX_STANDARD 17 CACHE STRING "C++ standard version expected to compile libbr.")
set(LIBBR_CONFIGURE_IDE_DEFAULT OFF)
if (XCODE OR MSVC_IDE)
set(LIBBR_CONFIGURE_IDE_DEFAULT ON)
endif()
option(LIBBR_CONFIGURE_IDE "Configure libcxx for use within an IDE" ${LIBBR_CONFIGURE_IDE_DEFAULT})
if (NOT LIBBR_ENABLE_SHARED AND NOT LIBBR_ENABLE_STATIC)
message(FATAL_ERROR "libbr must be built as either a shared or static library.")
endif ()
if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
if (LIBBR_BUILD_32_BITS)
message(STATUS "Building 32 bits executables and libraries.")
endif ()
elseif (LIBBR_BUILD_32_BITS)
message(FATAL_ERROR "LIBBR_BUILD_32_BITS=ON is not supported on this platform.")
endif ()
#===============================================================================
# libdir
#===============================================================================
if (NOT DEFINED LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR lib)
endif()
#===============================================================================
# Compiler Flags
#===============================================================================
include(LibbrFlags)
if (LIBBR_CXX_STANDARD LESS 17)
message(FATAL_ERROR "C++17 or greater is required.")
endif()
if (MSVC)
check_cxx_compiler_flag("/std:c++${LIBBR_CXX_STANDARD}" "LIBBR_SUPPORTS_STD_EQ_CXX${LIBBR_CXX_STANDARD}_FLAG")
if (NOT LIBBR_SUPPORTS_STD_EQ_CXX${LIBBR_CXX_STANDARD}_FLAG)
message(FATAL_ERROR "Unsupported C++ standard version: ${LIBBR_CXX_STANDARD}")
endif()
add_compile_flags(/utf-8 /Zc:__cplusplus /std:c++${LIBBR_CXX_STANDARD})
else()
check_cxx_compiler_flag("-std=c++${LIBBR_CXX_STANDARD}" "LIBBR_SUPPORTS_STD_EQ_CXX${LIBBR_CXX_STANDARD}_FLAG")
if (NOT LIBBR_SUPPORTS_STD_EQ_CXX${LIBBR_CXX_STANDARD}_FLAG)
message(FATAL_ERROR "Unsupported C++ standard version: ${LIBBR_CXX_STANDARD}")
endif()
endif()
set(CMAKE_CXX_STANDARD ${LIBBR_CXX_STANDARD})
add_target_flags_if(LIBBR_BUILD_32_BITS "-m32")
#===============================================================================
# Main
#===============================================================================
include_directories(libbr/..)
add_subdirectory(libbr)
#===============================================================================
# Tests
#===============================================================================
add_subdirectory(test)
#===============================================================================
# Setup Doxygen Target
#===============================================================================
if(LIBBR_BUILD_DOCUMENTATION)
find_package(Doxygen)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()
add_custom_target(document
COMMAND ${DOXYGEN_EXECUTABLE} "${PROJECT_SOURCE_DIR}/Doxyfile"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
USES_TERMINAL
)
endif()