mirror of
https://github.com/openziti/ziti-sdk-c.git
synced 2026-11-07 03:00:42 +00:00
standardize cmake with presets and vcpkg
This commit is contained in:
@@ -24,3 +24,4 @@ Testing/
|
||||
|
||||
#additional stuff for localtesting
|
||||
local.cmake
|
||||
/CMakeUserPresets.json
|
||||
|
||||
+14
-10
@@ -1,14 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
include(git.cmake)
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
include(cmake/version.cmake)
|
||||
get_version(${CMAKE_CURRENT_LIST_DIR}/version.txt ver)
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
project(ziti-sdk
|
||||
VERSION ${ver}
|
||||
LANGUAGES C CXX
|
||||
)
|
||||
|
||||
option(ZITI_BUILD_PROGRAMS "Build programs." ON)
|
||||
option(ZITI_BUILD_TESTS "Build tests." ON)
|
||||
include(cmake/project-is-top-level.cmake)
|
||||
include(cmake/variables.cmake)
|
||||
|
||||
option(HAVE_LIBSODIUM "use and link installed shared libsodium library" OFF)
|
||||
|
||||
@@ -42,8 +44,6 @@ endif()
|
||||
|
||||
message("cross-compiling ${CMAKE_CROSSCOMPILING}")
|
||||
|
||||
enable_testing()
|
||||
|
||||
if (DEFINED ENV{BUILD_NUMBER})
|
||||
set(ZITI_BUILDNUM $ENV{BUILD_NUMBER})
|
||||
endif ()
|
||||
@@ -89,11 +89,15 @@ endif()
|
||||
|
||||
add_subdirectory(library)
|
||||
|
||||
if (ZITI_BUILD_PROGRAMS)
|
||||
add_subdirectory(programs)
|
||||
if (PROJECT_IS_TOP_LEVEL)
|
||||
option(BUILD_EXAMPLES "Build examples tree." "${ziti_DEVELOPER_MODE}")
|
||||
if (BUILD_EXAMPLES)
|
||||
add_subdirectory(programs)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (ZITI_BUILD_TESTS)
|
||||
if (ziti_DEVELOPER_MODE)
|
||||
ENABLE_TESTING()
|
||||
add_subdirectory(tests)
|
||||
endif ()
|
||||
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
{
|
||||
"version": 2,
|
||||
"cmakeMinimumRequired": {
|
||||
"major": 3,
|
||||
"minor": 14,
|
||||
"patch": 0
|
||||
},
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "dev-mode",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"ziti_DEVELOPER_MODE": "ON",
|
||||
"VCPKG_MANIFEST_FEATURES": "test;samples"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "vcpkg",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "vcpkg-win64-static",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ninja",
|
||||
"hidden": true,
|
||||
"generator": "Ninja"
|
||||
},
|
||||
{
|
||||
"name": "ninja-multi-config",
|
||||
"hidden": true,
|
||||
"generator": "Ninja Multi-Config"
|
||||
},
|
||||
{
|
||||
"name": "ci-std",
|
||||
"description": "This preset makes sure the project actually builds with at least the specified standard",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_EXTENSIONS": "ON",
|
||||
"CMAKE_C_STANDARD": "99",
|
||||
"CMAKE_C_STANDARD_REQUIRED": "ON",
|
||||
"CMAKE_CXX_EXTENSIONS": "OFF",
|
||||
"CMAKE_CXX_STANDARD": "11",
|
||||
"CMAKE_CXX_STANDARD_REQUIRED": "ON"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "flags-unix",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_FLAGS": "",
|
||||
"CMAKE_CXX_FLAGS": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "flags-windows",
|
||||
"description": "Note that all the flags after /W4 are required for MSVC to conform to the language standard",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_FLAGS": "/utf-8 /W4 /permissive- /volatile:iso /Zc:preprocessor",
|
||||
"CMAKE_CXX_FLAGS": "/utf-8 /W4 /permissive- /volatile:iso /Zc:preprocessor /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew /EHsc"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ci-unix",
|
||||
"hidden": true,
|
||||
"inherits": [
|
||||
"flags-unix",
|
||||
"ci-std",
|
||||
"ninja-multi-config"
|
||||
],
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ci-win64",
|
||||
"inherits": [
|
||||
"flags-windows",
|
||||
"ci-std",
|
||||
"ninja"
|
||||
],
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"hidden": true
|
||||
},
|
||||
{
|
||||
"name": "ci-build",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"hidden": true
|
||||
},
|
||||
{
|
||||
"name": "ci-macOS",
|
||||
"inherits": [
|
||||
"ci-build",
|
||||
"ci-unix",
|
||||
"dev-mode",
|
||||
"vcpkg"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ci-ubuntu",
|
||||
"inherits": [
|
||||
"ci-build",
|
||||
"ci-unix",
|
||||
"vcpkg",
|
||||
"dev-mode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ci-windows",
|
||||
"inherits": [
|
||||
"ci-build",
|
||||
"ci-win64",
|
||||
"dev-mode",
|
||||
"vcpkg",
|
||||
"vcpkg-win64-static"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# This variable is set by project() in CMake 3.21+
|
||||
string(
|
||||
COMPARE EQUAL
|
||||
"${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}"
|
||||
PROJECT_IS_TOP_LEVEL
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
# ---- Developer mode ----
|
||||
|
||||
# Developer mode enables targets and code paths in the CMake scripts that are
|
||||
# only relevant for the developer(s) of tlsuv
|
||||
# Targets necessary to build the project must be provided unconditionally, so
|
||||
# consumers can trivially build and package the project
|
||||
if (PROJECT_IS_TOP_LEVEL)
|
||||
option(ziti_DEVELOPER_MODE "Enable developer mode" OFF)
|
||||
option(BUILD_SHARED_LIBS "Build shared libs." OFF)
|
||||
endif ()
|
||||
|
||||
# ---- Warning guard ----
|
||||
|
||||
# target_include_directories with the SYSTEM modifier will request the compiler
|
||||
# to omit warnings from the provided paths, if the compiler supports that
|
||||
# This is to provide a user experience similar to find_package when
|
||||
# add_subdirectory or FetchContent is used to consume this project
|
||||
set(warning_guard "")
|
||||
if (NOT PROJECT_IS_TOP_LEVEL)
|
||||
option(
|
||||
ziti_INCLUDES_WITH_SYSTEM
|
||||
"Use SYSTEM modifier for tlsuv's includes, disabling warnings"
|
||||
ON
|
||||
)
|
||||
mark_as_advanced(tlsuv_INCLUDES_WITH_SYSTEM)
|
||||
if (ziti_INCLUDES_WITH_SYSTEM)
|
||||
set(warning_guard SYSTEM)
|
||||
endif ()
|
||||
endif ()
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
function(get_version version_file version_var)
|
||||
execute_process(
|
||||
COMMAND git describe --tags HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_INFO
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_VARIABLE git_error
|
||||
)
|
||||
|
||||
if (git_error)
|
||||
unset(GIT_INFO)
|
||||
message("getting version from ${version_file}")
|
||||
file(STRINGS ${version_file} ver_info)
|
||||
list(LENGTH ver_info ver_info_len)
|
||||
list(GET ver_info 0 GIT_INFO)
|
||||
endif ()
|
||||
|
||||
if (${GIT_INFO} MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)$")
|
||||
set(_ver ${CMAKE_MATCH_1})
|
||||
elseif (${GIT_INFO} MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-[^-]*")
|
||||
string(JOIN "." _ver ${CMAKE_MATCH_1} ${CMAKE_MATCH_2})
|
||||
endif ()
|
||||
|
||||
set(${version_var} ${_ver} PARENT_SCOPE)
|
||||
endfunction()
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "ziti",
|
||||
"version-semver": "1.0.0",
|
||||
"dependencies": [
|
||||
"libuv",
|
||||
"openssl",
|
||||
"zlib",
|
||||
"llhttp"
|
||||
],
|
||||
"default-features": [
|
||||
"tls"
|
||||
],
|
||||
"features": {
|
||||
"test": {
|
||||
"description": "Dependencies for testing",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "catch2",
|
||||
"version>=": "2.13.9#1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"samples": {
|
||||
"description": "Dependencies for samples",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "getopt-win32",
|
||||
"platform": "windows"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"name": "catch2",
|
||||
"version": "2.13.9#1"
|
||||
}
|
||||
],
|
||||
"builtin-baseline": "f14984af3738e69f197bf0e647a8dca12de92996"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
$Format: %(describe:tags)$
|
||||
ref: $Format: %D$
|
||||
hash: $Format: %h$
|
||||
Reference in New Issue
Block a user