-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
130 lines (102 loc) · 4.14 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#
# Copyright (C) 2019 Clovis Durand <cd.clovel19@gmail.com>
#
# -----------------------------------------------------------------------------
# CMake version required ----------------------------------
cmake_minimum_required(VERSION 3.0)
project(shairport-metadata-reader)
if(NOT DEFINED PRJ_VERSION)
set(PRJ_VERSION "1.0.0")
endif(NOT DEFINED PRJ_VERSION)
#------------------------------------------------------------------------------
# Build definition (to do before calling 'project()')
#------------------------------------------------------------------------------
# Build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
# CASE OF C PROJECT
set(CMAKE_C_STANDARD 99)
if(NOT CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat-security" CACHE STRING "C99 compilation flags" FORCE)
endif(NOT CMAKE_C_FLAGS)
# CASE OF CPP PROJECT
set(CMAKE_CXX_STANDARD 11)
if(NOT CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat-security" CACHE STRING "C++11 compilation flags" FORCE)
endif(NOT CMAKE_CXX_FLAGS)
#------------------------------------------------------------------------------
# Project definition, variable and dependencies
#------------------------------------------------------------------------------
set(CMAKE_PROJECT_NAME ${PROJECT_NAME})
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_PROJECT_BRIEF "ShairPort Sync metadata reader app")
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/image CACHE PATH "" FORCE)
endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(PKG_CONFIG_PATH ${CMAKE_SOURCE_DIR}/../image/lib/pkgconfig CACHE PATH "")
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${PKG_CONFIG_PATH}")
message(STATUS "Pkgconfig extra path are: $ENV{PKG_CONFIG_PATH} ")
# Allow CTest
enable_testing()
# Allow subdirectory test and config
option(ENABLE_TESTS "Enable Tests" 1)
find_package(Doxygen)
option(ENABLE_DOCS "Build API documentation" ${DOXYGEN_FOUND})
#------------------------------------------------------------------------------
# Project version
#------------------------------------------------------------------------------
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE
"^([\\.0-9]+).*"
"\\1"
tmp_VERSION
"${PRJ_VERSION}"
)
string(REGEX REPLACE
"^([0-9]+)\\..*"
"\\1"
tmp_SOVERSION
"${tmp_VERSION}"
)
# Major version is for product/marketing purpose
# Minor version is incremented everytime it gets public
set(MAJ_MIN_VERSION ${tmp_VERSION} CACHE STRING "Major and minor version" FORCE)
# Release version is incremented everytime it gets use inside the company
set(RELEASE_VERSION ${tmp_SOVERSION} CACHE STRING "Release version" FORCE)
# Build version is generated using the hash of the current commit build with
set(BUILD_VERSION ${GIT_COMMIT_HASH} CACHE STRING "Build version" FORCE)
#------------------------------------------------------------------------------
# pkgconfig
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Project configuration
#------------------------------------------------------------------------------
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/inc)
#------------------------------------------------------------------------------
# Sub-directories
#------------------------------------------------------------------------------
# Main build
add_subdirectory(src)
# Builds dependent on main build
if(ENABLE_TESTS)
message(STATUS "TESTS enabled")
add_subdirectory(tests)
else()
message(STATUS "TESTS disabled")
endif(ENABLE_TESTS)
if(ENABLE_DOCS)
message(STATUS "DOCS enabled")
add_subdirectory(docs)
else()
message(STATUS "DOCS disabled")
endif (ENABLE_DOCS)