CMakeLists.txt 8.94 KB
Newer Older
1
cmake_minimum_required (VERSION 3.0)
Jeroen Simonetti's avatar
Jeroen Simonetti committed
2 3 4 5 6
project (agocontrol)

# The version number.
set (AGOCONTROL_VERSION 0.1)

7 8
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

9 10
find_package(PkgConfig REQUIRED)

11 12
include (CheckIncludeFiles)

13 14
include(cmake/AgoFileHelpers.cmake)

15 16 17
find_package(PythonNaive)


Johan Ström's avatar
Johan Ström committed
18 19
set (INSTALL_PREFIX /usr)

Johan Ström's avatar
Johan Ström committed
20
# FreeBSD have some differences in building, mainly
21
# that non-base libs/includes are located in /usr/local.
Johan Ström's avatar
Johan Ström committed
22 23 24 25 26 27 28 29 30 31 32
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
    set (OS_FREEBSD YES)
    set (INSTALL_PREFIX /usr/local)
    include_directories("${INSTALL_PREFIX}/include")
    link_directories(${INSTALL_PREFIX}/lib)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
    set (OS_LINUX YES)
    set (INSTALL_PREFIX /usr)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
    # See README.OSX. Does not actually build.
    set (OS_DARWIN YES)
Johan Ström's avatar
Johan Ström committed
33
    include_directories("./local-include")
Johan Ström's avatar
Johan Ström committed
34 35 36
else()
    message(STATUS "Unknown OS ${CMAKE_SYSTEM_NAME}, expect issues!")
endif()
Johan Ström's avatar
Johan Ström committed
37

Jeroen Simonetti's avatar
Jeroen Simonetti committed
38
# some configurable values
Johan Ström's avatar
Johan Ström committed
39
if (OS_FREEBSD)
Johan Ström's avatar
Johan Ström committed
40 41
    set (BASEDIR ${INSTALL_PREFIX}/agocontrol CACHE STRING "Directory to store agocontrol installation")
    set (ETCDIR ${INSTALL_PREFIX}/etc CACHE STRING "Directory for system-wide settings")
Johan Ström's avatar
Johan Ström committed
42 43 44
    set (CONFDIR ${ETCDIR}/agocontrol CACHE STRING "Directory for agocontrol settings")
    # XXX: Not sure what "variable" data is, but only .sql files are installed currently,
    # and those should be stored in share.
Johan Ström's avatar
Johan Ström committed
45 46
    set (DATADIR ${INSTALL_PREFIX}/share/agocontrol CACHE STRING "Directory for variable data")
    set (LOCALSTATEDIR ${INSTALL_PREFIX}/var/agocontrol CACHE STRING "Directory for state info")
Johan Ström's avatar
Johan Ström committed
47
else()
Johan Ström's avatar
Johan Ström committed
48 49 50 51 52
    set (BASEDIR /opt/agocontrol CACHE STRING "Directory to store agocontrol installation")
    set (ETCDIR /etc CACHE STRING "Directory for system-wide settings")
    set (CONFDIR ${ETCDIR}/opt/agocontrol CACHE STRING "Directory for agocontrol settings")
    set (DATADIR /var/opt/agocontrol CACHE STRING "Directory for variable data")
    set (LOCALSTATEDIR /var/opt/agocontrol CACHE STRING "Directory for state info")
Johan Ström's avatar
Johan Ström committed
53 54 55
    if(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin")
        set (CMAKE_EXE_LINKER_FLAGS "-Wl,-z,now")
    endif()
Johan Ström's avatar
Johan Ström committed
56
endif()
Johan Ström's avatar
Johan Ström committed
57 58 59 60 61 62 63

# Common structure
set (BINDIR ${BASEDIR}/bin CACHE STRING "Directory to store Binaries")
set (LIBDIR ${INSTALL_PREFIX}/lib CACHE STRING "Directory for libraries")
set (INCDIR ${INSTALL_PREFIX}/include/agocontrol CACHE STRING "Directory for include files")
set (HTMLDIR ${BASEDIR}/html CACHE STRING "Directory for rpc HTML files")
set (AUGEASLENSEDIR ${INSTALL_PREFIX}/share/augeas/lenses CACHE STRING "Directory for augeas lenses")
Jeroen Simonetti's avatar
Jeroen Simonetti committed
64

Johan Ström's avatar
Johan Ström committed
65 66
set (PYTHON2DIST ${INSTALL_PREFIX}/${Python2_SITELIB} CACHE STRING "Directory for Python 2.7 packages")
set (PYTHON3DIST ${INSTALL_PREFIX}/${Python3_SITELIB} CACHE STRING "Directory for Python 3 packages")
Jeroen Simonetti's avatar
Jeroen Simonetti committed
67

Johan Ström's avatar
Johan Ström committed
68 69
# Enable C++11
if (CMAKE_VERSION VERSION_LESS "3.1")
Johan Ström's avatar
Johan Ström committed
70
    # Used on Debian Jessie builders
Johan Ström's avatar
Johan Ström committed
71
    if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Johan Ström's avatar
Johan Ström committed
72
        # Note: must ont set for CFLAGS!
Johan Ström's avatar
Johan Ström committed
73 74 75
        set (CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}")
    endif ()
else ()
Johan Ström's avatar
Johan Ström committed
76
    set (CMAKE_CXX_STANDARD 11)
Johan Ström's avatar
Johan Ström committed
77 78
endif ()

79
set_property( DIRECTORY
Johan Ström's avatar
Johan Ström committed
80 81 82 83 84 85 86 87 88 89 90 91
    APPEND PROPERTY
    COMPILE_OPTIONS
    -Wall
    -DBOOST_LOG_DYN_LINK
    -DBOOST_FILESYSTEM_VERSION=3
    -DBOOST_FILESYSTEM_NO_DEPRECATED

    # Workaround for bug in Boost on Clang which tries to add pragma warning group keyward-warning
    # which does not exists in clang:
    # http://lists.boost.org/Archives/boost/2016/07/230350.php
    -Wno-error=unknown-pragmas
    )
Johan Ström's avatar
Johan Ström committed
92

Jeroen Simonetti's avatar
Jeroen Simonetti committed
93
# add the binary tree to the search path for include files
Jeroen Simonetti's avatar
Jeroen Simonetti committed
94
# so that we will find version.h and other configured files
Jeroen Simonetti's avatar
Jeroen Simonetti committed
95
include_directories("${PROJECT_BINARY_DIR}")
Jeroen Simonetti's avatar
Jeroen Simonetti committed
96 97
include_directories("${PROJECT_BINARY_DIR}/shared")
include_directories("${PROJECT_SOURCE_DIR}/shared")
Jeroen Simonetti's avatar
Jeroen Simonetti committed
98

99 100 101
# We have an amalgamated version of jsoncpp, ensure we can include <json/json.h>
include_directories("${PROJECT_SOURCE_DIR}/shared/jsoncpp")

102 103 104 105 106 107 108 109 110
macro(log_pkg_found PKG_NAME PKG_FOUND PKG_VERSION NOTFOUND_LEVEL NOTFOUND_EXTRA)
    if("${PKG_FOUND}" AND "${PKG_VERSION}" STREQUAL "")
        message(STATUS "${PKG_NAME} found")
    elseif(${PKG_FOUND})
        message(STATUS "${PKG_NAME} version: ${PKG_VERSION}")
    else()
        message(${NOTFOUND_LEVEL} "${PKG_NAME} not found${NOTFOUND_EXTRA}")
    endif()
endmacro()
Jeroen Simonetti's avatar
Jeroen Simonetti committed
111

112

113 114 115
find_package(Threads REQUIRED)
find_package(Boost COMPONENTS system filesystem thread program_options date_time regex chrono REQUIRED)
find_package(Boost COMPONENTS log)
Johan Ström's avatar
Johan Ström committed
116
if(Boost_LOG_FOUND)
117
    ADD_DEFINITIONS(-DHAVE_BOOST_LOG)
Johan Ström's avatar
Johan Ström committed
118
else()
119
    find_package(Boost COMPONENTS REQUIRED date_time)
Johan Ström's avatar
Johan Ström committed
120
endif()
121

122
pkg_search_module(YAML_CPP REQUIRED yaml-cpp yaml-cpp03)
123
log_pkg_found(yamlcpp "${YAML_CPP_FOUND}" "${YAML_CPP_VERSION}" FATAL_ERROR "")
124

125 126
pkg_search_module(AUGEAS REQUIRED augeas)
log_pkg_found(augeas "${AUGEAS_FOUND}" "${AUGEAS_VERSION}" FATAL_ERROR "")
127

128
pkg_search_module(SQLITE REQUIRED sqlite3)
129
log_pkg_found(sqlite3 "${SQLITE_FOUND}" "${SQLITE_VERSION}" FATAL_ERROR "")
130 131 132 133 134

# Mongoose may use openssl
pkg_search_module(OPENSSL openssl)
log_pkg_found(openssl "${OPENSSL_FOUND}" "${OPENSSL_VERSION}" STATUS ", building without https support")

135 136 137 138 139 140 141 142 143 144
# Linux/debian has lua5.x, FreeBSD has lua-5.x, fedora has just lua
pkg_search_module(LUA lua5.3 lua-5.3 lua5.2 lua-5.2 lua5.1 lua-5.1 lua)
log_pkg_found(lua "${LUA_FOUND}" "${LUA_VERSION}" WARNING ", parts of core will not be built")

find_package(CppDb)
log_pkg_found(cppdb "${CPPDB_FOUND}" "" WARNING ", parts of core will not be built")

pkg_search_module(LIBRRD librrd)
log_pkg_found(librrd "${LIBRRD_FOUND}" "${LIBRRD_VERSION}" WARNING ", parts of core will not be built")

Johan Ström's avatar
Johan Ström committed
145
if(OS_LINUX)
Johan Ström's avatar
Johan Ström committed
146 147
    # used by agosystem
    pkg_search_module(LIBPROCPS REQUIRED libprocps)
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
    log_pkg_found(libprocps "${LIBPROCPS_FOUND}" "${LIBPROCPS_VERSION}" WARNING "")

    find_package(LinuxI2C)
endif()

pkg_search_module(LIBCURL libcurl)
log_pkg_found(libcurl "${LIBCURL_FOUND}" "${LIBCURL_VERSION}" STATUS "")

find_package(OpenCV)
log_pkg_found(OpenCV "${OpenCV_FOUND}" "${OpenCV_VERSION}" STATUS "")

find_package(OpenZWave)
log_pkg_found(OpenZWave "${OpenZWave_FOUND}" "${OpenZWave_VERSION}" STATUS "")

find_package(EibClient)
log_pkg_found(EibClient "${EibClient_FOUND}" "${EibClient_VERSION}" STATUS "")

pkg_check_modules(OpenLighting libola)
log_pkg_found(OpenLighting "${OpenLighting_FOUND}" "${OpenLighting_VERSION}" STATUS "")
167

168 169
include_directories(${Boost_INCLUDE_DIRS})

170 171 172 173 174
find_program(INTLTOOL_MERGE intltool-merge)
if(NOT INTLTOOL_MERGE)
    message(FATAL_ERROR "Program 'intltool-merge' is required to build web UI")
endif()

Johan Ström's avatar
Johan Ström committed
175 176 177
# Fix for Boost < 1.56 built without C++, when we build with C++11
# https://stackoverflow.com/questions/35007134/c-boost-undefined-reference-to-boostfilesystemdetailcopy-file
# https://chaste.cs.ox.ac.uk/trac/wiki/ChasteGuides/ModernCpp#Boostscopedenumsforboost1.56
Johan Ström's avatar
Johan Ström committed
178
if(Boost_VERSION VERSION_LESS 105600)
Johan Ström's avatar
Johan Ström committed
179 180 181 182 183 184
    message(STATUS "Boost version < 1.56, building with BOOST_NO_CXX11_SCOPED_ENUMS")
    set_property( DIRECTORY
        APPEND PROPERTY
        COMPILE_OPTIONS
        -DBOOST_NO_CXX11_SCOPED_ENUMS
    )
Johan Ström's avatar
Johan Ström committed
185
endif()
Johan Ström's avatar
Johan Ström committed
186

187
find_package(CppUnit)
188
log_pkg_found(CppUnit "${CPPUNIT_FOUND}" "${CPPUNIT_VERSION}" STATUS ", not building unit-tests")
189

190 191
check_include_files("xlocale.h" HAVE_XLOCALE_H)

Jeroen Simonetti's avatar
Jeroen Simonetti committed
192 193 194 195
set (ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${LIBDIR}")
set (LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${LIBDIR}")
set (RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${BINDIR}")

196 197 198
get_filename_component(CMAKE_CURRENT_SOURCE_DIR_REAL "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
get_filename_component(CMAKE_CURRENT_BINARY_DIR_REAL "${CMAKE_CURRENT_BINARY_DIR}" REALPATH)
if ("${CMAKE_CURRENT_SOURCE_DIR_REAL}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR_REAL}")
Johan Ström's avatar
Johan Ström committed
199 200
    set (IN_SOURCE_BUILD TRUE)
    message(WARNING "In-Source build is not recommended. Instead, create a separate directory and run cmake /path/to/source")
201
else()
Johan Ström's avatar
Johan Ström committed
202
    set (IN_SOURCE_BUILD FALSE)
203
endif()
204

205 206 207
# Shared for all
install(DIRECTORY DESTINATION ${BINDIR})

Jeroen Simonetti's avatar
Jeroen Simonetti committed
208
# add sub directories
Johan Ström's avatar
Johan Ström committed
209
option(BUILD_SHARED "Build the agoclient shared library" ON)
210
if (BUILD_SHARED)
Johan Ström's avatar
Johan Ström committed
211
  add_subdirectory (shared)
212 213
endif()

Johan Ström's avatar
Johan Ström committed
214
option(BUILD_TESTS "Build the unittests" ON)
215
if (BUILD_TESTS AND CPPUNIT_FOUND)
Johan Ström's avatar
Johan Ström committed
216 217 218
    # These are only for Shared right now, so add them right after.
    enable_testing()
    add_subdirectory (unittest)
219 220
endif()

Johan Ström's avatar
Johan Ström committed
221
option(BUILD_CORE "Build the CORE" ON)
222
if (BUILD_CORE)
Johan Ström's avatar
Johan Ström committed
223
  add_subdirectory (core)
224 225 226
  install (FILES data/inventory.sql data/datalogger.sql DESTINATION ${DATADIR})
endif()

Johan Ström's avatar
Johan Ström committed
227
option(BUILD_GATEWAYS "Build the gateways" ON)
228
if (BUILD_GATEWAYS)
Johan Ström's avatar
Johan Ström committed
229
  add_subdirectory (gateways)
230 231
endif()

Johan Ström's avatar
Johan Ström committed
232
option(BUILD_DEVICES "Build the devices" ON)
233
if (BUILD_DEVICES)
Johan Ström's avatar
Johan Ström committed
234
  add_subdirectory (devices)
235 236
endif()

Johan Ström's avatar
Johan Ström committed
237
option(BUILD_CONF "Build the configs" ON)
238
if (BUILD_CONF)
Johan Ström's avatar
Johan Ström committed
239
  add_subdirectory (conf)
240 241
endif()

Johan Ström's avatar
Johan Ström committed
242
option(BUILD_SCRIPTS "Build the scripts" ON)
243 244
if (BUILD_SCRIPTS)
  add_subdirectory (scripts)
Harald Klein's avatar
Harald Klein committed
245
endif()
Johan Ström's avatar
Johan Ström committed
246 247 248 249 250


# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
Johan Ström's avatar
Johan Ström committed
251 252 253
        "${PROJECT_SOURCE_DIR}/build_config.h.in"
        "${PROJECT_BINARY_DIR}/build_config.h"
        @ONLY
Johan Ström's avatar
Johan Ström committed
254
)