summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 14e4471d0f9c24b253294939467243721c02211e (plain) (blame)
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
131
cmake_minimum_required(VERSION 3.4)

include(FindPkgConfig)
include(CheckIncludeFiles)

project(Horizon
        LANGUAGES C CXX
        VERSION 0.9.0)


add_definitions(-DVERSTR="${PROJECT_VERSION}")


if(MSVC)
  add_compile_options(/W4 /WX)
else()
  add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-function
                      -Werror)
endif()

if(POLICY CMP0100)
  cmake_policy(SET CMP0100 NEW)
endif()


option(BUILD_TOOLS "Enable building of tools (Validator, Simulator, etc)" ON)
option(BUILD_UI "Enable user interface" ON)


## Code Coverage stuff ##
option(COVERAGE "Build for code coverage tests (slow)" OFF)
IF(COVERAGE)
    SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} --coverage")
    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
    SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage")
ENDIF(COVERAGE)


## Valgrind stuff ##
find_program(VALGRIND_EXECUTABLE NAMES valgrind)
IF(VALGRIND_EXECUTABLE)
option(VALGRIND "Run Valgrind during test phase" OFF)
ENDIF(VALGRIND_EXECUTABLE)


## Firmware stuff ##
option(UNSUPPORTED_NONFREE_FIRMWARE "Support loading and installation of non-libre firmware (DANGEROUS)" OFF)
mark_as_advanced(FORCE UNSUPPORTED_NONFREE_FIRMWARE)

IF(UNSUPPORTED_NONFREE_FIRMWARE)
    add_definitions(-DNON_LIBRE_FIRMWARE)
ENDIF(UNSUPPORTED_NONFREE_FIRMWARE)


## Installation Environment support stuff ##
option(INSTALL "Build Installation Environment support (Linux only)" ON)

check_include_files(linux/wireless.h HAVE_LINUX_WIRELESS_H)
IF(NOT HAVE_LINUX_WIRELESS_H)
SET(INSTALL OFF)
ENDIF(NOT HAVE_LINUX_WIRELESS_H)


include_directories(.)


## Test stuff ##
find_program(RSPEC_EXECUTABLE NAMES rspec)
enable_testing()


IF(INSTALL)
    add_definitions(-DHAS_INSTALL_ENV)
    pkg_check_modules(BLKID REQUIRED blkid)
    pkg_check_modules(LIBUDEV REQUIRED libudev)
    pkg_check_modules(PARTED REQUIRED libparted)
    find_library(SKARNET NAMES skarnet)
    find_library(BCNM NAMES wpactrl PATH_SUFFIXES bcnm)
    if(BCNM STREQUAL "BCNM-NOTFOUND")
        message(FATAL_ERROR "BCNM is required for the Installation Environment.")
    endif()
    set(BUILD_SHARED_LIBS ON)
    option(BUILD_IMAGE "Enable building the image creation tools" ON)

    add_subdirectory(diskman)
    add_subdirectory(executor)
ELSE(INSTALL)
    set(BUILD_SHARED_LIBS OFF)
ENDIF(INSTALL)


if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
    SET(FS_LIBRARY stdc++fs)
    add_definitions(-DFS_IS_STDCXX)
ELSE()
    find_package(Boost REQUIRED COMPONENTS filesystem)
    SET(FS_LIBRARY ${Boost_FILESYSTEM_LIBRARY})
    add_definitions(-DFS_IS_BOOST)
ENDIF()


add_subdirectory(hscript)
add_subdirectory(owner)
IF(BUILD_TOOLS)
    add_subdirectory(tools)
ENDIF(BUILD_TOOLS)
IF(BUILD_UI)
    add_subdirectory(ui)
ENDIF(BUILD_UI)
IF(INSTALL)
    add_subdirectory(fetch)
    IF(BUILD_IMAGE)
        add_subdirectory(image)
    ENDIF(BUILD_IMAGE)
ENDIF(INSTALL)


IF(COVERAGE)
    find_program(LCOV_EXECUTABLE NAMES lcov)

    IF(LCOV_EXECUTABLE)
        add_custom_command(OUTPUT horizon.coverage
            COMMAND lcov ARGS --exclude '/usr/include/boost/*' --exclude '/usr/include/c++/*' --exclude '*/3rdparty/*' --capture --directory ${CMAKE_BINARY_DIR} --output-file horizon.coverage)
        add_custom_target(lcov_report DEPENDS horizon.coverage)
        add_custom_command(OUTPUT cov_html
            COMMAND genhtml ARGS horizon.coverage --output-directory cov_html)
        add_custom_target(lcov_html DEPENDS cov_html)
    ENDIF(LCOV_EXECUTABLE)
ENDIF(COVERAGE)

INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/devel/image.yang DESTINATION share/doc/horizon)