faf843bc3570c714e3921517d1ca626098f6e9a4
[ric-app/ts.git] / CMakeLists.txt
1 #==================================================================================
2 #       Copyright (c) 2020 AT&T Intellectual Property.
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License"),
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15 #==================================================================================
16 #
17
18 # This CMake definition supports several -D command line options:
19 #
20 #       -DDEBUG=n                       Enable debugging level n
21 #       -DGPROF=1                       Enable profiling compile time flags
22 #
23 #       Building the binaries in this project should be as easy as running the
24 #       following command in this directory:
25 #               rm -fr .build
26 #               make .build
27 #               cd .build
28 #               cmake .. [-DGPROF=1] [-DDEBUG=1]
29 #               make test [install] ARGS=-V
30 #
31
32 project( ricxfcpp )
33 cmake_minimum_required( VERSION 3.14 )
34
35 set( major_version "1" )                # until CI supports auto tagging; must hard set
36 set( minor_version "2" )
37 set( patch_level "3" )
38
39 set( install_root "${CMAKE_INSTALL_PREFIX}" )
40 set( install_inc "/usr/local/include" )
41
42 # Must use GNUInstallDirs to install libraries into correct
43 # locations on all platforms.
44 include( GNUInstallDirs )
45
46 # externals may install using LIBDIR as established by the gnu include; it varies from system
47 # to system, and we don't trust that it is always set, so we default to lib if it is missing.
48 #
49 if( NOT CMAKE_INSTALL_LIBDIR )
50         set( CMAKE_INSTALL_LIBDIR "lib" )
51 endif()
52
53 set( install_lib "${CMAKE_INSTALL_LIBDIR}" )
54
55 if( DEBUG )                                     # if set, we'll set debugging on in the compile
56         set( debugging ${DEBUG} )
57         message( "+++ debugging is being set to ${DEBUG}" )
58 else()
59         set( debugging 0 )
60         message( "+++ debugging is set to off" )
61 endif()
62 unset( DEBUG CACHE )                                    # we don't want this to persist
63
64
65 # ---------------- extract some things from git ------------------------------
66
67 # commit id for the version string
68 execute_process(
69         COMMAND bash -c "git rev-parse --short HEAD|awk '{printf\"%s\", $0}'"
70         OUTPUT_VARIABLE git_id
71 )
72
73 # define constants used in the version string, debugging, etc.
74 add_definitions(
75         -DGIT_ID=${git_id}
76         -DMAJOR_VER=${major_version}
77         -DMINOR_VER=${minor_version}
78         -DPATCH_VER=${patch_level}
79         -DDEBUG=${debugging}
80 )
81
82
83 # bleeding cmake names are short novels; and when lines cannot be split they're a pain
84 set ( srcd "${CMAKE_CURRENT_SOURCE_DIR}" )
85
86
87 # Compiler flags
88 #
89 set( CMAKE_POSITION_INDEPENDENT_CODE ON )
90 if( GPROF )                                     # if set, we'll set profiling flag on compiles
91         message( "+++ profiling is on" )
92         set( CMAKE_C_FLAGS "-pg " )
93         set( CMAKE_CXX_FLAGS "-pg " )
94 else()
95         set( CMAKE_C_FLAGS "-g " )
96         set( CMAKE_CXX_FLAGS "-g " )
97         message( "+++ profiling is off" )
98 endif()
99 unset( GPROF CACHE )                                    # ensure this does not persist
100
101 # protobuf and grpc stufs
102 add_subdirectory( ext/protobuf )
103
104 # general stufs
105 add_subdirectory( src/utils )
106
107 # each binary is built from a subset
108 add_subdirectory( src/ts_xapp )
109
110
111 # -------- unit testing -------------------------------------------------------
112 enable_testing()
113 add_test(
114         NAME drive_unit_tests
115         COMMAND bash ../test/unit_test.sh -q
116         WORKING_DIRECTORY ../test
117 )