diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 08ab0ae..cf96c5c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,25 +1,46 @@ name: CMake -on: [push, pull_request] +on: + push: + pull_request: jobs: build: + # Skip building pull requests from the same repository + if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }} runs-on: ${{ matrix.os }} strategy: - fail-fast: true + fail-fast: false matrix: - os: [windows-2019, macos-10.15, ubuntu-20.04] + os: [windows-latest, macos-latest, ubuntu-latest] env: - BUILD_TYPE: Release + BUILD_TYPE: "Release" + CMAKE_GENERATOR: "Ninja" + VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" + steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - name: Compile with gcc 10 on ubuntu - if: ${{ matrix.os == 'ubuntu-20.04' }} - run: | - echo "CC=gcc-10" >> $GITHUB_ENV - echo "CXX=g++-10" >> $GITHUB_ENV - - name: Build + - name: Checkout + uses: actions/checkout@v4 + + # Reference: https://learn.microsoft.com/en-us/vcpkg/consume/binary-caching-github-actions-cache + - name: Export GitHub Actions cache environment variables + uses: actions/github-script@v7 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + + - name: Install Ninja + uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # v5 + + - name: Visual Studio Development Environment + uses: ilammy/msvc-dev-cmd@cec98b9d092141f74527d0afa6feb2af698cfe89 # v1.12.1 + + - name: CMake Build run: | - cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} + cmake -B build "-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}" cmake --build build --config ${{ env.BUILD_TYPE }} --parallel + + - name: Run Tests + run: | + build/example diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index 198eaed..0000000 --- a/.gitpod.yml +++ /dev/null @@ -1,26 +0,0 @@ -tasks: - - command: gp open "$GITPOD_REPO_ROOT/cmake.toml" - - command: gp open "$GITPOD_REPO_ROOT/src/main.cpp" - -github: - prebuilds: - # enable for the master/default branch (defaults to true) - master: true - # enable for all branches in this repo (defaults to false) - branches: true - # enable for pull requests coming from this repo (defaults to true) - pullRequests: false - # enable for pull requests coming from forks (defaults to false) - pullRequestsFromForks: false - # add a "Review in Gitpod" button as a comment to pull requests (defaults to true) - addComment: false - # add a "Review in Gitpod" button to pull requests (defaults to false) - addBadge: false - # add a label once the prebuild is ready to pull requests (defaults to false) - addLabel: prebuilt-in-gitpod - -vscode: - extensions: - - ms-vscode.cmake-tools - - bungcip.better-toml - - llvm-vs-code-extensions.vscode-clangd diff --git a/CMakeLists.txt b/CMakeLists.txt index 918a977..fe31e05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,72 +3,86 @@ cmake_minimum_required(VERSION 3.15) -# Regenerate CMakeLists.txt automatically in the root project +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build") +endif() + set(CMKR_ROOT_PROJECT OFF) if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(CMKR_ROOT_PROJECT ON) - # Bootstrap cmkr - include("cmake/cmkr.cmake" OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT) + # Bootstrap cmkr and automatically regenerate CMakeLists.txt + include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT) if(CMKR_INCLUDE_RESULT) cmkr() endif() # Enable folder support set_property(GLOBAL PROPERTY USE_FOLDERS ON) -endif() -# Create a configure-time dependency on cmake.toml to improve IDE support -if(CMKR_ROOT_PROJECT) - configure_file(cmake.toml cmake.toml COPYONLY) + # Create a configure-time dependency on cmake.toml to improve IDE support + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS cmake.toml) endif() +# vcpkg settings +set(VCPKG_OVERLAY_PORTS + "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg-overlay" +) +set(VCPKG_OVERLAY_TRIPLETS + "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg-overlay" +) project(vcpkg_template) if(CMKR_ROOT_PROJECT AND NOT CMKR_DISABLE_VCPKG) include(FetchContent) - message(STATUS "Fetching vcpkg...") - FetchContent_Declare(vcpkg URL "https://github.com/microsoft/vcpkg/archive/refs/tags/2021.05.12.tar.gz") + # Fix warnings about DOWNLOAD_EXTRACT_TIMESTAMP + if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) + endif() + message(STATUS "Fetching vcpkg (2024.11.16)...") + FetchContent_Declare(vcpkg + URL + "https://github.com/microsoft/vcpkg/archive/refs/tags/2024.11.16.tar.gz" + SUBBUILD_DIR + "CMakeFiles/vcpkg-subbuild" + SOURCE_DIR + vcpkg + BINARY_DIR + "CMakeFiles/vcpkg-build" + ) FetchContent_MakeAvailable(vcpkg) + + if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin AND CMAKE_OSX_ARCHITECTURES STREQUAL "") + set(CMAKE_OSX_ARCHITECTURES ${CMAKE_HOST_SYSTEM_PROCESSOR} CACHE STRING "" FORCE) + endif() include("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake") endif() # Packages -find_package(fmt REQUIRED CONFIG) - -find_package(unofficial-sqlite3 REQUIRED CONFIG) +find_package(fmt REQUIRED) -# Target example -set(CMKR_TARGET example) -set(example_SOURCES "") +find_package(unofficial-sqlite3 REQUIRED) -list(APPEND example_SOURCES - "src/main.cpp" -) +find_package(unofficial-mylib REQUIRED) -list(APPEND example_SOURCES +# Target: example +set(example_SOURCES cmake.toml + "src/main.cpp" ) -set(CMKR_SOURCES ${example_SOURCES}) add_executable(example) -if(example_SOURCES) - target_sources(example PRIVATE ${example_SOURCES}) -endif() - -get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT) -if(NOT CMKR_VS_STARTUP_PROJECT) - set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT example) -endif() - +target_sources(example PRIVATE ${example_SOURCES}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${example_SOURCES}) target_link_libraries(example PRIVATE fmt::fmt unofficial::sqlite3::sqlite3 + unofficial::mylib::mylib ) -unset(CMKR_TARGET) -unset(CMKR_SOURCES) - +get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT) +if(NOT CMKR_VS_STARTUP_PROJECT) + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT example) +endif() diff --git a/README.md b/README.md index 056ebf0..e7d7e2c 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,64 @@ -[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/from-referrer/) - # vcpkg_template This is a template showcasing [cmkr](https://github.com/build-cpp/cmkr) together with [vcpkg](https://github.com/microsoft/vcpkg) for frictionless cross platform dependency management with CMake. -## Building (IDE) - -Clone this repository and open it in your favorite IDE with CMake support (Visual Studio, CLion, Qt Creator). Everything should work out of the box. +## Building -## Building (command line) +Use the following commands to build the project: ``` -cmake -Bbuild +cmake -B build +cmake --build build ``` -Then open the `.sln` (Windows) or run `make` (Unix) from the `build` directory. - ## cmake.toml Under the hood cmkr generates the `CMakeLists.txt` required to build this project from the `cmake.toml` file: ```toml -[cmake] -version = "3.15" -cmkr-include = "cmake/cmkr.cmake" - [project] name = "vcpkg_template" -# See https://vcpkg.io/en/packages.html for available packages +# See https://vcpkg.link for available packages # Chose a version from https://github.com/microsoft/vcpkg/releases [vcpkg] -version = "2021.05.12" -packages = ["fmt", "sqlite3"] +version = "2024.11.16" +packages = [ + "fmt", + "sqlite3", + "mylib", +] +overlay = "vcpkg-overlay" -[find-package] -fmt = { version = "*" } -unofficial-sqlite3 = { version = "*" } +# Make the packages available to CMake +[find-package.fmt] +[find-package.unofficial-sqlite3] +[find-package.unofficial-mylib] [target.example] type = "executable" sources = ["src/main.cpp"] -link-libraries = ["fmt::fmt", "unofficial::sqlite3::sqlite3"] +link-libraries = [ + "fmt::fmt", + "unofficial::sqlite3::sqlite3", + "unofficial::mylib::mylib", +] +``` + +## Vcpkg overlay + +The `[vcpkg].overlay` key points to a local folder used as an overlay for vcpkg ports and triplets: + +```sh +vcpkg-overlay +├── mylib # custom port +│ ├── CMakeLists.txt +│ ├── portfile.cmake +│ ├── usage +│ └── vcpkg.json +└── x64-windows.cmake # custom triplet ``` + +The `vcpkg-overlay/mylib` [overlay port](https://learn.microsoft.com/en-us/vcpkg/concepts/overlay-ports) is used to make the example [mylib](https://gitlab.com/mrexodia/mylib) available without having to fork the vcpkg repository or create a custom registry. + +The `vcpkg-overlay/x64-windows.cmake` [overlay triplet](https://learn.microsoft.com/en-us/vcpkg/users/examples/overlay-triplets-linux-dynamic) is used to always build static libraries for Windows (instead of shared libraries, which is normally the default). diff --git a/cmake.toml b/cmake.toml index 1b84c2a..652f027 100644 --- a/cmake.toml +++ b/cmake.toml @@ -1,21 +1,27 @@ -[cmake] -version = "3.15" -cmkr-include = "cmake/cmkr.cmake" - [project] name = "vcpkg_template" -# See https://vcpkg.io/en/packages.html for available packages +# See https://vcpkg.link for available packages # Chose a version from https://github.com/microsoft/vcpkg/releases [vcpkg] -version = "2021.05.12" -packages = ["fmt", "sqlite3"] +version = "2024.11.16" +packages = [ + "fmt", + "sqlite3", + "mylib", +] +overlay = "vcpkg-overlay" -[find-package] -fmt = { version = "*" } -unofficial-sqlite3 = { version = "*" } +# Make the packages available to CMake +[find-package.fmt] +[find-package.unofficial-sqlite3] +[find-package.unofficial-mylib] [target.example] type = "executable" sources = ["src/main.cpp"] -link-libraries = ["fmt::fmt", "unofficial::sqlite3::sqlite3"] \ No newline at end of file +link-libraries = [ + "fmt::fmt", + "unofficial::sqlite3::sqlite3", + "unofficial::mylib::mylib", +] diff --git a/cmake/cmkr.cmake b/cmkr.cmake similarity index 52% rename from cmake/cmkr.cmake rename to cmkr.cmake index 3e4b540..55dac02 100644 --- a/cmake/cmkr.cmake +++ b/cmkr.cmake @@ -2,22 +2,33 @@ include_guard() # Change these defaults to point to your infrastructure if desired set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE) -set(CMKR_TAG "archive_760b2a85" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) +set(CMKR_TAG "v0.2.43" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) +set(CMKR_COMMIT_HASH "" CACHE STRING "cmkr git commit hash (optional)" FORCE) + +# To bootstrap/generate a cmkr project: cmake -P cmkr.cmake +if(CMAKE_SCRIPT_MODE_FILE) + set(CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}/build") + set(CMAKE_CURRENT_BINARY_DIR "${CMAKE_BINARY_DIR}") + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}") +endif() # Set these from the command line to customize for development/debugging purposes set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable") set(CMKR_SKIP_GENERATION OFF CACHE BOOL "skip automatic cmkr generation") +set(CMKR_BUILD_TYPE "Debug" CACHE STRING "cmkr build configuration") +mark_as_advanced(CMKR_REPO CMKR_TAG CMKR_COMMIT_HASH CMKR_EXECUTABLE CMKR_SKIP_GENERATION CMKR_BUILD_TYPE) # Disable cmkr if generation is disabled -if(DEFINED ENV{CI} OR CMKR_SKIP_GENERATION) +if(DEFINED ENV{CI} OR CMKR_SKIP_GENERATION OR CMKR_BUILD_SKIP_GENERATION) message(STATUS "[cmkr] Skipping automatic cmkr generation") + unset(CMKR_BUILD_SKIP_GENERATION CACHE) macro(cmkr) endmacro() return() endif() # Disable cmkr if no cmake.toml file is found -if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake.toml") +if(NOT CMAKE_SCRIPT_MODE_FILE AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake.toml") message(AUTHOR_WARNING "[cmkr] Not found: ${CMAKE_CURRENT_SOURCE_DIR}/cmake.toml") macro(cmkr) endmacro() @@ -47,22 +58,68 @@ else() endif() # Use cached cmkr if found -set(CMKR_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_cmkr_${CMKR_TAG}") +if(DEFINED ENV{CMKR_CACHE}) + set(CMKR_DIRECTORY_PREFIX "$ENV{CMKR_CACHE}") + string(REPLACE "\\" "/" CMKR_DIRECTORY_PREFIX "${CMKR_DIRECTORY_PREFIX}") + if(NOT CMKR_DIRECTORY_PREFIX MATCHES "\\/$") + set(CMKR_DIRECTORY_PREFIX "${CMKR_DIRECTORY_PREFIX}/") + endif() + # Build in release mode for the cache + set(CMKR_BUILD_TYPE "Release") +else() + set(CMKR_DIRECTORY_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/_cmkr_") +endif() +set(CMKR_DIRECTORY "${CMKR_DIRECTORY_PREFIX}${CMKR_TAG}") set(CMKR_CACHED_EXECUTABLE "${CMKR_DIRECTORY}/bin/${CMKR_EXECUTABLE_NAME}") -if(NOT CMKR_CACHED_EXECUTABLE STREQUAL CMKR_EXECUTABLE AND CMKR_EXECUTABLE MATCHES "^${CMAKE_CURRENT_BINARY_DIR}/_cmkr") - message(AUTHOR_WARNING "[cmkr] Upgrading '${CMKR_EXECUTABLE}' to '${CMKR_CACHED_EXECUTABLE}'") - unset(CMKR_EXECUTABLE CACHE) +# Helper function to check if a string starts with a prefix +# Cannot use MATCHES, see: https://github.com/build-cpp/cmkr/issues/61 +function(cmkr_startswith str prefix result) + string(LENGTH "${prefix}" prefix_length) + string(LENGTH "${str}" str_length) + if(prefix_length LESS_EQUAL str_length) + string(SUBSTRING "${str}" 0 ${prefix_length} str_prefix) + if(prefix STREQUAL str_prefix) + set("${result}" ON PARENT_SCOPE) + return() + endif() + endif() + set("${result}" OFF PARENT_SCOPE) +endfunction() + +# Handle upgrading logic +if(CMKR_EXECUTABLE AND NOT CMKR_CACHED_EXECUTABLE STREQUAL CMKR_EXECUTABLE) + cmkr_startswith("${CMKR_EXECUTABLE}" "${CMAKE_CURRENT_BINARY_DIR}/_cmkr" CMKR_STARTSWITH_BUILD) + cmkr_startswith("${CMKR_EXECUTABLE}" "${CMKR_DIRECTORY_PREFIX}" CMKR_STARTSWITH_CACHE) + if(CMKR_STARTSWITH_BUILD) + if(DEFINED ENV{CMKR_CACHE}) + message(AUTHOR_WARNING "[cmkr] Switching to cached cmkr: '${CMKR_CACHED_EXECUTABLE}'") + if(EXISTS "${CMKR_CACHED_EXECUTABLE}") + set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE) + else() + unset(CMKR_EXECUTABLE CACHE) + endif() + else() + message(AUTHOR_WARNING "[cmkr] Upgrading '${CMKR_EXECUTABLE}' to '${CMKR_CACHED_EXECUTABLE}'") + unset(CMKR_EXECUTABLE CACHE) + endif() + elseif(DEFINED ENV{CMKR_CACHE} AND CMKR_STARTSWITH_CACHE) + message(AUTHOR_WARNING "[cmkr] Upgrading cached '${CMKR_EXECUTABLE}' to '${CMKR_CACHED_EXECUTABLE}'") + unset(CMKR_EXECUTABLE CACHE) + endif() endif() if(CMKR_EXECUTABLE AND EXISTS "${CMKR_EXECUTABLE}") message(VERBOSE "[cmkr] Found cmkr: '${CMKR_EXECUTABLE}'") elseif(CMKR_EXECUTABLE AND NOT CMKR_EXECUTABLE STREQUAL CMKR_CACHED_EXECUTABLE) message(FATAL_ERROR "[cmkr] '${CMKR_EXECUTABLE}' not found") +elseif(NOT CMKR_EXECUTABLE AND EXISTS "${CMKR_CACHED_EXECUTABLE}") + set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE) + message(STATUS "[cmkr] Found cached cmkr: '${CMKR_EXECUTABLE}'") else() set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE) message(VERBOSE "[cmkr] Bootstrapping '${CMKR_EXECUTABLE}'") - + message(STATUS "[cmkr] Fetching cmkr...") if(EXISTS "${CMKR_DIRECTORY}") cmkr_exec("${CMAKE_COMMAND}" -E rm -rf "${CMKR_DIRECTORY}") @@ -76,23 +133,34 @@ else() ${CMKR_REPO} "${CMKR_DIRECTORY}" ) - message(STATUS "[cmkr] Building cmkr...") + if(CMKR_COMMIT_HASH) + execute_process( + COMMAND "${GIT_EXECUTABLE}" checkout -q "${CMKR_COMMIT_HASH}" + RESULT_VARIABLE CMKR_EXEC_RESULT + WORKING_DIRECTORY "${CMKR_DIRECTORY}" + ) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "Tag '${CMKR_TAG}' hash is not '${CMKR_COMMIT_HASH}'") + endif() + endif() + message(STATUS "[cmkr] Building cmkr (using system compiler)...") cmkr_exec("${CMAKE_COMMAND}" --no-warn-unused-cli "${CMKR_DIRECTORY}" "-B${CMKR_DIRECTORY}/build" - "-DCMAKE_BUILD_TYPE=Release" + "-DCMAKE_BUILD_TYPE=${CMKR_BUILD_TYPE}" + "-DCMAKE_UNITY_BUILD=ON" "-DCMAKE_INSTALL_PREFIX=${CMKR_DIRECTORY}" "-DCMKR_GENERATE_DOCUMENTATION=OFF" ) cmkr_exec("${CMAKE_COMMAND}" --build "${CMKR_DIRECTORY}/build" - --config Release + --config "${CMKR_BUILD_TYPE}" --parallel ) cmkr_exec("${CMAKE_COMMAND}" --install "${CMKR_DIRECTORY}/build" - --config Release + --config "${CMKR_BUILD_TYPE}" --prefix "${CMKR_DIRECTORY}" --component cmkr ) @@ -109,6 +177,29 @@ if(NOT CMKR_EXEC_RESULT EQUAL 0) message(FATAL_ERROR "[cmkr] Failed to get version, try clearing the cache and rebuilding") endif() +# Use cmkr.cmake as a script +if(CMAKE_SCRIPT_MODE_FILE) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake.toml") + execute_process(COMMAND "${CMKR_EXECUTABLE}" init + RESULT_VARIABLE CMKR_EXEC_RESULT + ) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "[cmkr] Failed to bootstrap cmkr project. Please report an issue: https://github.com/build-cpp/cmkr/issues/new") + else() + message(STATUS "[cmkr] Modify cmake.toml and then configure using: cmake -B build") + endif() + else() + execute_process(COMMAND "${CMKR_EXECUTABLE}" gen + RESULT_VARIABLE CMKR_EXEC_RESULT + ) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "[cmkr] Failed to generate project.") + else() + message(STATUS "[cmkr] Configure using: cmake -B build") + endif() + endif() +endif() + # This is the macro that contains black magic macro(cmkr) # When this macro is called from the generated file, fake some internal CMake variables @@ -142,21 +233,21 @@ macro(cmkr) # Copy the now-generated CMakeLists.txt to CMakerLists.txt # This is done because you cannot include() a file you are currently in configure_file(CMakeLists.txt "${CMKR_TEMP_FILE}" COPYONLY) - + # Add the macro required for the hack at the start of the cmkr macro set_source_files_properties("${CMKR_TEMP_FILE}" PROPERTIES CMKR_CURRENT_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}" ) - + # 'Execute' the newly-generated CMakeLists.txt include("${CMKR_TEMP_FILE}") - + # Delete the generated file file(REMOVE "${CMKR_TEMP_FILE}") - + # Do not execute the rest of the original CMakeLists.txt return() endif() # Resume executing the unmodified CMakeLists.txt endif() -endmacro() +endmacro() \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 2845315..429ebf5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,10 @@ -#include #include #include +#include +#include int main() { fmt::print("SQLite version: {}\n", sqlite3_libversion()); + fmt::print("{} version: {}\n", mylib::reverse("bilym"), mylib::version()); } \ No newline at end of file diff --git a/vcpkg-overlay/mylib/CMakeLists.txt b/vcpkg-overlay/mylib/CMakeLists.txt new file mode 100644 index 0000000..8e8de4c --- /dev/null +++ b/vcpkg-overlay/mylib/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.15) +project(mylib) + +include(GNUInstallDirs) + +file(GLOB_RECURSE SOURCES + src/*.cpp + src/*.hpp +) + +add_library(mylib STATIC ${SOURCES}) +target_include_directories(mylib PUBLIC + $ + $ +) + +if(WIN32) + target_compile_definitions(mylib PRIVATE + _CRT_SECURE_NO_WARNINGS + ) +endif() + +install( + TARGETS mylib + EXPORT unofficial-mylib +) + +install( + EXPORT unofficial-mylib + FILE unofficial-mylib-config.cmake + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/unofficial-mylib + NAMESPACE unofficial::mylib:: +) + +install( + DIRECTORY ${CMAKE_SOURCE_DIR}/include/mylib + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) diff --git a/vcpkg-overlay/mylib/portfile.cmake b/vcpkg-overlay/mylib/portfile.cmake new file mode 100644 index 0000000..5f8d719 --- /dev/null +++ b/vcpkg-overlay/mylib/portfile.cmake @@ -0,0 +1,16 @@ +vcpkg_from_git( + OUT_SOURCE_PATH SOURCE_PATH + URL https://gitlab.com/mrexodia/mylib + REF 603babd11cbe14005d563f2e501bcea10fc3a9a0 # main on 2024-12-06 + HEAD_REF main +) + +file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}") + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" +) + +vcpkg_cmake_install() +vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-${PORT}) +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/vcpkg-overlay/mylib/usage b/vcpkg-overlay/mylib/usage new file mode 100644 index 0000000..95f98cc --- /dev/null +++ b/vcpkg-overlay/mylib/usage @@ -0,0 +1,4 @@ +mylib provides CMake targets: + + find_package(unofficial-mylib CONFIG REQUIRED) + target_link_libraries(main PRIVATE unofficial::mylib::mylib) \ No newline at end of file diff --git a/vcpkg-overlay/mylib/vcpkg.json b/vcpkg-overlay/mylib/vcpkg.json new file mode 100644 index 0000000..a6cdde2 --- /dev/null +++ b/vcpkg-overlay/mylib/vcpkg.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "name": "mylib", + "version-semver": "1.2.3", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} \ No newline at end of file diff --git a/vcpkg-overlay/x64-windows.cmake b/vcpkg-overlay/x64-windows.cmake new file mode 100644 index 0000000..63d6cde --- /dev/null +++ b/vcpkg-overlay/x64-windows.cmake @@ -0,0 +1,3 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) diff --git a/vcpkg.json b/vcpkg.json index 6081c48..597f958 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,11 +1,13 @@ -{ - "$cmkr": "This file is automatically generated from cmake.toml - DO NOT EDIT", - "$cmkr-url": "https://github.com/build-cpp/cmkr", - "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json", - "dependencies": [ - "fmt", - "sqlite3" - ], - "name": "vcpkg-template", - "version-string": "" -} +{ + "$cmkr": "This file is automatically generated from cmake.toml - DO NOT EDIT", + "$cmkr-url": "https://github.com/build-cpp/cmkr", + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "dependencies": [ + "fmt", + "sqlite3", + "mylib" + ], + "description": "", + "name": "vcpkg-template", + "version-string": "none" +}