2015-09-13 20:25:26 +00:00
###
2019-03-29 19:43:16 +00:00
### Copyright 2015-2019 Oliver Giles
2015-09-13 20:25:26 +00:00
###
### This file is part of Laminar
###
### Laminar is free software: you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation, either version 3 of the License, or
### (at your option) any later version.
###
### Laminar is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with Laminar. If not, see <http://www.gnu.org/licenses/>
###
project ( laminar )
cmake_minimum_required ( VERSION 2.8 )
2017-11-18 09:24:43 +00:00
cmake_policy ( SET CMP0058 NEW )
2015-09-13 20:25:26 +00:00
set ( CMAKE_INCLUDE_CURRENT_DIR ON )
2019-06-30 13:24:20 +00:00
if ( NOT CMAKE_INSTALL_PREFIX )
set ( CMAKE_INSTALL_PREFIX / )
endif ( NOT CMAKE_INSTALL_PREFIX )
2019-06-30 13:40:25 +00:00
message ( "-- Install prefix set to '${CMAKE_INSTALL_PREFIX}'" )
2019-06-30 13:24:20 +00:00
2019-06-30 13:40:25 +00:00
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE Release )
endif ( NOT CMAKE_BUILD_TYPE )
message ( "-- Install type set to '${CMAKE_BUILD_TYPE}'" )
2019-06-30 13:24:20 +00:00
2018-07-20 11:15:59 +00:00
add_definitions ( "-std=c++14 -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare" )
2015-09-13 20:25:26 +00:00
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -DDEBUG" )
# This macro takes a list of files, gzips them and converts the output into
# object files so they can be linked directly into the application.
# ld generates symbols based on the string argument given to its executable,
# so it is significant from which directory it is called. BASEDIR will be
# removed from the beginning of paths to the remaining arguments
macro ( generate_compressed_bins BASEDIR )
foreach ( FILE ${ ARGN } )
set ( COMPRESSED_FILE "${FILE}.z" )
set ( OUTPUT_FILE "${FILE}.o" )
2015-11-19 20:43:57 +00:00
get_filename_component ( DIR ${ FILE } PATH )
2015-09-13 20:25:26 +00:00
if ( DIR )
file ( MAKE_DIRECTORY ${ CMAKE_CURRENT_BINARY_DIR } / ${ DIR } )
endif ( )
add_custom_command ( OUTPUT ${ COMPRESSED_FILE }
C O M M A N D g z i p < $ { B A S E D I R } / $ { F I L E } > $ { C O M P R E S S E D _ F I L E }
D E P E N D S $ { B A S E D I R } / $ { F I L E }
)
add_custom_command ( OUTPUT ${ OUTPUT_FILE }
2018-06-23 11:36:31 +00:00
C O M M A N D $ { C M A K E _ L I N K E R } - r - b b i n a r y - o $ { O U T P U T _ F I L E } $ { C O M P R E S S E D _ F I L E }
C O M M A N D $ { C M A K E _ O B J C O P Y }
- - r e n a m e - s e c t i o n . d a t a = . r o d a t a . a l l o c , l o a d , r e a d o n l y , d a t a , c o n t e n t s
- - a d d - s e c t i o n . n o t e . G N U - s t a c k = / d e v / n u l l
- - s e t - s e c t i o n - f l a g s . n o t e . G N U - s t a c k = c o n t e n t s , r e a d o n l y $ { O U T P U T _ F I L E }
2015-09-13 20:25:26 +00:00
D E P E N D S $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { C O M P R E S S E D _ F I L E }
)
list ( APPEND COMPRESSED_BINS ${ OUTPUT_FILE } )
endforeach ( )
endmacro ( )
# Generates Cap'n Proto interface from definition file
add_custom_command ( OUTPUT laminar.capnp.c++ laminar.capnp.h
C O M M A N D c a p n p c o m p i l e - o c + + : $ { C M A K E _ B I N A R Y _ D I R }
- - s r c - p r e f i x = $ { C M A K E _ S O U R C E _ D I R } / s r c $ { C M A K E _ S O U R C E _ D I R } / s r c / l a m i n a r . c a p n p
D E P E N D S s r c / l a m i n a r . c a p n p )
# Zip and compile statically served resources
generate_compressed_bins ( ${ CMAKE_SOURCE_DIR } /src/resources index.html js/app.js
2017-12-28 14:57:57 +00:00
f a v i c o n . i c o f a v i c o n - 1 5 2 . p n g i c o n . p n g )
2017-07-13 18:57:28 +00:00
2019-03-29 19:43:16 +00:00
# The code that allows dynamic modifying of index.html requires knowing its original size
add_custom_command ( OUTPUT index_html_size.h
C O M M A N D s h - c ' ( e c h o - n " \ \ #define INDEX_HTML_UNCOMPRESSED_SIZE " && wc -c < "${CMAKE_SOURCE_DIR}/src/resources/index.html" ) > index_html_size.h'
D E P E N D S s r c / r e s o u r c e s / i n d e x . h t m l )
2015-09-13 20:25:26 +00:00
# Download 3rd-party frontend JS libs...
2017-07-13 18:57:28 +00:00
file ( DOWNLOAD https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js
j s / v u e . m i n . j s E X P E C T E D _ M D 5 a e 2 f c a 1 c f a 0 e 3 1 3 7 7 8 1 9 b 1 b 0 f f e f 7 0 4 c )
file ( DOWNLOAD https://cdnjs.cloudflare.com/ajax/libs/vue-router/2.7.0/vue-router.min.js
j s / v u e - r o u t e r . m i n . j s E X P E C T E D _ M D 5 5 d 3 e 3 5 7 1 0 d b e 0 2 d e 7 8 c 3 9 e 3 e 4 3 9 b 8 d 4 e )
2015-09-13 20:25:26 +00:00
file ( DOWNLOAD https://raw.githubusercontent.com/drudru/ansi_up/v1.3.0/ansi_up.js
j s / a n s i _ u p . j s E X P E C T E D _ M D 5 1 5 8 5 6 6 d c 1 f f 8 f 2 8 0 4 d e 9 7 2 f 7 e 8 4 1 e 2 f 6 )
2018-07-06 14:47:48 +00:00
file ( DOWNLOAD https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js
j s / C h a r t . m i n . j s E X P E C T E D _ M D 5 f 6 c 8 e f a 6 5 7 1 1 e 0 c b b c 9 9 b a 7 2 9 9 7 e c d 0 e )
2015-09-13 20:25:26 +00:00
file ( DOWNLOAD https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css
c s s / b o o t s t r a p . m i n . c s s E X P E C T E D _ M D 5 5 d 5 3 5 7 c b 3 7 0 4 e 1 f 4 3 a 1 f 5 b f e d 2 a e b f 4 2 )
# ...and compile them
2017-07-13 18:57:28 +00:00
generate_compressed_bins ( ${ CMAKE_BINARY_DIR } js/vue-router.min.js js/vue.min.js
2018-07-06 14:47:48 +00:00
j s / a n s i _ u p . j s j s / C h a r t . m i n . j s c s s / b o o t s t r a p . m i n . c s s )
2015-09-13 20:25:26 +00:00
# (see resources.cpp where these are fetched)
## Server
add_executable ( laminard src/database.cpp src/main.cpp src/server.cpp src/laminar.cpp
2019-03-29 19:43:16 +00:00
s r c / c o n f . c p p s r c / r e s o u r c e s . c p p s r c / r u n . c p p l a m i n a r . c a p n p . c + + $ { C O M P R E S S E D _ B I N S } i n d e x _ h t m l _ s i z e . h )
2018-09-28 07:36:10 +00:00
target_link_libraries ( laminard capnp-rpc capnp kj-http kj-async kj pthread sqlite3 z )
2015-09-13 20:25:26 +00:00
## Client
add_executable ( laminarc src/client.cpp laminar.capnp.c++ )
2015-11-19 20:44:18 +00:00
target_link_libraries ( laminarc capnp-rpc capnp kj-async kj pthread )
2015-09-13 20:25:26 +00:00
2018-01-26 11:07:02 +00:00
## Tests
set ( BUILD_TESTS FALSE CACHE BOOL "Build tests" )
if ( BUILD_TESTS )
find_package ( GTest REQUIRED )
include_directories ( ${ GTEST_INCLUDE_DIRS } src )
2018-02-03 14:47:41 +00:00
add_executable ( laminar-tests src/conf.cpp src/database.cpp src/laminar.cpp src/run.cpp src/server.cpp laminar.capnp.c++ src/resources.cpp ${ COMPRESSED_BINS } test/test-conf.cpp test/test-database.cpp test/test-laminar.cpp test/test-run.cpp test/test-server.cpp )
2018-09-28 07:36:10 +00:00
target_link_libraries ( laminar-tests ${ GTEST_BOTH_LIBRARIES } gmock capnp-rpc capnp kj-http kj-async kj pthread sqlite3 z )
2018-01-26 11:07:02 +00:00
endif ( )
2018-12-14 12:37:44 +00:00
set ( SYSTEMD_UNITDIR lib/systemd/system CACHE PATH "Path to systemd unit files" )
2019-06-30 03:17:59 +00:00
2018-10-16 17:20:43 +00:00
set ( BASH_COMPLETIONS_DIR usr/share/bash-completion/completions CACHE PATH "Path to bash completions directory" )
set ( ZSH_COMPLETIONS_DIR usr/share/zsh/site-functions CACHE PATH "Path to zsh completions directory" )
2019-06-30 03:17:59 +00:00
install ( FILES etc/laminarc-completion.bash DESTINATION ${ BASH_COMPLETIONS_DIR } RENAME laminarc )
install ( FILES etc/laminarc-completion.zsh DESTINATION ${ ZSH_COMPLETIONS_DIR } RENAME _laminarc )
2015-09-19 12:50:22 +00:00
install ( TARGETS laminard laminarc RUNTIME DESTINATION usr/bin )
2018-10-16 17:40:10 +00:00
install ( FILES etc/laminar.service DESTINATION ${ SYSTEMD_UNITDIR } )
2019-06-30 03:05:18 +00:00
# An initial attempt at solving https://github.com/ohwgiles/laminar/issues/92
2019-06-30 13:40:25 +00:00
if ( NOT EXISTS "${CMAKE_INSTALL_PREFIX}etc/laminar.conf" )
2019-06-30 03:05:18 +00:00
install (
2019-06-30 13:40:25 +00:00
F I L E S $ { C M A K E _ I N S T A L L _ P R E F I X } e t c / l a m i n a r . c o n f
2019-06-30 03:05:18 +00:00
D E S T I N A T I O N e t c
)
2019-06-30 13:40:25 +00:00
else ( NOT EXISTS "${CMAKE_INSTALL_PREFIX}etc/laminar.conf" )
2019-06-30 03:05:18 +00:00
# hardcoded values are examples of technical debt, and in an ideal world, are eliminated.
2019-06-30 13:40:25 +00:00
MESSAGE ( "-- A ${CMAKE_INSTALL_PREFIX}etc/laminar.conf file exists, will create ${CMAKE_INSTALL_PREFIX}etc/laminar.conf.example instead of overwriting." )
2019-06-30 03:05:18 +00:00
# This also displays at config time, rather than install time.
# In an ideal world, the user gets offered the option to overwrite, compare, or keep/copy the file
install (
2019-06-30 13:40:25 +00:00
F I L E S $ { C M A K E _ I N S T A L L _ P R E F I X } e t c / l a m i n a r . c o n f
2019-06-30 03:05:18 +00:00
D E S T I N A T I O N e t c
R E N A M E " l a m i n a r . c o n f . e x a m p l e "
)
2019-06-30 13:40:25 +00:00
endif ( NOT EXISTS "${CMAKE_INSTALL_PREFIX}etc/laminar.conf" )
2019-06-30 03:05:18 +00:00