[nativefiledialog] Add new port (#7944)

* [nativefiledialog] Add new port

* [nativefiledialog] Use zenity if GTK3 not found

* Add UWP fatal error
This commit is contained in:
myd7349 2019-09-07 05:57:50 +08:00 committed by Griffin Downs
parent 2fb3debcff
commit 8e2f0c7c12
3 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,70 @@
cmake_minimum_required(VERSION 3.14)
project(nfd LANGUAGES C)
include(GNUInstallDirs)
option(NFD_GTK_BACKEND "Using GTK backend" ON)
file(GLOB nfd_sources
"${PROJECT_SOURCE_DIR}/src/*.h"
"${PROJECT_SOURCE_DIR}/src/include/*.h"
"${PROJECT_SOURCE_DIR}/src/nfd_common.c"
)
if (WIN32)
enable_language(CXX)
list(APPEND nfd_sources "${PROJECT_SOURCE_DIR}/src/nfd_win.cpp")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if (NFD_GTK_BACKEND)
find_package(GTK3 QUIET)
if (GTK3_FOUND)
list(APPEND nfd_sources "${PROJECT_SOURCE_DIR}/src/nfd_gtk.c")
else ()
list(APPEND nfd_sources "${PROJECT_SOURCE_DIR}/src/nfd_zenity.c")
endif ()
else ()
list(APPEND nfd_sources "${PROJECT_SOURCE_DIR}/src/nfd_zenity.c")
endif ()
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND nfd_sources "${PROJECT_SOURCE_DIR}/src/nfd_cocoa.m")
endif ()
add_library(nfd ${nfd_sources})
set_target_properties(
nfd
PROPERTIES
DEBUG_POSTFIX "_d"
PUBLIC_HEADER ${CMAKE_CURRENT_LIST_DIR}/src/include/nfd.h
)
target_compile_definitions(
nfd
PRIVATE
$<$<C_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
)
target_include_directories(
nfd
PUBLIC
$<BUILD_INTERFACE:
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/src/include
>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if (GTK3_FOUND)
target_include_directories(nfd PUBLIC ${GTK3_INCLUDE_DIRS})
target_link_libraries(nfd PUBLIC ${GTK3_LIBRARIES})
endif ()
install(TARGETS nfd EXPORT unofficial-nativefiledialog-config)
install(
EXPORT unofficial-nativefiledialog-config
NAMESPACE unofficial::nativefiledialog::
DESTINATION share/unofficial-nativefiledialog
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)

View File

@ -0,0 +1,7 @@
Source: nativefiledialog
Version: 2019-08-28
Description: A tiny, neat C library that portably invokes native file open and save dialogs
Homepage: https://github.com/mlabbe/nativefiledialog
Feature: zenity
Description: Using Zenity backend on Linux

View File

@ -0,0 +1,41 @@
include(vcpkg_common_functions)
if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
message(FATAL_ERROR "${PORT} does not currently support UWP")
endif()
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO mlabbe/nativefiledialog
REF ceb75f7abf30736aa8ee4800cde0d444c798f8b9
SHA512 dd2bff28bb08fb1f6b07ad28530da039f176fb641e300b816040a2b2b840611e418cad44fdaf395ec565c50149ce58c80f88f6a77b403b843f2b14f1f2c91d7d
HEAD_REF master
)
file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
vcpkg_check_features(
OUT_FEATURE_OPTIONS FEATURE_OPTIONS
INVERTED_FEATURES "zenity" NFD_GTK_BACKEND
)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
${FEATURE_OPTIONS}
)
vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-${PORT} TARGET_PATH share/unofficial-${PORT})
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
# Handle copyright
configure_file(${SOURCE_PATH}/LICENSE ${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright COPYONLY)
# CMake integration test
vcpkg_test_cmake(PACKAGE_NAME unofficial-${PORT})