From 714c08797390905449499febd17c94b146bfa329 Mon Sep 17 00:00:00 2001 From: lukas Date: Mon, 4 May 2020 21:17:10 +0200 Subject: [PATCH 1/5] first winbuild tests --- CMakeLists.txt | 110 +++++++++++++++++++++++++++++++--------- src/api/TelegramAPI.cpp | 4 +- 2 files changed, 89 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bca895b..70666c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,41 +16,105 @@ SET(CMAKE_BUILD_TYPE Release) # manually SET build type (Release / Debug) SET(LIB_METHOD STATIC) #SHARED / STATIC SET(PROJECT_VERSION 1.3.2) option(BUILD_DOC "Build documentation" ON) +set(WinBuild true) 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) +if (${WinBuild}) + set(LIBSUFFIX .dll) + set(SUFFIX .exe) + + set(CMAKE_SYSTEM_NAME WindowsStore) + set(CMAKE_SYSTEM_VERSION 10.0) + set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) # x64 build toolchain + #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}) + + + # 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_FIND_ROOT_PATH_MODE_PACKAGE 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++ -DCURL_STATICLIB -lstdc++ -lwsock32 -lws2_32 ${CMAKE_CSS_STANDARD_LIBRARIES}") +# set(CMAKE_CXX_STANDARD_LIBRARIES " -lpthread ${CMAKE_CXX_STANDARD_LIBRARIES} -static") +# +# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") + + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static") + # 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 "") +endif () + + # config libs message(STATUS "Config of Libraries") # libcurl -find_package(CURL REQUIRED) -if (CURL_FOUND) +if (${WinBuild}) + # configure libcurl + FIND_PATH(CURL_INCLUDE_DIRS curl/curl.h /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/include/) # search for libconfig include headers + FIND_LIBRARY(CURL_LIBRARIES NAMES curl HINTS /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib) # search for actual lib + 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}") + set(CURL_LIBRARIES /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libcurl.dll.a) + + include_directories(${CURL_INCLUDE_DIRS} inc) + + # configure libconfig + FIND_PATH(LIBCONFIG++_INCLUDE_DIRS libconfig.h++ /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/include/) # search for libconfig include headers + FIND_LIBRARY(LIBCONFIG++_LIBRARIES NAMES config++ HINTS /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib) # search for actual lib + set(LIBCONFIG++_LIBRARIES /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libconfig++.dll.a) + + message(STATUS "Found LIBCONFIG++ version: ${CURL_VERSION_STRING}") + message(STATUS "Using LIBCONFIG++ include dir(s): ${LIBCONFIG++_INCLUDE_DIRS}") + message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}") + + include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc) + + # configure libconfig + else () - message(FATAL_ERROR "Could not find CURL") + find_package(CURL REQUIRED) + if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES) + 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}") + else () + message(FATAL_ERROR "Could not find CURL") + endif () + include_directories(${CURL_INCLUDE_DIR} inc) + + message("") + # libconfig + FIND_PACKAGE(libconfig++ REQUIRED) + if (LIBCONFIG++_INCLUDE_DIRS AND LIBCONFIG++_LIBRARY_DIRS) + message(STATUS "Found libconfig version: ${LIBCONFIG++_VERSION}") + message(STATUS "Using libconfig include dir(s): ${LIBCONFIG++_INCLUDE_DIRS}") + message(STATUS "Using libconfig lib(s): ${LIBCONFIG++_LIBRARY_DIRS}") + else () + message(FATAL_ERROR "Could not find CURL") + endif () + include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc) endif () -include_directories(${CURL_INCLUDE_DIR} inc) - -# libconfig -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 - -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) - - 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}) message("") @@ -94,7 +158,7 @@ SET(SOURCE add_executable(iprefresher ${SOURCE}) # LINK generated LIBS # -target_link_libraries(iprefresher api logger ${CURL_LIBRARIES} config++) +target_link_libraries(iprefresher api logger ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES}) # INSTALL to SYSTEM # SET(CMAKE_INSTALL_PREFIX "/") diff --git a/src/api/TelegramAPI.cpp b/src/api/TelegramAPI.cpp index 3df25ea..00131ac 100644 --- a/src/api/TelegramAPI.cpp +++ b/src/api/TelegramAPI.cpp @@ -15,8 +15,8 @@ int TelegramAPI::sendMessage(const std::string& text) { std::string reply = request("https://api.telegram.org/bot" + apikey + "/sendmessage", false, args, headers); - unsigned const long ULONG_MAX = -1; - if (reply.find("\"error_code\"") != ULONG_MAX) { + unsigned long ulongmax = -1; + if (reply.find("\"error_code\"") != ulongmax) { Logger::error("failed to refresh the ip (Dynu API)"); return -1; } From 2b66e229e37dc0874a972749f3ff90841e9fd4fb Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 5 May 2020 14:20:02 +0200 Subject: [PATCH 2/5] improved windows cross build nsis packaging --- CMakeLists.txt | 95 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70666c3..3c550d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,13 +15,14 @@ SET(CMAKE_CXX_STANDARD 17) SET(CMAKE_BUILD_TYPE Release) # manually SET build type (Release / Debug) SET(LIB_METHOD STATIC) #SHARED / STATIC SET(PROJECT_VERSION 1.3.2) -option(BUILD_DOC "Build documentation" ON) +option(BUILD_DOC "Build documentation" OFF) set(WinBuild true) 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) +# setup winbuild compilers if (${WinBuild}) set(LIBSUFFIX .dll) set(SUFFIX .exe) @@ -48,16 +49,13 @@ if (${WinBuild}) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE 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++ -DCURL_STATICLIB -lstdc++ -lwsock32 -lws2_32 ${CMAKE_CSS_STANDARD_LIBRARIES}") -# set(CMAKE_CXX_STANDARD_LIBRARIES " -lpthread ${CMAKE_CXX_STANDARD_LIBRARIES} -static") -# -# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") - - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static") - # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") - # set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) - #add_definitions(-DCURL_STATICLIB) + set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CSS_STANDARD_LIBRARIES}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") + # currently libs are dynamically linked eg. dlls have to be copied to same folder + # todo link dynamically. + # maybe so: set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static") + # or set(CMAKE_CXX_STANDARD_LIBRARIES -lcurl -lpthread -static-libgcc -static-libstdc++ -lcrypto -lssl -lws2_32 -static -DCURL_STATICLIB) + # or add_definitions(-DCURL_STATICLIB) else () set(LIBSUFFIX .so) set(SUFFIX "") @@ -68,21 +66,20 @@ endif () message(STATUS "Config of Libraries") # libcurl if (${WinBuild}) + SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll") # configure libcurl FIND_PATH(CURL_INCLUDE_DIRS curl/curl.h /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/include/) # search for libconfig include headers - FIND_LIBRARY(CURL_LIBRARIES NAMES curl HINTS /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib) # search for actual lib + FIND_LIBRARY(CURL_LIBRARIES NAMES libcurl.dll.a HINTS /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib) # search for actual lib 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}") - set(CURL_LIBRARIES /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libcurl.dll.a) include_directories(${CURL_INCLUDE_DIRS} inc) # configure libconfig FIND_PATH(LIBCONFIG++_INCLUDE_DIRS libconfig.h++ /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/include/) # search for libconfig include headers - FIND_LIBRARY(LIBCONFIG++_LIBRARIES NAMES config++ HINTS /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib) # search for actual lib - set(LIBCONFIG++_LIBRARIES /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libconfig++.dll.a) + FIND_LIBRARY(LIBCONFIG++_LIBRARIES NAMES libconfig++.dll.a HINTS /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib) # search for actual lib message(STATUS "Found LIBCONFIG++ version: ${CURL_VERSION_STRING}") message(STATUS "Using LIBCONFIG++ include dir(s): ${LIBCONFIG++_INCLUDE_DIRS}") @@ -160,16 +157,28 @@ add_executable(iprefresher ${SOURCE}) # LINK generated LIBS # target_link_libraries(iprefresher api logger ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES}) -# INSTALL to SYSTEM # +# General Packaging options: +message(STATUS "config of Package build") + +set(CPACK_PACKAGE_NAME "DynuIpRefresher") +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") +SET(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") +SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}") +SET(CPACK_PACKAGE_CONTACT "Lukas Heiligenbrunner ") + SET(CMAKE_INSTALL_PREFIX "/") -# install binaries -install(TARGETS iprefresher DESTINATION usr/bin) -# install systemd service and enable it -install(FILES service/iprefresher.service DESTINATION lib/systemd/system) + +IF (NOT ${WinBuild}) + # INSTALL to Linux SYSTEM # + + # install binaries + install(TARGETS iprefresher DESTINATION usr/bin) + # install systemd service and enable it + install(FILES service/iprefresher.service DESTINATION lib/systemd/system) -IF (UNIX) - message(STATUS "config of Package build") SET(CPACK_DEB_COMPONENT_INSTALL 1) SET(CPACK_OUTPUT_FILE_PREFIX packages) SET(CPACK_PACKAGING_INSTALL_PREFIX "/") # no prefix for package structure @@ -204,22 +213,40 @@ IF (UNIX) SET(CPACK_CMAKE_GENERATOR "Unix Makefiles") SET(CPACK_SOURCE_GENERATOR "TGZ;TBZ2") - 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") - SET(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") - SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${PROJECT_VERSION}") - SET(CPACK_PACKAGE_CONTACT "Lukas Heiligenbrunner ") SET(CPACK_PACKAGE_SECTION "games") INCLUDE(CPack) +ELSE () + # Pack a NSIS intaller + set(CPACK_GENERATOR NSIS) - add_custom_target(build-linux-packages - "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target package - DEPENDS ${PROJECT_NAME} - COMMENT "Installing ${PROJECT_NAME}") - message("") -ENDIF (UNIX) + set(CPACK_NSIS_testcomp_INSTALL_DIRECTORY /) + set(CPACK_PACKAGE_INSTALL_DIRECTORY "DynuIpRefresher") + SET(CPACK_NSIS_MODIFY_PATH ON) + + set_target_properties(iprefresher PROPERTIES SUFFIX ".exe") + install(TARGETS iprefresher DESTINATION .) + # todo more dynamic + install(FILES /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libcurl-4.dll + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libssh2-1.dll + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libcrypto-1_1-x64.dll + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libssl-1_1-x64.dll + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/zlib1.dll + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libidn2-0.dll + /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libconfig++-11.dll + DESTINATION .) +ENDIF () + +INCLUDE(CPack) + +add_custom_target(build-packages + "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target package + DEPENDS ${PROJECT_NAME} + COMMENT "Installing ${PROJECT_NAME}") +message("") # check if Doxygen is installed if (BUILD_DOC) From c3bc2293c7a5a53a527862f265731ce5346d6568 Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 5 May 2020 14:34:25 +0200 Subject: [PATCH 3/5] remove double include of cpack --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c550d6..acd644c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,8 +214,6 @@ IF (NOT ${WinBuild}) SET(CPACK_SOURCE_GENERATOR "TGZ;TBZ2") SET(CPACK_PACKAGE_SECTION "games") - - INCLUDE(CPack) ELSE () # Pack a NSIS intaller set(CPACK_GENERATOR NSIS) From d353a2485c1f8df2a8063d71ed811deab771549f Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 5 May 2020 17:02:39 +0200 Subject: [PATCH 4/5] more dynamic .dll folder for exe packing other config dir for windows build --- CMakeLists.txt | 68 +++++++++++++++++++++++++++++--------------------- src/Config.cpp | 7 +++--- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acd644c..a4238a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,9 +56,15 @@ if (${WinBuild}) # maybe so: set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static") # or set(CMAKE_CXX_STANDARD_LIBRARIES -lcurl -lpthread -static-libgcc -static-libstdc++ -lcrypto -lssl -lws2_32 -static -DCURL_STATICLIB) # or add_definitions(-DCURL_STATICLIB) + + # windows config path is same as executable + set(CONFIG_PATH "./iprefresher.cfg") else () set(LIBSUFFIX .so) set(SUFFIX "") + + # set /etc/ config path + set(CONFIG_PATH "/etc/iprefresher.cfg") endif () @@ -71,9 +77,9 @@ if (${WinBuild}) FIND_PATH(CURL_INCLUDE_DIRS curl/curl.h /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/include/) # search for libconfig include headers FIND_LIBRARY(CURL_LIBRARIES NAMES libcurl.dll.a HINTS /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib) # search for actual lib - 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}") + message(STATUS "") include_directories(${CURL_INCLUDE_DIRS} inc) @@ -81,14 +87,10 @@ if (${WinBuild}) FIND_PATH(LIBCONFIG++_INCLUDE_DIRS libconfig.h++ /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/include/) # search for libconfig include headers FIND_LIBRARY(LIBCONFIG++_LIBRARIES NAMES libconfig++.dll.a HINTS /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/lib) # search for actual lib - message(STATUS "Found LIBCONFIG++ version: ${CURL_VERSION_STRING}") message(STATUS "Using LIBCONFIG++ include dir(s): ${LIBCONFIG++_INCLUDE_DIRS}") message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}") include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc) - - # configure libconfig - else () find_package(CURL REQUIRED) if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES) @@ -123,19 +125,11 @@ FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h #include namespace Version { const std::string VERSION = \"${PROJECT_VERSION}\"; + const std::string ConfigDir = \"${CONFIG_PATH}\"; const std::string SAMPLECONFIG = R\"(${SAMPLECONFIG})\"; }" ) -# generate post script for checking if configuration already exists -FILE(WRITE ${CMAKE_SOURCE_DIR}/postinst - "#!/bin/bash -if [ ! -f /etc/iprefresher.cfg ]; then - cat > /etc/iprefresher.cfg <<- EOM -${SAMPLECONFIG}EOM -fi\n" - ) - add_library(api ${LIB_METHOD} src/api/API.cpp src/api/TelegramAPI.cpp @@ -178,6 +172,15 @@ IF (NOT ${WinBuild}) # install systemd service and enable it install(FILES service/iprefresher.service DESTINATION lib/systemd/system) + # generate post script for checking if configuration already exists + FILE(WRITE ${CMAKE_SOURCE_DIR}/postinst + "#!/bin/bash +if [ ! -f ${CONFIG_PATH} ]; then + cat > ${CONFIG_PATH} <<- EOM +${SAMPLECONFIG}EOM +fi\n" + ) + SET(CPACK_DEB_COMPONENT_INSTALL 1) SET(CPACK_OUTPUT_FILE_PREFIX packages) @@ -215,27 +218,34 @@ IF (NOT ${WinBuild}) SET(CPACK_PACKAGE_SECTION "games") ELSE () + # INSTALL to Windows SYSTEM # + + # install binary to current folder + set_target_properties(iprefresher PROPERTIES SUFFIX ".exe") + install(TARGETS iprefresher DESTINATION .) + + # install .dll dependencies + # todo check if files exist... + install(FILES /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/libcurl-4.dll + /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/libssh2-1.dll + /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/libstdc++-6.dll + /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/libgcc_s_seh-1.dll + /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/libcrypto-1_1-x64.dll + /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/libssl-1_1-x64.dll + /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/libwinpthread-1.dll + /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/zlib1.dll + /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/libidn2-0.dll + /usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/libconfig++-11.dll + DESTINATION .) + + # Pack a NSIS intaller set(CPACK_GENERATOR NSIS) + message(STATUS "Using NSIS Package build.") set(CPACK_NSIS_testcomp_INSTALL_DIRECTORY /) set(CPACK_PACKAGE_INSTALL_DIRECTORY "DynuIpRefresher") SET(CPACK_NSIS_MODIFY_PATH ON) - - set_target_properties(iprefresher PROPERTIES SUFFIX ".exe") - install(TARGETS iprefresher DESTINATION .) - # todo more dynamic - install(FILES /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libcurl-4.dll - /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libssh2-1.dll - /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll - /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll - /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libcrypto-1_1-x64.dll - /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libssl-1_1-x64.dll - /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll - /usr/x86_64-w64-mingw32/sys-root/mingw/bin/zlib1.dll - /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libidn2-0.dll - /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libconfig++-11.dll - DESTINATION .) ENDIF () INCLUDE(CPack) diff --git a/src/Config.cpp b/src/Config.cpp index 07bc961..8fdfd2f 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -21,13 +21,14 @@ std::string Config::chatId; bool Config::readCredentials() { libconfig::Config cfg; try { - cfg.readFile("/etc/iprefresher.cfg"); + // todo make dynamic here + cfg.readFile(Version::ConfigDir.c_str()); } catch (const libconfig::FileIOException &fioex) { std::cout << "I/O error while reading config file." << std::endl << "creating new config file!" << std::endl; std::ofstream myfile; - myfile.open("/etc/iprefresher.cfg"); + myfile.open(Version::ConfigDir); if (myfile.is_open()) { myfile << Version::SAMPLECONFIG; myfile.close(); @@ -66,7 +67,7 @@ bool Config::validateConfig() { libconfig::Config cfg; try { Logger::message("reading config file"); - cfg.readFile("/etc/iprefresher.cfg"); + cfg.readFile(Version::ConfigDir.c_str()); } catch (const libconfig::FileIOException &fioex) { Logger::warning("config file doesn't exist or permission denied!"); From 9f99997c8b76d83ec4acf36d4f790f555b6a252c Mon Sep 17 00:00:00 2001 From: lukas Date: Wed, 6 May 2020 11:03:39 +0200 Subject: [PATCH 5/5] added Readme for cross compile tasks --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a9eaf3..d3b06a0 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,16 @@ cd into downloaded files and Generate makefiles: ### Windows cross build -TODO! +Set Winbuild flag in CMakeList.txt. + +Dependencies: +* MinGW Compiler +* MinGW-libcurl +* MinGW-libconfig++ + +Optional dependencies +* NSIS Pack tool (for creating installer) +* doxygen (for generating html doc) + +Some addition configuration of lib paths may be needed in CMakeList.txt. +`make package` will pack it into a NSIS installer for Windows.