Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libappimage_static #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
azubieta marked this conversation as resolved.
Show resolved Hide resolved
"${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"
Expand Down
28 changes: 12 additions & 16 deletions src/libappimage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_subdirectory(utils)

set(
libappimage_sources
libappimage.c
libappimage.cpp
$<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:appimage_utils>
Expand All @@ -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
Expand All @@ -44,24 +42,22 @@ foreach(target libappimage libappimage_static)
target_link_libraries(${target} PRIVATE -static-libgcc -static-libstdc++)
endif()

target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I somewhere read that using PUBLIC_HEADER like this is actually wrong. Is there any reason you use that property? Are there alternative ways? (IIRC, you introduced that years ago, and I was always curious.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, using PUBLIC_HEADER in Unix system is wrong, that property only has a real effect on MacOS.

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/
Expand All @@ -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"
)
92 changes: 0 additions & 92 deletions src/libappimage/libappimage.c

This file was deleted.

51 changes: 50 additions & 1 deletion src/libappimage/libappimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
#include <type_traits>

// libraries
extern "C" {
#include <glob.h>
}
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <XdgUtils/BaseDir/BaseDir.h>
#include <XdgUtils/DesktopEntry/DesktopEntry.h>

// local
#include <XdgUtils/DesktopEntry/DesktopEntry.h>
#include <appimage/utils/ResourcesExtractor.h>
#include <appimage/core/AppImage.h>
#include "utils/Logger.h"
Expand Down Expand Up @@ -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<char*>(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;

Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions tests/client_app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "test" here is to check if linking works? You should document that somewhere, e.g., above this line.

target_link_libraries(client_app_static_linked libappimage_static)
10 changes: 0 additions & 10 deletions travis/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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