File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
88set (LINUXDEPLOY_VERSION 0.1-alpha-1)
99add_definitions (-DLINUXDEPLOY_VERSION= "${LINUXDEPLOY_VERSION} " )
1010
11+ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH } "${CMAKE_SOURCE_DIR } /cmake/Modules/" )
12+
1113add_subdirectory (lib )
1214
1315add_subdirectory (src )
Original file line number Diff line number Diff line change 1+ message (STATUS "Searching for libmagic" )
2+
3+ find_library (LIBMAGIC_A libmagic.a )
4+
5+ if (NOT LIBMAGIC_A)
6+ message (FATAL_ERROR "libmagic.a not found" )
7+ endif ()
8+
9+ find_path (LIBMAGIC_MAGIC_H
10+ NAMES magic.h
11+ HINTS ${CMAKE_INSTALL_PREFIX }
12+ PATH_SUFFIXES include include /linux
13+ )
14+
15+ if (NOT LIBMAGIC_MAGIC_H)
16+ message (FATAL_ERROR "magic.h not found" )
17+ endif ()
18+
19+ add_library (libmagic_static INTERFACE IMPORTED )
20+ set_property (TARGET libmagic_static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${LIBMAGIC_MAGIC_H} )
21+ set_property (TARGET libmagic_static PROPERTY INTERFACE_LINK_LIBRARIES ${LIBMAGIC_A} )
Original file line number Diff line number Diff line change 11# globally include own includes
22include_directories (${PROJECT_SOURCE_DIR } /include )
33
4+ add_subdirectory (util )
45add_subdirectory (core )
Original file line number Diff line number Diff line change @@ -7,8 +7,11 @@ file(GLOB HEADERS ${PROJECT_SOURCE_DIR}/include/linuxdeploy/core/*.h)
77
88set (Boost_USE_STATIC_LIBS ON )
99find_package (Boost REQUIRED COMPONENTS filesystem regex )
10+
1011find_package (Threads )
1112
13+ find_package (LibMagic )
14+
1215find_package (PkgConfig )
1316pkg_check_modules (magick++ REQUIRED IMPORTED_TARGET Magick++ )
1417
@@ -19,9 +22,8 @@ execute_process(
1922)
2023
2124add_library (linuxdeploy_core STATIC elf.cpp log .cpp appdir.cpp desktopfile.cpp ${HEADERS} )
22- target_link_libraries (linuxdeploy_core PUBLIC Boost::filesystem Boost::regex subprocess cpp-feather-ini-parser PkgConfig::magick++ ${CMAKE_THREAD_LIBS_INIT} )
25+ target_link_libraries (linuxdeploy_core PUBLIC linuxdeploy_util Boost::filesystem Boost::regex subprocess cpp-feather-ini-parser PkgConfig::magick++ libmagic_static ${CMAKE_THREAD_LIBS_INIT} )
2326target_include_directories (linuxdeploy_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR } )
24- target_include_directories (linuxdeploy_core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR } /../util )
2527target_include_directories (linuxdeploy_core PUBLIC ${PROJECT_SOURCE_DIR } /include )
2628target_compile_definitions (linuxdeploy_core PUBLIC -DBOOST_NO_CXX11_SCOPED_ENUMS )
2729
Original file line number Diff line number Diff line change 1+ add_library (linuxdeploy_util STATIC magicwrapper.cpp magicwrapper.h util.h )
2+ target_include_directories (linuxdeploy_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR } )
Original file line number Diff line number Diff line change 1+ // system includes
2+ #include < magic.h>
3+ #include < string>
4+
5+ // local includes
6+ #include " magicwrapper.h"
7+
8+ namespace linuxdeploy {
9+ namespace util {
10+ namespace magic {
11+ class MagicWrapper ::PrivateData {
12+ private:
13+ magic_t cookie;
14+
15+ public:
16+ PrivateData () noexcept (false ) {
17+ cookie = magic_open (MAGIC_DEBUG | MAGIC_SYMLINK | MAGIC_MIME_TYPE );
18+
19+ if (cookie == nullptr )
20+ throw MagicError (" Failed to open magic database" );
21+ }
22+
23+ ~PrivateData () {
24+ if (cookie != nullptr ) {
25+ magic_close (cookie);
26+ cookie = nullptr ;
27+ }
28+ };
29+
30+ std::string fileType (const std::string& path) {
31+ const auto * buf = magic_file (cookie, path.c_str ());
32+
33+ if (buf == nullptr )
34+ return " " ;
35+
36+ return buf;
37+ }
38+ };
39+
40+ MagicWrapper::MagicWrapper () {
41+ d = new PrivateData ();
42+ }
43+
44+ MagicWrapper::~MagicWrapper () {
45+ delete d;
46+ }
47+ }
48+ }
49+ }
Original file line number Diff line number Diff line change 1+ // system includes
2+ #include < exception>
3+ #include < string>
4+ #include < utility>
5+
6+ #pragma once
7+
8+ namespace linuxdeploy {
9+ namespace util {
10+ namespace magic {
11+ // thrown by constructors if opening the magic database fails
12+ class MagicError : std::exception {
13+ private:
14+ const std::string message;
15+
16+ public:
17+ explicit MagicError () : message() {}
18+
19+ explicit MagicError (std::string message) : message(std::move(message)) {}
20+
21+ const char * what () {
22+ return message.c_str ();
23+ }
24+ };
25+
26+ class MagicWrapper {
27+ private:
28+ class PrivateData ;
29+ PrivateData *d;
30+
31+ public:
32+ MagicWrapper ();
33+ ~MagicWrapper ();
34+ };
35+ }
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments