2020-05-01 13:33:20 +00:00
# @author Lukas Heiligenbrunner
2020-05-01 10:33:51 +00:00
# main CMake file
#
2020-05-01 13:33:20 +00:00
# Build lib dependencies:
## libcurl (with sources)
## libconfig (with sources)
#
# documenation build needs doxygen to be installed.
2019-10-23 20:05:10 +00:00
cmake_minimum_required ( VERSION 3.13 )
2019-10-26 12:41:43 +00:00
project ( iprefresher DESCRIPTION "Dynu ip refresher" )
2019-05-01 09:14:52 +00:00
2020-05-01 14:47:22 +00:00
SET ( CMAKE_CXX_STANDARD 17 )
2019-05-01 09:14:52 +00:00
2020-05-01 14:47:22 +00:00
SET ( CMAKE_BUILD_TYPE Release ) # manually SET build type (Release / Debug)
SET ( LIB_METHOD STATIC ) #SHARED / STATIC
SET ( PROJECT_VERSION 1.3.1-dev )
2019-10-27 12:41:40 +00:00
option ( BUILD_DOC "Build documentation" ON )
2019-10-26 08:57:32 +00:00
2020-05-01 14:47:22 +00:00
SET ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } /bin )
SET ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } /bin )
SET ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } /bin )
2019-08-01 20:31:58 +00:00
2020-04-30 08:47:32 +00:00
# config libs
2019-10-27 13:14:03 +00:00
message ( STATUS "Config of Libraries" )
2020-04-30 08:47:32 +00:00
# libcurl
2019-05-01 09:14:52 +00:00
find_package ( CURL REQUIRED )
2019-10-25 10:24:19 +00:00
if ( CURL_FOUND )
2019-10-24 20:00:58 +00:00
message ( STATUS "Found CURL version: ${CURL_VERSION_STRING}" )
message ( STATUS "Using CURL include dir(s): ${CURL_INCLUDE_DIRS}" )
message ( STATUS "Using CURL lib(s): ${CURL_LIBRARIES}" )
2019-10-25 10:24:19 +00:00
else ( )
2019-10-27 13:14:03 +00:00
message ( FATAL_ERROR "Could not find CURL" )
2019-10-25 10:24:19 +00:00
endif ( )
2019-08-01 19:19:02 +00:00
include_directories ( ${ CURL_INCLUDE_DIR } inc )
2019-05-01 09:14:52 +00:00
2020-04-29 18:06:27 +00:00
# libconfig
2020-04-30 08:47:32 +00:00
FIND_PATH ( LIBCONFIG_INCLUDE_DIR libconfig.h++ /usr/include /usr/local/include ) # search for libconfig include headers
FIND_LIBRARY ( CONFIG++_LIBRARY NAMES config++ PATH /usr/lib /usr/local/lib ) # search for actual lib
2020-04-29 18:06:27 +00:00
2020-04-30 08:47:32 +00:00
IF ( CONFIG++_LIBRARY AND LIBCONFIG_INCLUDE_DIR )
MESSAGE ( STATUS "Found Config++: ${CONFIG++_LIBRARY}" )
ELSE ( CONFIG++_LIBRARY AND LIBCONFIG_INCLUDE_DIR )
IF ( NOT LIBCONFIG_INCLUDE_DIR )
MESSAGE ( FATAL_ERROR "Could not find LibConfig++ header file! Try to install 'libconfig-devel'" )
ENDIF ( NOT LIBCONFIG_INCLUDE_DIR )
2020-04-29 18:06:27 +00:00
2020-04-30 08:47:32 +00:00
IF ( NOT CONFIG++_LIBRARY )
MESSAGE ( FATAL_ERROR "Could not find LibConfig++ library file! Try to install 'libconfig'" )
ENDIF ( NOT CONFIG++_LIBRARY )
ENDIF ( CONFIG++_LIBRARY AND LIBCONFIG_INCLUDE_DIR )
include_directories ( ${ LIBCONFIG_INCLUDE_DIR } )
2020-04-29 18:06:27 +00:00
message ( "" )
2020-05-01 14:56:37 +00:00
#read sample config
FILE ( READ ${ CMAKE_SOURCE_DIR } /config/iprefresher.cfg SAMPLECONFIG )
2019-10-26 12:41:43 +00:00
#add version header
FILE ( WRITE ${ CMAKE_SOURCE_DIR } /inc/Version.h
2020-05-01 14:56:37 +00:00
" \ #pragma once
#include <string>
n a m e s p a c e V e r s i o n {
c o n s t s t d : : s t r i n g V E R S I O N = \ " $ { P R O J E C T _ V E R S I O N } \ " ;
c o n s t s t d : : s t r i n g S A M P L E C O N F I G = R \ " ( $ { S A M P L E C O N F I G } ) \ " ;
} "
2019-10-26 12:41:43 +00:00
)
2020-05-01 14:47:22 +00:00
# generate post script for checking if configuration already exists
2020-05-01 15:11:59 +00:00
FILE ( WRITE ${ CMAKE_SOURCE_DIR } /postinst
2020-05-01 14:47:22 +00:00
" #!/bin/bash
i f [ ! - f / e t c / i p r e f r e s h e r . c f g ] ; t h e n
c a t > / e t c / i p r e f r e s h e r . c f g < < - E O M
$ { S A M P L E C O N F I G } E O M
2020-05-01 15:11:59 +00:00
f i \ n "
2020-05-01 14:47:22 +00:00
)
2019-10-27 12:41:40 +00:00
add_library ( api ${ LIB_METHOD }
2019-05-08 17:19:42 +00:00
s r c / a p i / A P I . c p p
s r c / a p i / T e l e g r a m A P I . c p p
2019-06-18 09:23:24 +00:00
s r c / a p i / D y n u A P I . c p p
2020-05-01 14:56:37 +00:00
s r c / a p i / I P A P I . c p p )
2019-08-01 18:18:39 +00:00
2019-10-27 12:41:40 +00:00
add_library ( logger ${ LIB_METHOD }
2019-10-26 12:41:43 +00:00
s r c / F i l e L o g g e r . c p p
2020-05-01 14:56:37 +00:00
s r c / L o g g e r . c p p )
2019-08-01 18:18:39 +00:00
2020-05-01 14:47:22 +00:00
SET ( SOURCE
2019-08-01 18:18:39 +00:00
s r c / m a i n . c p p
2019-10-26 12:41:43 +00:00
s r c / I P R e f r e s h e r . c p p
2020-04-30 17:37:11 +00:00
s r c / C o n f i g . c p p )
2019-05-05 13:38:48 +00:00
2019-10-23 19:55:45 +00:00
add_executable ( iprefresher ${ SOURCE } )
2019-08-01 19:19:02 +00:00
# LINK generated LIBS #
2020-04-29 18:06:27 +00:00
target_link_libraries ( iprefresher api logger ${ CURL_LIBRARIES } config++ )
2019-05-01 09:14:52 +00:00
2019-08-01 19:19:02 +00:00
# INSTALL to SYSTEM #
2020-05-01 14:47:22 +00:00
SET ( CMAKE_INSTALL_PREFIX "/" )
2020-05-01 10:33:51 +00:00
# install binaries
2020-04-30 15:12:30 +00:00
install ( TARGETS iprefresher DESTINATION usr/bin )
2020-05-01 10:33:51 +00:00
# install systemd service and enable it
2020-04-29 18:06:27 +00:00
install ( FILES service/iprefresher.service DESTINATION lib/systemd/system )
2019-10-23 07:24:35 +00:00
IF ( UNIX )
2019-10-27 13:14:03 +00:00
message ( STATUS "config of Package build" )
2019-10-25 10:24:19 +00:00
SET ( CPACK_DEB_COMPONENT_INSTALL 1 )
2019-10-26 08:57:32 +00:00
SET ( CPACK_OUTPUT_FILE_PREFIX packages )
2020-05-01 14:47:22 +00:00
SET ( CPACK_PACKAGING_INSTALL_PREFIX "/" ) # no prefix for package structure
2019-10-25 10:24:19 +00:00
2019-10-23 19:47:54 +00:00
FIND_PROGRAM ( RPMBUILD_EXECUTABLE rpmbuild )
2019-10-23 19:55:45 +00:00
FIND_PROGRAM ( DEB_EXECUTABLE dpkg )
2019-10-23 19:47:54 +00:00
2019-10-23 19:55:45 +00:00
SET ( CPACK_GENERATOR "TGZ;TBZ2" )
2019-10-23 19:47:54 +00:00
#check if rpm build is possible
2019-10-23 19:55:45 +00:00
if ( NOT ${ RPMBUILD_EXECUTABLE } STREQUAL "RPMBUILD_EXECUTABLE-NOTFOUND" )
2019-10-23 19:47:54 +00:00
message ( STATUS "found rpm build executeable --> able to build rpm" )
2020-05-01 14:47:22 +00:00
SET ( CPACK_GENERATOR "${CPACK_GENERATOR};RPM" )
2020-05-01 15:11:59 +00:00
SET ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/postinst" )
2020-05-01 14:47:22 +00:00
SET ( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib/systemd/system" "/lib/systemd" "/lib" "/usr/local/bin" "/usr/local" ) # --> needed to not override existing folders
2019-10-23 19:55:45 +00:00
else ( NOT ${ RPMBUILD_EXECUTABLE } STREQUAL "RPMBUILD_EXECUTABLE-NOTFOUND" )
message ( STATUS "not found rpm build tools --> not building rpm" )
endif ( NOT ${ RPMBUILD_EXECUTABLE } STREQUAL "RPMBUILD_EXECUTABLE-NOTFOUND" )
2019-10-23 19:47:54 +00:00
2019-10-23 19:55:45 +00:00
#check if deb build is possible
if ( NOT ${ DEB_EXECUTABLE } STREQUAL "DEB_EXECUTABLE-NOTFOUND" )
message ( STATUS "found deb build tools --> able to build deb" )
2020-05-01 14:47:22 +00:00
SET ( CPACK_GENERATOR "${CPACK_GENERATOR};DEB" )
2020-05-01 15:11:59 +00:00
set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/postinst" )
2019-10-23 19:55:45 +00:00
else ( NOT ${ DEB_EXECUTABLE } STREQUAL "DEB_EXECUTABLE-NOTFOUND" )
message ( STATUS "not found deb build tools --> not building deb" )
endif ( NOT ${ DEB_EXECUTABLE } STREQUAL "DEB_EXECUTABLE-NOTFOUND" )
2019-10-23 19:47:54 +00:00
2019-10-23 07:24:35 +00:00
SET ( CPACK_CMAKE_GENERATOR "Unix Makefiles" )
SET ( CPACK_SOURCE_GENERATOR "TGZ;TBZ2" )
2019-10-23 19:47:54 +00:00
2019-10-23 07:24:35 +00:00
SET ( CPACK_PACKAGE_DESCRIPTION "IPrefresher to refresh Dynu ip address and notify user via Telegram" )
SET ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "IPrefresher to refresh Dynu ip address and notify user via Telegram" )
SET ( CPACK_PACKAGE_VENDOR "Lukas Heilgienbrunner" )
2019-10-26 12:41:43 +00:00
SET ( CPACK_PACKAGE_VERSION "${PROJECT_VERSION}" )
SET ( CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}" )
2020-04-29 16:33:30 +00:00
SET ( CPACK_PACKAGE_CONTACT "Lukas Heiligenbrunner <lukas.heiligenbrunner@gmail.com>" )
2019-10-23 07:24:35 +00:00
SET ( CPACK_PACKAGE_SECTION "games" )
2020-05-01 14:47:22 +00:00
SET ( CPACK_PACKAGE_DEPENDS "libcurl (>= 7.0.0-1), libconfig (>= 1.5.0)" )
2019-10-23 19:47:54 +00:00
2019-10-23 07:24:35 +00:00
INCLUDE ( CPack )
2019-10-24 20:00:58 +00:00
add_custom_target ( build-linux-packages
" $ { C M A K E _ C O M M A N D } " - - b u i l d " $ { C M A K E _ B I N A R Y _ D I R } " - - t a r g e t p a c k a g e
D E P E N D S $ { P R O J E C T _ N A M E }
C O M M E N T " I n s t a l l i n g $ { P R O J E C T _ N A M E } " )
2020-04-29 16:33:30 +00:00
message ( "" )
2019-10-27 12:41:40 +00:00
ENDIF ( UNIX )
# check if Doxygen is installed
2019-10-27 13:14:03 +00:00
if ( BUILD_DOC )
message ( STATUS "config of DOxygen build" )
find_package ( Doxygen )
if ( DOXYGEN_FOUND )
2020-05-01 14:47:22 +00:00
# SET input and output files
SET ( DOXYGEN_IN ${ CMAKE_CURRENT_SOURCE_DIR } /docs/Doxyfile.in )
SET ( DOXYGEN_OUT ${ CMAKE_CURRENT_BINARY_DIR } /Doxyfile )
2019-10-27 12:41:40 +00:00
# request to configure the file
configure_file ( ${ DOXYGEN_IN } ${ DOXYGEN_OUT } @ONLY )
# note the option ALL which allows to build the docs together with the application
add_custom_target ( doc_doxygen ALL
C O M M A N D $ { D O X Y G E N _ E X E C U T A B L E } $ { D O X Y G E N _ O U T }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
C O M M E N T " G e n e r a t i n g A P I d o c u m e n t a t i o n w i t h D o x y g e n "
V E R B A T I M )
2019-10-27 13:14:03 +00:00
message ( STATUS "Successfully configured doxygen" )
else ( DOXYGEN_FOUND )
message ( STATUS "Doxygen need to be installed to generate the doxygen documentation" )
endif ( DOXYGEN_FOUND )
message ( "" )
2020-04-30 09:30:41 +00:00
endif ( BUILD_DOC )