1- # REFERENCE PROJECT CMAKELISTS.TXT
2- #
3- # @author Barthélémy von Haller
1+ ####################################
2+ # General project definition
3+ ####################################
4+
5+ CMAKE_MINIMUM_REQUIRED (VERSION 3.5.2 FATAL_ERROR)
6+
7+ ### CMP0025 Compiler id for Apple Clang is now AppleClang.
8+ ### CMP0042 MACOSX_RPATH is enabled by default.
9+
10+ FOREACH (p
11+ CMP0025 # CMake 3.0
12+ CMP0042 # CMake 3.0
13+ )
14+ IF (POLICY ${p} )
15+ cmake_policy (SET ${p} NEW)
16+ ENDIF ()
17+ endforeach ()
418
5- cmake_minimum_required (VERSION 2.8)
6- set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR} /../cmake) # main (top) cmake dir
719set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR} /cmake) # project specific cmake dir
20+ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR} /../cmake)
21+
22+ project (Monitoring)
823
9- # CMake useful variables
10- set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY " ${CMAKE_BINARY_DIR} /bin" )
11- set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY " ${CMAKE_BINARY_DIR} /lib" )
12- set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY " ${CMAKE_BINARY_DIR} /lib" )
24+ # Load some basic macros which are needed later on
25+ include (O2Utils )
26+ include (MonitoringDependencies)
27+ include (O2) # to be removed
1328
14- # Set the name of your project here
15- project ("Monitoring" )
29+ link_o2_subproject(Common)
30+ link_o2_subproject(InfoLogger)
31+
32+ # Set the default build type to "RelWithDebInfo"
33+ if (NOT CMAKE_BUILD_TYPE )
34+ set (CMAKE_BUILD_TYPE "RelWithDebInfo"
35+ CACHE
36+ STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Coverage."
37+ FORCE)
38+ endif (NOT CMAKE_BUILD_TYPE )
1639
1740# Set the version number of your project here (format is MAJOR.MINOR.PATCHLEVEL - e.g. 1.0.0)
1841set (VERSION_MAJOR "0" )
1942set (VERSION_MINOR "0" )
2043set (VERSION_PATCH "0" )
2144set (VERSION ${VERSION_MAJOR} .${VERSION_MINOR} .${VERSION_PATCH} )
2245
23- # Macros and variables for all O2 subprojects
24- include (O2)
25-
26- ## Git (and its revision)
27- find_package (Git QUIET ) # if we don't find git or FindGit.cmake is not on the system we ignore it.
28- ## GetGitRevisionDescription module to retreive branch and revision information from Git
29- ## Starting with Git 1.9 the module will be part of official cMake distribution, until then it has to be
30- ## part of the application
31- ## The Git module will trigger a reconfiguration for each pull that will bring a new revision on the local repository
32- set (VCS_REVISION "-1" )
33- if (GIT_FOUND)
34- include (GetGitRevisionDescription)
35- get_git_head_revision(GIT_REFSPEC GIT_SHA1)
36- message (STATUS "GIT branch ${GIT_REFSPEC} " )
37- message (STATUS "GIT revision ${GIT_SHA1} " )
38- set (VCS_REVISION ${GIT_SHA1} )
46+ # C++14
47+ IF (CMAKE_VERSION VERSION_LESS 3.1)
48+ include (CheckCXXCompilerFlag)
49+ CHECK_CXX_COMPILER_FLAG(-std=c++14 COMPILER_SUPPORTS_CXX14)
50+ if (COMPILER_SUPPORTS_CXX14)
51+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14" )
52+ else ()
53+ message (ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler." )
54+ endif ()
55+ ELSE ()
56+ set (CMAKE_CXX_STANDARD 14) # proper way in CMake >= 3.1
57+ ENDIF ()
58+
59+ # Add compiler flags for warnings and (more importantly) fPIC and debug symbols
60+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -fPIC" )
61+
62+
63+ # TODO RECONSIDER THE THINGS BELOW AFTER EXTRACTION TO ITS OWN REPO
64+ # Make sure we tell the topdir CMakeLists that we exist (if build from topdir)
65+ get_directory_property (hasParent PARENT_DIRECTORY )
66+ if (hasParent)
67+ set (PROJECT_${PROJECT_NAME} true PARENT_SCOPE)
3968endif ()
69+ include (PackageConfigurator)
4070
41- # This line finds the boost lib and headers.
42- set (Boost_NO_BOOST_CMAKE ON ) # Don't do a find_package in config mode before searching for a regular boost install.
43- find_package (Boost COMPONENTS unit_test_framework program_options system REQUIRED)
71+ add_subdirectory (doc )
4472
45- # Dependency on another subproject (InfoLogger)
46- link_o2_subproject(Common)
47- link_o2_subproject(InfoLogger)
48- find_package (Configuration )
4973
50- configure_file (examples/config-default.ini examples/config-default.ini COPYONLY )
5174
52- # This sets the include directory for the reference project. This is
53- # the -I flag in gcc. All the includes should be in this variable To
54- # add new directories to the include path, just add them in this list
55- # (after a space), or add an include_directories statement in a
56- # subdirectory's CMakeLists.
75+ ####################################
76+ # Module, library and executable definition
77+ ####################################
78+
79+ set (MODULE_NAME "Monitoring" )
80+
81+ O2_SETUP(NAME ${MODULE_NAME} )
82+
83+ set (SRCS
84+ src/Collector.cxx
85+ src/Metric.cxx
86+ src/Backends/InfoLoggerBackend.cxx
87+ src/Backends/Flume.cxx
88+ src/DerivedMetrics.cxx
89+ src/ProcessMonitor.cxx
90+ src/ProcessDetails.cxx
91+ src/MonitoringFactory.cxx
92+ src/Transports/UDP.cxx
93+ src/Transports/HTTP.cxx
94+ src/Exceptions/MonitoringException.cxx
95+ src/Exceptions/MonitoringInternalException.cxx
96+ )
97+
98+ # Detect operating system
99+ if (UNIX AND NOT APPLE )
100+ message (STATUS "Detected Linux OS: Process monitor enabled" )
101+ add_definitions (-D_OS_LINUX)
102+ endif ()
103+
104+ if (WIN32 )
105+ message (STATUS "Detected Windows OS: Process monitor disabled" )
106+ add_definitions (-D_OS_WINDOWS)
107+ endif ()
108+
109+ if (APPLE )
110+ message (STATUS "Detected Mac OS: Process monitor disabled" )
111+ add_definitions (-D_OS_MAC)
112+ endif ()
113+
114+ # Backends
115+ message (STATUS "Backends" )
116+ message (STATUS " Compiling InfoLoggerBackend backend" )
117+ message (STATUS " Compiling Flume UDP/JSON backend" )
118+
119+ if (APMON_FOUND)
120+ message (STATUS " Compiling ApMon backend" )
121+ list (APPEND SRCS src/Backends/ApMonBackend.cxx)
122+ add_definitions (-D_WITH_APPMON)
123+ else ()
124+ message (WARNING " ApMon not found, skipping ApMon backend" )
125+ endif ()
126+
127+ if (CURL_FOUND)
128+ message (STATUS " Compiling InfluxDB HTTP and UDP backend" )
129+ add_definitions (-D_WITH_INFLUX)
130+ list (APPEND SRCS src/Backends/InfluxDB.cxx)
131+ else ()
132+ message (WARNING " libcurl not found, skipping InfluxDB backend" )
133+ endif ()
134+
135+ # Produce the final Version.h using template Version.h.in and substituting variables.
136+ # We don't want to polute our source tree with it, thus putting it in binary tree.
137+ configure_file ("include/${MODULE_NAME} /Version.h.in"
138+ "${CMAKE_CURRENT_BINARY_DIR} /include/${MODULE_NAME} /Version.h"
139+ @ONLY
140+ )
141+
57142include_directories (
58- ${PROJECT_SOURCE_DIR} /include
59- ${PROJECT_BINARY_DIR} /include # add the binary tree to the search path so that we will find Version.h
60- ${Boost_INCLUDE_DIRS}
61- ${Configuration_INCLUDE_DIRS}
143+ ${CMAKE_CURRENT_BINARY_DIR} /include
62144)
63145
64- # Mac needed variables (adapt according to your needs)
65- set (CMAKE_MACOSX_RPATH ON )
66- #set(CMAKE_SKIP_BUILD_RPATH FALSE)
67- #set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
68- #set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
69- #set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
146+ configure_file (examples/config-default.ini examples/config-default.ini COPYONLY )
147+
148+ set (LIBRARY_NAME DataCollector)
149+ set (BUCKET_NAME o2_monitoring_bucket)
150+ O2_GENERATE_LIBRARY()
151+
152+ set (TEST_SRCS
153+ test /testCollector.cxx
154+ test /testDerived.cxx
155+ test /testFlume.cxx
156+ test /testMetric.cxx
157+ test /testProcessDetails.cxx
158+ test /testProcessMonitor.cxx
159+ )
160+
161+ O2_GENERATE_TESTS(
162+ MODULE_LIBRARY_NAME ${LIBRARY_NAME}
163+ BUCKET_NAME ${BUCKET_NAME}
164+ TEST_SRCS ${TEST_SRCS}
165+ )
70166
71- enable_testing () # needed on top-level CMakeLists.txt
72- add_subdirectory (include )
73- add_subdirectory (src)
74- add_subdirectory (doc )
75- add_subdirectory (test )
76- add_subdirectory (examples)
167+ set (EXAMPLES
168+ examples/1-Basic.cxx
169+ examples/2-TaggedMetrics.cxx
170+ examples/3-UserDefinedTimestamp
171+ examples/4-RateDerivedMetric.cxx
172+ examples/5-Benchmark.cxx
173+ examples/6-DedicatedInstance.cxx
174+ )
77175
78- # PACKAGING
79- # _____________________________________________________________________________
176+ foreach (example ${EXAMPLES} )
80177
81- include (CPackConfig)
178+ get_filename_component (example_name ${example} NAME )
179+ string (REGEX REPLACE ".cxx" "" example_name ${example_name} )
82180
83- #
84- # CMAKE PACKAGING (for other CMake projects to use this one easily)
85- # _____________________________________________________________________________
181+ O2_GENERATE_EXECUTABLE(
182+ EXE_NAME ${example_name}
183+ SOURCES ${example}
184+ MODULE_LIBRARY_NAME ${LIBRARY_NAME}
185+ BUCKET_NAME ${BUCKET_NAME}
186+ )
86187
87- include (PackageConfigurator )
188+ endforeach ( )
0 commit comments