diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f7da90b..4b9dfa63 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,19 @@ configure_package_config_file( "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/libappimageConfig.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libappimage ) + +configure_file( + "${PROJECT_SOURCE_DIR}/cmake/imported_dependencies.cmake" + "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/imported_dependencies.cmake" + COPYONLY +) + +configure_file( + "${PROJECT_SOURCE_DIR}/cmake/scripts.cmake" + "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/scripts.cmake" + COPYONLY +) + # ... for both configure_file( "${PROJECT_SOURCE_DIR}/cmake/libappimageConfigVersion.cmake.in" diff --git a/src/libappimage/CMakeLists.txt b/src/libappimage/CMakeLists.txt index d23fb1cc..17001f0b 100644 --- a/src/libappimage/CMakeLists.txt +++ b/src/libappimage/CMakeLists.txt @@ -5,7 +5,6 @@ add_subdirectory(utils) set( libappimage_sources - libappimage.c libappimage.cpp $ $ @@ -23,7 +22,6 @@ foreach(target libappimage libappimage_static) target_link_libraries( ${target} PRIVATE libarchive - PRIVATE xdg-basedir PRIVATE XdgUtils::DesktopEntry PRIVATE XdgUtils::BaseDir PRIVATE libappimage_hashlib @@ -44,24 +42,22 @@ foreach(target libappimage libappimage_static) target_link_libraries(${target} PRIVATE -static-libgcc -static-libstdc++) endif() - target_include_directories(${target} PUBLIC $) + set_property(TARGET ${target} PROPERTY PUBLIC_HEADER ${libappimage_public_header}) - set_property(TARGET libappimage PROPERTY PUBLIC_HEADER ${libappimage_public_header}) + set_property(TARGET ${target} PROPERTY VERSION ${libappimage_VERSION}) + set_property(TARGET ${target} PROPERTY SOVERSION ${libappimage_SOVERSION}) - set_property(TARGET libappimage PROPERTY VERSION ${libappimage_VERSION}) - set_property(TARGET libappimage PROPERTY SOVERSION ${libappimage_SOVERSION}) + # install libappimage + install( + TARGETS ${target} + EXPORT libappimageTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libappimage + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libappimage + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/appimage COMPONENT libappimage-dev + ) endforeach() -# install libappimage -install( - TARGETS libappimage - EXPORT libappimageTargets - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libappimage - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libappimage - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/appimage COMPONENT libappimage-dev -) - # install public headers install( DIRECTORY ${PROJECT_SOURCE_DIR}/include/appimage/ @@ -71,6 +67,6 @@ install( # Add all targets to the build-tree export set export( - TARGETS libappimage libappimage_shared libappimage_hashlib + TARGETS libappimage libappimage_static libappimage_shared libappimage_hashlib FILE "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/libappimageTargets.cmake" ) diff --git a/src/libappimage/libappimage.c b/src/libappimage/libappimage.c deleted file mode 100644 index 85d935c5..00000000 --- a/src/libappimage/libappimage.c +++ /dev/null @@ -1,92 +0,0 @@ -/************************************************************************** - * - * Copyright (c) 2004-18 Simon Peter - * - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - **************************************************************************/ - -#ident "AppImage by Simon Peter, http://appimage.org/" - -#include -#include -#include -#include - -#include "xdg-basedir.h" - -// own header -#include "appimage/appimage.h" - -#if HAVE_LIBARCHIVE3 == 1 // CentOS -# include -# include -#else // other systems - -# include -# include -#endif - -#include -#include - -char* appimage_registered_desktop_file_path(const char* path, char* md5, bool verbose) { - glob_t pglob = {}; - - // if md5 has been calculated before, we can just use it to save these extra calculations - // if not, we need to calculate it here - if (md5 == NULL) - md5 = appimage_get_md5(path); - - // sanity check - if (md5 == NULL) { - if (verbose) - fprintf(stderr, "appimage_get_md5() failed\n"); - return NULL; - } - - char* data_home = xdg_data_home(); - - // TODO: calculate this value exactly - char* glob_pattern = malloc(PATH_MAX); - sprintf(glob_pattern, "%s/applications/appimagekit_%s-*.desktop", data_home, md5); - - glob(glob_pattern, 0, NULL, &pglob); - - char* rv = NULL; - - if (pglob.gl_pathc <= 0) { - if (verbose) { - fprintf(stderr, "No results found by glob()"); - } - } else if (pglob.gl_pathc >= 1) { - if (pglob.gl_pathc > 1 && verbose) { - fprintf(stderr, "Too many results returned by glob(), returning first result found"); - } - - // need to copy value to be able to globfree() later on - rv = strdup(pglob.gl_pathv[0]); - } - - globfree(&pglob); - - return rv; -}; diff --git a/src/libappimage/libappimage.cpp b/src/libappimage/libappimage.cpp index c3dbad38..e5bedfe8 100644 --- a/src/libappimage/libappimage.cpp +++ b/src/libappimage/libappimage.cpp @@ -9,11 +9,15 @@ #include // libraries +extern "C" { +#include +} #include #include +#include +#include // local -#include #include #include #include "utils/Logger.h" @@ -228,6 +232,51 @@ off_t appimage_get_payload_offset(char const* path) { return 0; } + +char* appimage_registered_desktop_file_path(const char* path, char* md5, bool verbose) { + glob_t pglob = {}; + + // if md5 has been calculated before, we can just use it to save these extra calculations + // if not, we need to calculate it here + if (md5 == nullptr) + md5 = appimage_get_md5(path); + + // sanity check + if (md5 == nullptr) { + if (verbose) + fprintf(stderr, "appimage_get_md5() failed\n"); + return nullptr; + } + + std::string data_home = XdgUtils::BaseDir::XdgDataHome(); + + // TODO: calculate this value exactly + char* glob_pattern = static_cast(malloc(PATH_MAX)); + sprintf(glob_pattern, "%s/applications/appimagekit_%s-*.desktop", data_home.c_str(), md5); + + glob(glob_pattern, 0, nullptr, &pglob); + + char* rv = nullptr; + + if (pglob.gl_pathc <= 0) { + if (verbose) { + fprintf(stderr, "No results found by glob()"); + } + } else if (pglob.gl_pathc >= 1) { + if (pglob.gl_pathc > 1 && verbose) { + fprintf(stderr, "Too many results returned by glob(), returning first result found"); + } + + // need to copy value to be able to globfree() later on + rv = strdup(pglob.gl_pathv[0]); + } + + globfree(&pglob); + free(glob_pattern); + + return rv; +} + #ifdef LIBAPPIMAGE_DESKTOP_INTEGRATION_ENABLED using namespace appimage::desktop_integration; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4594c7aa..bb27daf8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,9 +9,10 @@ if(BUILD_TESTING) -DGIT_COMMIT="AppImageKit unit tests" ) - add_subdirectory(libappimage) + add_subdirectory(client_app) + if(ENABLE_COVERAGE) set(COVERAGE_LCOV_EXCLUDES '${PROJECT_SOURCE_DIR}/lib/*' '${PROJECT_SOURCE_DIR}/tests/*' '${PROJECT_SOURCE_DIR}/*build*' '/usr/*') setup_target_for_coverage_lcov( diff --git a/tests/client_app/CMakeLists.txt b/tests/client_app/CMakeLists.txt index b5ed361a..ae3e451d 100644 --- a/tests/client_app/CMakeLists.txt +++ b/tests/client_app/CMakeLists.txt @@ -1,7 +1,8 @@ project(client_app) cmake_minimum_required(VERSION 3.0) -find_package(libappimage REQUIRED) - add_executable(client_app main.c) target_link_libraries(client_app libappimage) + +add_executable(client_app_static_linked main.c) +target_link_libraries(client_app_static_linked libappimage_static) diff --git a/travis/build-and-test.sh b/travis/build-and-test.sh index c39787fd..eff9c2fc 100755 --- a/travis/build-and-test.sh +++ b/travis/build-and-test.sh @@ -39,13 +39,3 @@ else # run all unit tests ctest -V fi - -# install libappimage -DESTDIR=$BUILD_DIR/libappimage make install - -# do integration test -mkdir $BUILD_DIR/client_app_build -pushd $BUILD_DIR/client_app_build -cmake -DCMAKE_PREFIX_PATH=$BUILD_DIR/libappimage/usr/local/lib/cmake/libappimage $REPO_ROOT/tests/client_app/ -make -./client_app