more dynamic .dll folder for exe packing

other config dir for windows build
This commit is contained in:
lukas 2020-05-05 17:02:39 +02:00
parent c3bc2293c7
commit d353a2485c
2 changed files with 43 additions and 32 deletions

View File

@ -56,9 +56,15 @@ if (${WinBuild})
# maybe so: set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static") # 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 set(CMAKE_CXX_STANDARD_LIBRARIES -lcurl -lpthread -static-libgcc -static-libstdc++ -lcrypto -lssl -lws2_32 -static -DCURL_STATICLIB)
# or add_definitions(-DCURL_STATICLIB) # or add_definitions(-DCURL_STATICLIB)
# windows config path is same as executable
set(CONFIG_PATH "./iprefresher.cfg")
else () else ()
set(LIBSUFFIX .so) set(LIBSUFFIX .so)
set(SUFFIX "") set(SUFFIX "")
# set /etc/ config path
set(CONFIG_PATH "/etc/iprefresher.cfg")
endif () 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_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 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 include dir(s): ${CURL_INCLUDE_DIRS}")
message(STATUS "Using CURL lib(s): ${CURL_LIBRARIES}") message(STATUS "Using CURL lib(s): ${CURL_LIBRARIES}")
message(STATUS "")
include_directories(${CURL_INCLUDE_DIRS} inc) 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_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 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++ include dir(s): ${LIBCONFIG++_INCLUDE_DIRS}")
message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}") message(STATUS "Using LIBCONFIG++ lib(s): ${LIBCONFIG++_LIBRARIES}")
include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc) include_directories(${LIBCONFIG++_INCLUDE_DIRS} inc)
# configure libconfig
else () else ()
find_package(CURL REQUIRED) find_package(CURL REQUIRED)
if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES) if (CURL_INCLUDE_DIRS AND CURL_LIBRARIES)
@ -123,19 +125,11 @@ FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h
#include <string> #include <string>
namespace Version { namespace Version {
const std::string VERSION = \"${PROJECT_VERSION}\"; const std::string VERSION = \"${PROJECT_VERSION}\";
const std::string ConfigDir = \"${CONFIG_PATH}\";
const std::string SAMPLECONFIG = R\"(${SAMPLECONFIG})\"; 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} add_library(api ${LIB_METHOD}
src/api/API.cpp src/api/API.cpp
src/api/TelegramAPI.cpp src/api/TelegramAPI.cpp
@ -178,6 +172,15 @@ IF (NOT ${WinBuild})
# install systemd service and enable it # install systemd service and enable it
install(FILES service/iprefresher.service DESTINATION lib/systemd/system) 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_DEB_COMPONENT_INSTALL 1)
SET(CPACK_OUTPUT_FILE_PREFIX packages) SET(CPACK_OUTPUT_FILE_PREFIX packages)
@ -215,27 +218,34 @@ IF (NOT ${WinBuild})
SET(CPACK_PACKAGE_SECTION "games") SET(CPACK_PACKAGE_SECTION "games")
ELSE () 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 # Pack a NSIS intaller
set(CPACK_GENERATOR NSIS) set(CPACK_GENERATOR NSIS)
message(STATUS "Using NSIS Package build.")
set(CPACK_NSIS_testcomp_INSTALL_DIRECTORY /) set(CPACK_NSIS_testcomp_INSTALL_DIRECTORY /)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "DynuIpRefresher") set(CPACK_PACKAGE_INSTALL_DIRECTORY "DynuIpRefresher")
SET(CPACK_NSIS_MODIFY_PATH ON) 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 () ENDIF ()
INCLUDE(CPack) INCLUDE(CPack)

View File

@ -21,13 +21,14 @@ std::string Config::chatId;
bool Config::readCredentials() { bool Config::readCredentials() {
libconfig::Config cfg; libconfig::Config cfg;
try { try {
cfg.readFile("/etc/iprefresher.cfg"); // todo make dynamic here
cfg.readFile(Version::ConfigDir.c_str());
} }
catch (const libconfig::FileIOException &fioex) { catch (const libconfig::FileIOException &fioex) {
std::cout << "I/O error while reading config file." << std::endl << "creating new config file!" << std::endl; std::cout << "I/O error while reading config file." << std::endl << "creating new config file!" << std::endl;
std::ofstream myfile; std::ofstream myfile;
myfile.open("/etc/iprefresher.cfg"); myfile.open(Version::ConfigDir);
if (myfile.is_open()) { if (myfile.is_open()) {
myfile << Version::SAMPLECONFIG; myfile << Version::SAMPLECONFIG;
myfile.close(); myfile.close();
@ -66,7 +67,7 @@ bool Config::validateConfig() {
libconfig::Config cfg; libconfig::Config cfg;
try { try {
Logger::message("reading config file"); Logger::message("reading config file");
cfg.readFile("/etc/iprefresher.cfg"); cfg.readFile(Version::ConfigDir.c_str());
} }
catch (const libconfig::FileIOException &fioex) { catch (const libconfig::FileIOException &fioex) {
Logger::warning("config file doesn't exist or permission denied!"); Logger::warning("config file doesn't exist or permission denied!");