-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
86 lines (65 loc) · 2.49 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
cmake_minimum_required(VERSION 3.6.0)
project(appenv)
option(BUILD_EXAMPLES "Build example code" ON)
option(BUILD_DEBUG "Build a debug release" OFF)
option(BUILD_SHARED "Build a shared library" ON)
option(BUILD_STATIC "Build a static library" OFF)
#library version
set(MAJOR_VERSION 0)
set(MINOR_VERSION 0)
set(PATCH_VERSION 2)
if(${BUILD_DEBUG})
set(RELEASE_VERSION "debug")
else()
set(RELEASE_VERSION "prod")
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.22.0")
add_definitions(-DMAJOR_VERSION=${MAJOR_VERSION})
add_definitions(-DMINOR_VERSION=${MINOR_VERSION})
add_definitions(-DPATCH_VERSION=${PATCH_VERSION})
add_definitions(-DRELEASE_VERSION=\"${RELEASE_VERSION}\")
else()
add_compile_definitions(MAJOR_VERSION=${MAJOR_VERSION})
add_compile_definitions(MINOR_VERSION=${MINOR_VERSION})
add_compile_definitions(PATCH_VERSION=${PATCH_VERSION})
add_compile_definitions(RELEASE_VERSION=\"${RELEASE_VERSION}\")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_compile_options(-Wall -Wextra -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wmissing-declarations -Wredundant-decls -Wshadow -Woverloaded-virtual -Wno-deprecated -ansi -pedantic -fno-rtti)
#Add the include directory.
include_directories("include")
set(SOURCE "")
add_subdirectory("${PROJECT_SOURCE_DIR}/lib")
#Library building and installation.
if(${BUILD_DEBUG})
set(CMAKE_BUILD_TYPE Debug)
set(LIB_FILENAME "appenv_debug")
else()
set(CMAKE_BUILD_TYPE Release)
set(LIB_FILENAME "appenv")
endif()
if(${BUILD_SHARED})
add_library(appenv_shared SHARED ${SOURCE})
set_target_properties(appenv_shared PROPERTIES OUTPUT_NAME ${LIB_FILENAME})
target_compile_definitions(appenv_shared PUBLIC "-DLIB_VERSION=\"shared\"")
install(TARGETS appenv_shared DESTINATION lib)
message("will build ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-${RELEASE_VERSION}-shared")
endif()
if(${BUILD_STATIC})
add_library(appenv_static STATIC ${SOURCE})
set_target_properties(appenv_static PROPERTIES OUTPUT_NAME ${LIB_FILENAME})
target_compile_definitions(appenv_static PUBLIC "-DLIB_VERSION=\"static\"")
install(TARGETS appenv_static DESTINATION lib)
message("will build ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-${RELEASE_VERSION}-static")
endif()
install(DIRECTORY include/ DESTINATION include/)
IF(WIN32)
if(${BUILD_SHARED)
target_compile_definitions(appenv_shared PUBLIC -DWINBUILD)
endif()
if(${BUILD_STATIC})
target_compile_definitions(appenv_static PUBLIC -DWINBUILD)
endif()
ENDIF()