Skip to content

Commit

Permalink
[libmagic] Add CMake config. (#35274)
Browse files Browse the repository at this point in the history
* [libmagic] Add CMake config.

* Fix license information and add usage.

* Address PR feedback.
Co-authored-by: Kai Pastor <dg0yt@darc.de>

* Set some missing properties.

* Fix location to import library.

* Update version database.
  • Loading branch information
teo-tsirpanis committed Dec 1, 2023
1 parent ca9ac0b commit 16ee2ec
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
12 changes: 10 additions & 2 deletions ports/libmagic/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,13 @@ file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/${PORT}/man5")

# Handle copyright
file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/unofficial-${PORT}-config.cmake.in"
"${CURRENT_PACKAGES_DIR}/share/unofficial-${PORT}/unofficial-${PORT}-config.cmake"
INSTALL_DESTINATION "share/unofficial-${PORT}"
)

# Handle copyright and usage
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
69 changes: 69 additions & 0 deletions ports/libmagic/unofficial-libmagic-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@PACKAGE_INIT@

if(WIN32 AND "@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static")
include(CMakeFindDependencyMacro)
find_dependency(unofficial-tre)
endif()

# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()

if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static")
add_library(unofficial::libmagic::libmagic STATIC IMPORTED)
else()
add_library(unofficial::libmagic::libmagic SHARED IMPORTED)
endif()

set_target_properties(unofficial::libmagic::libmagic PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
)

if(WIN32 AND "@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static")
set_target_properties(unofficial::libmagic::libmagic PROPERTIES
INTERFACE_LINK_LIBRARIES "\$<LINK_ONLY:unofficial::tre::tre>"
)
endif()

macro(add_library_config config prefix)
set_property(TARGET unofficial::libmagic::libmagic APPEND PROPERTY IMPORTED_CONFIGURATIONS ${config})
if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static")
set_target_properties(unofficial::libmagic::libmagic PROPERTIES
IMPORTED_LOCATION_${config} "${_IMPORT_PREFIX}/${prefix}lib/@VCPKG_TARGET_STATIC_LIBRARY_PREFIX@magic@VCPKG_TARGET_STATIC_LIBRARY_SUFFIX@"
IMPORTED_LINK_INTERFACE_LANGUAGES_${config} "C"
)
else()
if(WIN32)
set(library_dir "${_IMPORT_PREFIX}/${prefix}bin/")
set(soversion_suffix "-1")
set_target_properties(unofficial::libmagic::libmagic PROPERTIES
IMPORTED_IMPLIB_${config} "${_IMPORT_PREFIX}/${prefix}/lib/@VCPKG_TARGET_IMPORT_LIBRARY_PREFIX@magic@VCPKG_TARGET_IMPORT_LIBRARY_SUFFIX@"
)
else()
set(library_dir "${_IMPORT_PREFIX}/${prefix}lib/")
endif()
set_target_properties(unofficial::libmagic::libmagic PROPERTIES
IMPORTED_LOCATION_${config} "${library_dir}@VCPKG_TARGET_SHARED_LIBRARY_PREFIX@magic${soversion_suffix}@VCPKG_TARGET_SHARED_LIBRARY_SUFFIX@"
)
unset(soversion_suffix)
unset(library_dir)
endif()
endmacro()

if("@VCPKG_BUILD_TYPE@" STREQUAL "" OR "@VCPKG_BUILD_TYPE@" STREQUAL "debug")
add_library_config(DEBUG "debug/")
endif()

if("@VCPKG_BUILD_TYPE@" STREQUAL "" OR "@VCPKG_BUILD_TYPE@" STREQUAL "release")
add_library_config(RELEASE "")
endif()

set_and_check(unofficial-libmagic_DICTIONARY "${_IMPORT_PREFIX}/share/libmagic/misc/magic.mgc")

unset(_IMPORT_PREFIX)

check_required_components(unofficial-libmagic)
6 changes: 6 additions & 0 deletions ports/libmagic/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
libmagic provides CMake targets:

find_package(unofficial-libmagic REQUIRED)
target_link_libraries(main PRIVATE unofficial::libmagic::libmagic)

The magic.mgc file can be accessed from the unofficial-libmagic_DICTIONARY variable.
2 changes: 2 additions & 0 deletions ports/libmagic/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "libmagic",
"version": "5.45",
"port-version": 1,
"description": "This library can be used to classify files according to magic number tests.",
"homepage": "https://github.com/file/file",
"license": "BSD-2-Clause",
"dependencies": [
{
"name": "dirent",
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -4498,7 +4498,7 @@
},
"libmagic": {
"baseline": "5.45",
"port-version": 0
"port-version": 1
},
"libmariadb": {
"baseline": "3.3.1",
Expand Down
5 changes: 5 additions & 0 deletions versions/l-/libmagic.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "65715ba20e3afecd46e0fb81326503257174585f",
"version": "5.45",
"port-version": 1
},
{
"git-tree": "30ebcd2ff5522b8c72ba5a5cadd840df34350382",
"version": "5.45",
Expand Down

0 comments on commit 16ee2ec

Please sign in to comment.