2019-10-23 20:05:10 +00:00
|
|
|
cmake_minimum_required(VERSION 3.13)
|
|
|
|
project(iprefresher VERSION 1.2.0 DESCRIPTION "Dynu ip refresher")
|
2019-05-01 09:14:52 +00:00
|
|
|
|
2019-08-01 18:18:39 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2019-05-01 09:14:52 +00:00
|
|
|
|
2019-10-23 19:47:54 +00:00
|
|
|
set(CMAKE_BUILD_TYPE Release) # manually set build type (Release / Debug)
|
|
|
|
set(libmethod STATIC) #SHARED / STATIC
|
2019-10-26 08:57:32 +00:00
|
|
|
set(WinBuild false)
|
|
|
|
|
|
|
|
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-10-25 10:24:19 +00:00
|
|
|
|
|
|
|
#set up toolchain
|
|
|
|
|
|
|
|
if (${WinBuild})
|
|
|
|
set(LIBSUFFIX .dll)
|
|
|
|
set(SUFFIX .exe)
|
2019-10-24 20:00:58 +00:00
|
|
|
|
2019-10-25 10:24:19 +00:00
|
|
|
set(CMAKE_SYSTEM_NAME Windows)
|
|
|
|
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
|
|
|
|
#set(TOOLCHAIN_PREFIX i686-w64-mingw32)
|
|
|
|
|
|
|
|
# cross compilers to use for C and C++
|
|
|
|
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
|
|
|
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
|
|
|
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
|
|
|
|
|
|
|
# target environment on the build host system
|
|
|
|
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw /usr/lib/gcc/${TOOLCHAIN_PREFIX}/8.3.0)
|
|
|
|
|
|
|
|
|
|
|
|
# modify default behavior of FIND_XXX() commands to
|
|
|
|
# search for headers/libs in the target environment and
|
|
|
|
# search for programs in the build host environment
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
|
|
|
|
|
|
# set(CMAKE_CXX_STANDARD_LIBRARIES -lcurl -lpthread -static-libgcc -static-libstdc++ -lcrypto -lssl -lws2_32 -std=c++11 -static -DCURL_STATICLIB)
|
|
|
|
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lcurl -lpthread -lstdc++ -lwsock32 -lws2_32 ${CMAKE_CSS_STANDARD_LIBRARIES}")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -Wl,-Bstatic,--whole-archive -Wl,--no-whole-archive")
|
|
|
|
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
|
|
|
|
# set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
|
|
|
|
add_definitions(-DCURL_STATICLIB)
|
|
|
|
else ()
|
|
|
|
set(LIBSUFFIX .so)
|
|
|
|
set(SUFFIX "")
|
2019-10-24 20:00:58 +00:00
|
|
|
endif ()
|
2019-08-01 20:31:58 +00:00
|
|
|
|
2019-10-25 10:24:19 +00:00
|
|
|
|
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}")
|
|
|
|
# include_directories(${CURL_INCLUDE_DIRS})
|
2019-10-25 10:24:19 +00:00
|
|
|
else ()
|
2019-10-24 20:00:58 +00:00
|
|
|
message(FATAL_ERROR "Could not find CURLLL")
|
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
|
|
|
|
2019-10-23 19:47:54 +00:00
|
|
|
add_library(api ${libmethod}
|
2019-05-08 17:19:42 +00:00
|
|
|
src/api/API.cpp
|
|
|
|
|
|
|
|
src/api/TelegramAPI.cpp
|
2019-06-18 09:23:24 +00:00
|
|
|
|
|
|
|
src/api/DynuAPI.cpp
|
2019-08-01 18:18:39 +00:00
|
|
|
|
|
|
|
src/api/IPAPI.cpp
|
|
|
|
)
|
|
|
|
|
2019-10-23 19:47:54 +00:00
|
|
|
add_library(logger ${libmethod}
|
2019-08-01 18:18:39 +00:00
|
|
|
src/Logger.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
set(SOURCE
|
|
|
|
src/main.cpp
|
2019-08-02 20:44:42 +00:00
|
|
|
src/IPRefresher.cpp inc/IPRefresher.h)
|
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 #
|
2019-10-23 19:55:45 +00:00
|
|
|
target_link_libraries(iprefresher api logger ${CURL_LIBRARIES})
|
2019-05-01 09:14:52 +00:00
|
|
|
|
2019-08-01 19:19:02 +00:00
|
|
|
# INSTALL to SYSTEM #
|
2019-10-23 19:55:45 +00:00
|
|
|
install(TARGETS iprefresher DESTINATION bin)
|
2019-10-26 08:57:32 +00:00
|
|
|
|
|
|
|
pkg_check_modules(SYSTEMD "systemd")
|
|
|
|
if (SYSTEMD_FOUND AND "${SYSTEMD_SERVICES_INSTALL_DIR}" STREQUAL "")
|
|
|
|
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE}
|
|
|
|
--variable=systemdsystemunitdir systemd
|
|
|
|
OUTPUT_VARIABLE SYSTEMD_SERVICES_INSTALL_DIR)
|
|
|
|
string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_SERVICES_INSTALL_DIR
|
|
|
|
"${SYSTEMD_SERVICES_INSTALL_DIR}")
|
|
|
|
elseif (NOT SYSTEMD_FOUND AND SYSTEMD_SERVICES_INSTALL_DIR)
|
|
|
|
message (FATAL_ERROR "Variable SYSTEMD_SERVICES_INSTALL_DIR is\
|
|
|
|
defined, but we can't find systemd using pkg-config")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (SYSTEMD_FOUND)
|
|
|
|
set(WITH_SYSTEMD "ON")
|
|
|
|
message(STATUS "systemd services install dir: ${SYSTEMD_SERVICES_INSTALL_DIR}")
|
|
|
|
else()
|
|
|
|
set(WITH_SYSTEMD "OFF")
|
|
|
|
endif (SYSTEMD_FOUND)
|
|
|
|
|
|
|
|
#set(CMAKE_INSTALL_PREFIX /)
|
|
|
|
message(STATUS ${CMAKE_BINARY_DIR})
|
|
|
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/iprefresher.service DESTINATION ${SYSTEMD_SERVICES_INSTALL_DIR})
|
2019-10-23 07:24:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
IF (UNIX)
|
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)
|
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")
|
|
|
|
set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM")
|
2019-10-23 20:05:10 +00:00
|
|
|
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/lib/systemd/system" "/usr/lib/systemd") # --> 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")
|
|
|
|
set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB")
|
|
|
|
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-23 07:32:33 +00:00
|
|
|
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
|
|
|
|
SET(CPACK_PACKAGE_VERSION_MINOR "2")
|
2019-10-23 07:24:35 +00:00
|
|
|
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
|
|
|
|
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
|
|
|
|
SET(CPACK_PACKAGE_CONTACT "Lukas Heiligenbrunner <ultimategameingcookie@gmail.com>")
|
|
|
|
SET(CPACK_PACKAGE_SECTION "games")
|
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
|
|
|
|
"${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target package
|
|
|
|
DEPENDS ${PROJECT_NAME}
|
|
|
|
COMMENT "Installing ${PROJECT_NAME}")
|
2019-10-23 19:47:54 +00:00
|
|
|
|
2019-10-25 10:24:19 +00:00
|
|
|
ENDIF (UNIX)
|