aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/portable-snippets/CMakeLists.txt96
-rw-r--r--ports/portable-snippets/CONTROL4
-rw-r--r--ports/portable-snippets/portfile.cmake32
3 files changed, 132 insertions, 0 deletions
diff --git a/ports/portable-snippets/CMakeLists.txt b/ports/portable-snippets/CMakeLists.txt
new file mode 100644
index 000000000..5f511265a
--- /dev/null
+++ b/ports/portable-snippets/CMakeLists.txt
@@ -0,0 +1,96 @@
+cmake_minimum_required(VERSION 3.14)
+
+project(portable-snippets LANGUAGES C)
+
+include(GNUInstallDirs)
+
+option(PSNIP_INSTALL_HEADERS "Install header files" ON)
+
+# https://stackoverflow.com/questions/7787823/cmake-how-to-get-the-name-of-all-subdirectories-of-a-directory
+function (list_subdir output_variable path)
+ file(GLOB sub_entries RELATIVE ${path} ${path}/*)
+
+ set(dirlist "")
+
+ foreach (entry ${sub_entries})
+ if (IS_DIRECTORY ${path}/${entry})
+ list(APPEND dirlist ${entry})
+ endif ()
+ endforeach ()
+
+ set(${output_variable} ${dirlist} PARENT_SCOPE)
+endfunction ()
+
+function (check_if_header_only output_variable files)
+ set(is_header_only 1)
+
+ foreach (entry ${files})
+ get_filename_component(file_ext ${entry} EXT)
+ if (file_ext STREQUAL .c)
+ set(is_header_only 0)
+ endif ()
+ endforeach ()
+
+ set(${output_variable} ${is_header_only} PARENT_SCOPE)
+endfunction ()
+
+list_subdir(subdirs ${CMAKE_CURRENT_LIST_DIR})
+list(REMOVE_ITEM subdirs tests)
+
+set(namespace unofficial::portable-snippets)
+
+foreach (subdir ${subdirs})
+ set(module ${subdir})
+ set(module_path "${CMAKE_CURRENT_LIST_DIR}/${subdir}")
+
+ file(GLOB entries
+ LIST_DIRECTORIES false
+ ${module_path}/*.h
+ ${module_path}/*.c
+ )
+
+ check_if_header_only(header_only "${entries}")
+
+ if (header_only)
+ add_library(${module} INTERFACE)
+
+ target_include_directories(
+ ${module}
+ INTERFACE
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+ )
+ else ()
+ add_library(${module} STATIC ${entries})
+
+ set_target_properties(
+ ${module}
+ PROPERTIES
+ PREFIX ""
+ OUTPUT_NAME "psnip-${module}"
+ )
+
+ target_include_directories(
+ ${module}
+ PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+ )
+
+ list(FILTER entries EXCLUDE REGEX "\.c$")
+ endif ()
+
+ add_library(${namespace}::${module} ALIAS ${module})
+
+ if (PSNIP_INSTALL_HEADERS)
+ install(FILES ${entries} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${subdir})
+ endif ()
+
+ install(TARGETS ${module} EXPORT unofficial-portable-snippets-config)
+endforeach ()
+
+install(
+ EXPORT unofficial-portable-snippets-config
+ NAMESPACE ${namespace}::
+ DESTINATION share/unofficial-portable-snippets
+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+)
diff --git a/ports/portable-snippets/CONTROL b/ports/portable-snippets/CONTROL
new file mode 100644
index 000000000..792cb9fc9
--- /dev/null
+++ b/ports/portable-snippets/CONTROL
@@ -0,0 +1,4 @@
+Source: portable-snippets
+Version: 2019-09-20
+Description: Collection of miscellaneous portable C snippets
+Homepage: https://github.com/nemequ/portable-snippets
diff --git a/ports/portable-snippets/portfile.cmake b/ports/portable-snippets/portfile.cmake
new file mode 100644
index 000000000..c84aca26b
--- /dev/null
+++ b/ports/portable-snippets/portfile.cmake
@@ -0,0 +1,32 @@
+include(vcpkg_common_functions)
+
+vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
+
+vcpkg_from_github(
+ OUT_SOURCE_PATH SOURCE_PATH
+ REPO nemequ/portable-snippets
+ REF 26496acb37ab46ee249ea19d45381da6955d89c4
+ SHA512 6213b22e4358b06f92396731d94fd27d4cf3568a47c56c057174c1839929c6a569ad5b1e1302fe0d092c4f393c570607b96e9e977223f86a9e3c2862010f3af0
+ HEAD_REF master
+)
+
+file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
+
+vcpkg_configure_cmake(
+ SOURCE_PATH ${SOURCE_PATH}
+ PREFER_NINJA
+ OPTIONS_DEBUG
+ -DPSNIP_INSTALL_HEADERS=OFF
+ OPTIONS_RELEASE
+ -DPSNIP_INSTALL_HEADERS=ON
+)
+
+vcpkg_install_cmake()
+
+vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-${PORT} TARGET_PATH share/unofficial-${PORT})
+
+# Handle copyright
+configure_file(${SOURCE_PATH}/COPYING.md ${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright COPYONLY)
+
+# CMake integration test
+vcpkg_test_cmake(PACKAGE_NAME unofficial-${PORT})