Skip to content

Commit b679d32

Browse files
Copilotjohnpatek
andauthored
Add vcpkg support with megamimes overlay port (#38)
* Initial plan * Add vcpkg support with megamimes overlay port Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com>
1 parent 3b25851 commit b679d32

8 files changed

Lines changed: 179 additions & 37 deletions

File tree

CMakeLists.txt

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,58 +30,89 @@ option(HYPERPAGE_COVER "Enable code coverage" OFF)
3030
option(HYPERPAGE_EXAMPLE "Build example" OFF)
3131
option(HYPERPAGE_DOCS "Build documentation" OFF)
3232

33-
include(FetchContent)
34-
FetchContent_Declare(
35-
MegaMimes
36-
GIT_REPOSITORY https://github.com/kobbyowen/MegaMimes.git
37-
GIT_TAG b839068db99cbfcff1af8df1229bd7e41701fe96
38-
)
39-
FetchContent_MakeAvailable(MegaMimes)
33+
# Check if CMAKE_TOOLCHAIN_FILE is set
34+
if(DEFINED CMAKE_TOOLCHAIN_FILE)
35+
message(STATUS "CMAKE_TOOLCHAIN_FILE is set to: ${CMAKE_TOOLCHAIN_FILE}")
36+
37+
# Check if the path points to the vcpkg toolchain file
38+
if("${CMAKE_TOOLCHAIN_FILE}" MATCHES ".*[/\\]scripts[/\\]buildsystems[/\\]vcpkg.cmake$")
39+
message(STATUS "vcpkg toolchain file detected via path matching.")
40+
set(VCPKG_TOOLCHAIN_ACTIVE TRUE)
41+
endif()
42+
endif()
4043

41-
FetchContent_Declare(
42-
sqlite3
43-
GIT_REPOSITORY https://github.com/sjinks/sqlite3-cmake.git
44-
GIT_TAG master
45-
)
46-
FetchContent_MakeAvailable(sqlite3)
44+
if(VCPKG_TOOLCHAIN_ACTIVE)
45+
find_package(megamimes CONFIG REQUIRED)
46+
find_package(unofficial-sqlite3 CONFIG REQUIRED)
47+
find_package(argparse CONFIG REQUIRED)
48+
find_package(mio CONFIG REQUIRED)
49+
50+
set(HYPERPAGE_EXTRA_SOURCES "")
51+
set(HYPERPAGE_PRIVATE_INCLUDES "")
52+
set(HYPERPAGE_SQLITE_TARGET unofficial::sqlite3::sqlite3)
53+
else()
54+
include(FetchContent)
55+
FetchContent_Declare(
56+
MegaMimes
57+
GIT_REPOSITORY https://github.com/kobbyowen/MegaMimes.git
58+
GIT_TAG b839068db99cbfcff1af8df1229bd7e41701fe96
59+
)
60+
FetchContent_MakeAvailable(MegaMimes)
4761

48-
FetchContent_Declare(
49-
argparse
50-
GIT_REPOSITORY https://github.com/p-ranav/argparse.git
51-
GIT_TAG master
52-
)
53-
FetchContent_MakeAvailable(argparse)
54-
FetchContent_Declare(
55-
mio
56-
GIT_REPOSITORY https://github.com/maxtek6/mio.git
57-
GIT_TAG master
58-
)
59-
FetchContent_MakeAvailable(mio)
62+
FetchContent_Declare(
63+
sqlite3
64+
GIT_REPOSITORY https://github.com/sjinks/sqlite3-cmake.git
65+
GIT_TAG master
66+
)
67+
FetchContent_MakeAvailable(sqlite3)
68+
69+
FetchContent_Declare(
70+
argparse
71+
GIT_REPOSITORY https://github.com/p-ranav/argparse.git
72+
GIT_TAG master
73+
)
74+
FetchContent_MakeAvailable(argparse)
75+
76+
FetchContent_Declare(
77+
mio
78+
GIT_REPOSITORY https://github.com/maxtek6/mio.git
79+
GIT_TAG master
80+
)
81+
FetchContent_MakeAvailable(mio)
82+
83+
set(HYPERPAGE_EXTRA_SOURCES ${megamimes_SOURCE_DIR}/src/MegaMimes.c)
84+
set(HYPERPAGE_PRIVATE_INCLUDES ${megamimes_SOURCE_DIR}/src)
85+
set(HYPERPAGE_SQLITE_TARGET SQLite::SQLite3)
86+
endif()
6087

6188
add_library(
62-
hyperpage
89+
hyperpage
6390
STATIC
6491
${CMAKE_CURRENT_SOURCE_DIR}/hyperpage.cpp
65-
${megamimes_SOURCE_DIR}/src/MegaMimes.c
92+
${HYPERPAGE_EXTRA_SOURCES}
6693
)
6794

6895
target_include_directories(
69-
hyperpage
70-
PUBLIC
96+
hyperpage
97+
PUBLIC
7198
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
7299
$<INSTALL_INTERFACE:include>
73100
PRIVATE
74-
${megamimes_SOURCE_DIR}/src)
101+
${HYPERPAGE_PRIVATE_INCLUDES}
102+
)
75103

76-
target_link_libraries(hyperpage PUBLIC SQLite::SQLite3)
104+
target_link_libraries(hyperpage PUBLIC ${HYPERPAGE_SQLITE_TARGET})
105+
if(VCPKG_TOOLCHAIN_ACTIVE)
106+
target_link_libraries(hyperpage PUBLIC megamimes::megamimes)
107+
endif()
77108

78109
set_target_properties(hyperpage PROPERTIES
79110
PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/hyperpage.hpp"
80111
)
81112

82113
add_executable(hyperpack ${CMAKE_CURRENT_SOURCE_DIR}/hyperpack.cpp)
83114
target_include_directories(hyperpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
84-
target_link_libraries(hyperpack PRIVATE argparse hyperpage mio::mio)
115+
target_link_libraries(hyperpack PRIVATE argparse::argparse hyperpage mio::mio)
85116

86117

87118
# CMake function for creating hyperpack archives

ports/megamimes/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(megamimes VERSION 1.0.0 LANGUAGES C)
3+
4+
include(GNUInstallDirs)
5+
include(CMakePackageConfigHelpers)
6+
7+
add_library(megamimes STATIC src/MegaMimes.c)
8+
add_library(megamimes::megamimes ALIAS megamimes)
9+
10+
target_include_directories(megamimes
11+
PUBLIC
12+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
13+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
14+
)
15+
16+
install(TARGETS megamimes
17+
EXPORT megamimes-targets
18+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
19+
)
20+
21+
install(FILES src/MegaMimes.h
22+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
23+
)
24+
25+
install(EXPORT megamimes-targets
26+
FILE megamimes-targets.cmake
27+
NAMESPACE megamimes::
28+
DESTINATION share/cmake/megamimes
29+
)
30+
31+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/megamimes-config.cmake"
32+
"include(\"\${CMAKE_CURRENT_LIST_DIR}/megamimes-targets.cmake\")\n"
33+
)
34+
35+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/megamimes-config.cmake"
36+
DESTINATION share/cmake/megamimes
37+
)

ports/megamimes/portfile.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
vcpkg_from_github(
2+
OUT_SOURCE_PATH SOURCE_PATH
3+
REPO kobbyowen/MegaMimes
4+
REF b839068db99cbfcff1af8df1229bd7e41701fe96
5+
SHA512 1581ddb6e85929ce7ec1e97578ad77fadd3f6ac82a1e4a379772dfa90b048a9c508059cc63525feef73a7a08e8553789830ef48e28ebc0e6a1123f1b0fb69889
6+
HEAD_REF master
7+
)
8+
9+
# MegaMimes does not include a CMakeLists.txt, so provide one
10+
file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
11+
12+
vcpkg_cmake_configure(
13+
SOURCE_PATH "${SOURCE_PATH}"
14+
)
15+
16+
vcpkg_cmake_install()
17+
18+
vcpkg_cmake_config_fixup(CONFIG_PATH share/cmake/megamimes)
19+
20+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
21+
22+
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

ports/megamimes/usage

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The package megamimes provides CMake targets:
2+
3+
find_package(megamimes CONFIG REQUIRED)
4+
target_link_libraries(main PRIVATE megamimes::megamimes)

ports/megamimes/vcpkg.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "megamimes",
3+
"version-date": "2021-12-01",
4+
"description": "A simple C library to get MIME type information about a file",
5+
"homepage": "https://github.com/kobbyowen/MegaMimes",
6+
"license": "MIT",
7+
"dependencies": [
8+
{
9+
"name": "vcpkg-cmake",
10+
"host": true
11+
},
12+
{
13+
"name": "vcpkg-cmake-config",
14+
"host": true
15+
}
16+
]
17+
}

tests/CMakeLists.txt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,39 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21+
include(FetchContent)
22+
2123
FetchContent_Declare(
2224
Maxtest
2325
GIT_REPOSITORY https://github.com/maxtek6/maxtest.git
2426
GIT_TAG master
2527
)
2628
FetchContent_MakeAvailable(Maxtest)
2729

30+
if(VCPKG_TOOLCHAIN_ACTIVE)
31+
set(HYPERTEST_EXTRA_SOURCES "")
32+
set(HYPERTEST_EXTRA_INCLUDES "")
33+
set(HYPERTEST_SQLITE_TARGET unofficial::sqlite3::sqlite3)
34+
else()
35+
set(HYPERTEST_EXTRA_SOURCES ${megamimes_SOURCE_DIR}/src/MegaMimes.c)
36+
set(HYPERTEST_EXTRA_INCLUDES ${megamimes_SOURCE_DIR}/src)
37+
set(HYPERTEST_SQLITE_TARGET SQLite::SQLite3)
38+
endif()
39+
2840
maxtest_add_executable(
2941
unit ${CMAKE_CURRENT_SOURCE_DIR}/unit.cpp
3042
${CMAKE_CURRENT_SOURCE_DIR}/../hyperpage.cpp
31-
${megamimes_SOURCE_DIR}/src/MegaMimes.c)
43+
${HYPERTEST_EXTRA_SOURCES})
3244

33-
target_include_directories(unit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ ${megamimes_SOURCE_DIR}/src)
45+
target_include_directories(unit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ ${HYPERTEST_EXTRA_INCLUDES})
3446

3547
if(HYPERPAGE_COVER)
3648
if(WIN32)
3749
message("skipping code coverage for windows")
38-
target_link_libraries(unit PRIVATE SQLite::SQLite3)
50+
target_link_libraries(unit PRIVATE ${HYPERTEST_SQLITE_TARGET})
3951
else()
4052
target_compile_options(unit PRIVATE -fprofile-arcs -ftest-coverage -g -O0)
41-
target_link_libraries(unit PRIVATE SQLite::SQLite3 gcov "--coverage")
53+
target_link_libraries(unit PRIVATE ${HYPERTEST_SQLITE_TARGET} gcov "--coverage")
4254
add_custom_target(
4355
cover
4456
DEPENDS unit)
@@ -47,7 +59,11 @@ if(HYPERPAGE_COVER)
4759
COMMAND gcovr -r ${CMAKE_CURRENT_SOURCE_DIR}/.. -e ${CMAKE_CURRENT_SOURCE_DIR})
4860
endif()
4961
else()
50-
target_link_libraries(unit PRIVATE SQLite::SQLite3)
62+
target_link_libraries(unit PRIVATE ${HYPERTEST_SQLITE_TARGET})
63+
endif()
64+
65+
if(VCPKG_TOOLCHAIN_ACTIVE)
66+
target_link_libraries(unit PRIVATE megamimes::megamimes)
5167
endif()
5268

5369
maxtest_add_test(unit store_load $<TARGET_FILE_DIR:unit>)

vcpkg-configuration.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"overlay-ports": [
3+
"./ports"
4+
]
5+
}

vcpkg.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "hyperpage",
3+
"version": "1.0.0",
4+
"dependencies": [
5+
"argparse",
6+
"megamimes",
7+
"mio",
8+
"sqlite3"
9+
]
10+
}

0 commit comments

Comments
 (0)