comparison CMakeLists.txt @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 cmake_minimum_required (VERSION 3.1)
2
3 project(thymian)
4
5 # CMake Settings
6 SET(CMAKE_COLOR_MAKEFILE ON)
7 SET(CMAKE_VERBOSE_MAKEFILE OFF)
8 set(THYMIAN_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9
10 if(NOT CMAKE_BUILD_TYPE)
11 set(CMAKE_BUILD_TYPE "Debug")
12 endif()
13
14 IF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
15 add_definitions("-DDEBUG_BUILD")
16 message("Debug build for development purposes only")
17 ENDIF()
18
19 include(cmake/TargetArch.cmake)
20 target_architecture(TARGET_CPU)
21 message("Targeting: ${TARGET_CPU}")
22
23 # Options
24 option(ENABLE_TESTS "Enable some unit tests" ON)
25 option(CLANG_SANITIZE "Use specific clang sanitizer compilation, development only" OFF)
26 option(coverage-build "gcov/lcov test coverage analysis (make coverage_test)" OFF)
27
28 # Python
29 find_package (Python3
30 COMPONENTS Interpreter Development Compiler)
31
32 set(CMAKE_CXX_STANDARD 17)
33 set(CMAKE_CXX_STANDARD_REQUIRED ON)
34
35 set(COMMON_COMPILER_FLAGS "-pedantic")
36
37 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
38 if(CLANG_SANITIZE)
39 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILER_FLAGS} -fsanitize=address -fno-omit-frame-pointer -O1 -fno-optimize-sibling-calls")
40 else()
41 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILER_FLAGS} -fPIC -fsanitize=address -fno-omit-frame-pointer -O1 -fno-optimize-sibling-calls")
42 endif()
43 else()
44 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILER_FLAGS} -fpermissive -finline-functions -Wno-long-long -fvisibility-inlines-hidden")
45 endif()
46
47 # Coverage build?
48 if(coverage-build)
49 set(CMAKE_BUILD_TYPE Debug)
50 message("building for coverage ...")
51 SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage -rdynamic -ftest-coverage -fprofile-arcs -fpermissive -finline-functions -Wno-long-long -fvisibility-inlines-hidden -fno-omit-frame-pointer -fsanitize=address")
52 SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage -rdynamic -ftest-coverage -fprofile-arcs -fpermissive -finline-functions -Wno-long-long -fvisibility-inlines-hidden -fno-omit-frame-pointer -fsanitize=address")
53 include(cmake/CodeCoverage.cmake)
54 SETUP_TARGET_FOR_COVERAGE(templater_test ctest coverage)
55 endif()
56
57 MESSAGE("CMAKE FLAGS: ${CMAKE_CXX_FLAGS}")
58 add_definitions("-D_GLIBCXX_USE_CXX11_ABI")
59
60 message("Generator: ${CMAKE_GENERATOR}")
61
62 ## Compiler flags
63 if(CMAKE_COMPILER_IS_GNUCXX)
64 # Optimize the stuff if building RELEASE
65 if(CMAKE_BUILD_TYPE MATCHES RELEASE)
66 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Os") ## Optimize
67 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s") ## Strip binary
68 else()
69 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") ## All warnings, please
70 endif()
71
72 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
73 message("GCC version: ${CMAKE_CXX_COMPILER_VERSION}")
74
75 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.1)
76 add_definitions(-Wimplicit-fallthrough=0)
77 endif()
78 endif()
79
80 endif()
81
82 # Generate the header files for version info
83 set(WEB_VERSION_MAJOR 1)
84 set(WEB_VERSION_MINOR 0)
85 set(WEB_VERSION_PATCH 0)
86
87 configure_file (
88 ${CMAKE_CURRENT_SOURCE_DIR}/version.h.tpl
89 ${CMAKE_CURRENT_BINARY_DIR}/version.h
90 )
91
92 # Include directories
93 set(CMAKE_INCLUDE_CURRENT_DIR ON)
94
95 include_directories(
96 SYSTEM
97 ${CONAN_INCLUDE_DIRS}
98 ${CMAKE_CURRENT_BINARY_DIR}
99 ${CMAKE_CURRENT_SOURCE_DIR}
100 ${CMAKE_CURRENT_SOURCE_DIR}/templates
101 ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/compressor
102 ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/tinyxml
103 ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty
104 ${CMAKE_CURRENT_SOURCE_DIR}/common
105 ${CMAKE_CURRENT_SOURCE_DIR}/cppdb
106 ${Python3_INCLUDE_DIRS}
107 )
108
109 add_definitions("-DPYTHON_SCRIPTING")
110
111 add_subdirectory(cppdb)
112 add_subdirectory(common)
113 add_subdirectory(3rdparty/tinyxml)
114 add_subdirectory(3rdparty/compressor)
115 add_subdirectory(mailer)
116 add_subdirectory(templates)
117 add_subdirectory(server)
118
119 if(ENABLE_TESTS)
120 add_subdirectory(tests)
121 enable_testing()
122 add_test(NAME templater_test COMMAND templ_test)
123 endif()