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

Support cross-compiling in the libmagic vcpkg port overlay. #5333

Merged
merged 1 commit into from
Oct 3, 2024
Merged
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
3 changes: 2 additions & 1 deletion ports/libmagic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unset(CONFIGURE_AC_CONTENT)
project(file VERSION ${CMAKE_MATCH_1})

option(FILE_TESTS "Enable file tests" OFF)
set(FILE_COMMAND "file" CACHE PATH "Path to the file command to generate magic.mgc. Should be set for cross-compiling scenarios.")

# Get library directory for multiarch linux distros
include(GNUInstallDirs)
Expand Down Expand Up @@ -133,7 +134,7 @@ foreach(MAGIC_FRAGMENT ${MAGIC_FRAGMENTS})
endforeach()

add_custom_command(OUTPUT magic.mgc
COMMAND file -C -m magic
COMMAND ${FILE_COMMAND} -C -m magic
COMMENT "Compiling magic file"
)

Expand Down
16 changes: 9 additions & 7 deletions ports/libmagic/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ file(COPY "${CMAKE_CURRENT_LIST_DIR}/unofficial-libmagic-config.cmake.in" DESTIN
file(COPY "${CMAKE_CURRENT_LIST_DIR}/magic.def" DESTINATION "${SOURCE_PATH}/src")
file(COPY "${CMAKE_CURRENT_LIST_DIR}/config.h" DESTINATION "${SOURCE_PATH}/src")

if(VCPKG_CROSSCOMPILING)
set(FILE_COMMAND_OPT "-DFILE_COMMAND=${CURRENT_HOST_INSTALLED_DIR}/tools/libmagic/file${VCPKG_HOST_EXECUTABLE_SUFFIX}")
elseif(VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
set(EXTRA_ARGS "ADD_BIN_TO_PATH")
endif()

vcpkg_cmake_configure(
SOURCE_PATH ${SOURCE_PATH}
OPTIONS
${FILE_COMMAND_OPT}
)

vcpkg_cmake_install()
vcpkg_cmake_install(${EXTRA_ARGS})
vcpkg_copy_pdbs()
vcpkg_fixup_pkgconfig()
vcpkg_copy_tools(TOOL_NAMES file AUTO_CLEAN)
Expand All @@ -47,12 +55,6 @@ 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")

if(VCPKG_CROSSCOMPILING)
vcpkg_add_to_path(PREPEND "${CURRENT_HOST_INSTALLED_DIR}/tools/libmagic/bin")
elseif(VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
set(EXTRA_ARGS "ADD_BIN_TO_PATH")
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
endif()
Expand Down
4 changes: 4 additions & 0 deletions ports/libmagic/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"description": "This library can be used to classify files according to magic number tests.",
"homepage": "https://github.com/file/file",
"dependencies": [
{
"name": "libmagic",
"host": true
},
{
"name": "vcpkg-cmake",
"host": true
Expand Down
Loading