-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
156 lines (109 loc) · 4.81 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Copyright (C) 2013 iFunFactory Inc. All Rights Reserved.
#
# This work is confidential and proprietary to iFunFactory Inc. and
# must not be used, disclosed, copied, or distributed without the prior
# consent of iFunFactory Inc.
# Generated by funapi_initiator.py
# You can edit this file to meet your taste.
###############################################################################
# Environment setting
###############################################################################
# Enforces a minimum version.
cmake_minimum_required(VERSION 2.8)
# Sets cmake PROJECT_NAME var.
# Enables only C++.
project(giving_tree CXX)
# Funapi component name specified in MANIFEST.json and the launcher.
set(COMPONENT_NAME ${PROJECT_NAME}_server)
# Sets Funapi-specific environment variables.
set(FUNAPI_ROOT /usr)
set(FUNAPI_BIN_DIR ${FUNAPI_ROOT}/bin)
set(FUNAPI_INCLUDE_DIR ${FUNAPI_ROOT}/include)
set(FUNAPI_DATA_DIR ${FUNAPI_ROOT}/share/funapi)
set(FUNAPI_RUNNER ${FUNAPI_BIN_DIR}/funapi_runner)
set(FUNAPI_LAUNCHER_GENERATOR ${FUNAPI_BIN_DIR}/funapi_launcher_generator.py)
###############################################################################
# Utility functions.
###############################################################################
function (CheckRequirements)
# Checks if there's a protobuf compiler
find_program(PROTOC protoc)
if (NOT PROTOC)
message(FATAL_ERROR "Protobuf compiler not found.")
endif()
endfunction ()
###############################################################################
# Requirements
###############################################################################
# Checks if everything is ready.
CheckRequirements()
###############################################################################
# Targets to build
###############################################################################
# Work-around to re-trigger cmake after VERSION changes.
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/VERSION
${CMAKE_CURRENT_BINARY_DIR}/VERSION.ignoreme)
# We will create two launchers:
# One for local testing and the other for actual deployment.
add_custom_target(
launchers ALL
DEPENDS ${PROJECT_NAME}-local ${PROJECT_NAME}-launcher)
# Creates a debugging launcher using the Funapi launcher generator.
add_custom_command(
OUTPUT ${PROJECT_NAME}-local
DEPENDS ${FUNAPI_LAUNCHER_GENERATOR}
COMMAND ${FUNAPI_LAUNCHER_GENERATOR}
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-local
${FUNAPI_ROOT}
${COMPONENT_NAME}
${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src
COMMAND chmod a+rx ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-local)
# Creates a production launcher using the Funapi launcher generator.
add_custom_command(
OUTPUT ${PROJECT_NAME}-launcher
DEPENDS ${FUNAPI_LAUNCHER_GENERATOR}
COMMAND ${FUNAPI_LAUNCHER_GENERATOR}
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-launcher
${FUNAPI_ROOT}
${COMPONENT_NAME}
/usr/lib
/usr/share/${PROJECT_NAME}/manifests
/usr/share/${PROJECT_NAME}
COMMAND chmod a+rx ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-launcher)
###############################################################################
# Installation rules
###############################################################################
# Ubuntu uses /usr instead of /usr/local.
set(CMAKE_INSTALL_PREFIX "/usr")
# The production launcher must be installed.
install(
PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-launcher
RENAME ${PROJECT_NAME}
DESTINATION bin)
# Also bundles auxiliary files.
install(
FILES VERSION LICENSE README DEBIAN
DESTINATION share/${PROJECT_NAME})
###############################################################################
# Sub-modules
###############################################################################
# Keeps adding targets/commands.
add_subdirectory(src)
###############################################################################
# Packaging rules
###############################################################################
# Makes a tgz package.
# Funapi expects a package name in the form of $name_$version_install.tar.gz.
string(REPLACE "_" "-" NORMALIZED_NAME ${PROJECT_NAME})
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/VERSION VERSION)
string(STRIP ${VERSION} VERSION)
set(CPACK_GENERATOR "TGZ")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
set(CPACK_PACKAGE_NAME ${NORMALIZED_NAME})
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_PACKAGE_FILE_NAME ${NORMALIZED_NAME}_${VERSION}_install)
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "_CPack_Packages")
include(CPack)