-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
78 lines (71 loc) · 2.52 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
cmake_minimum_required(VERSION 3.16)
project(jsonschema VERSION 4.1.5 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(vendor/noa/cmake/noa.cmake)
# Options
option(JSONSCHEMA_TESTS "Build the JSON Schema CLI tests" OFF)
option(JSONSCHEMA_TESTS_CI "Build the JSON Schema CLI CI tests" OFF)
option(JSONSCHEMA_DEVELOPMENT "Build the JSON Schema CLI in development mode" OFF)
option(JSONSCHEMA_CONTINUOUS "Perform a continuous JSON Schema CLI release" ON)
find_package(JSONToolkit REQUIRED)
find_package(AlterSchema REQUIRED)
find_package(Blaze REQUIRED)
find_package(JSONBinPack REQUIRED)
find_package(Hydra REQUIRED)
add_subdirectory(src)
if(JSONSCHEMA_DEVELOPMENT)
noa_target_clang_format(SOURCES
src/*.h src/*.cc)
noa_target_clang_tidy(SOURCES
src/*.h src/*.cc)
noa_target_shellcheck(SOURCES
test/*.sh install *.sh)
endif()
# Testing
if(JSONSCHEMA_TESTS)
enable_testing()
add_subdirectory(test)
endif()
if(PROJECT_IS_TOP_LEVEL)
# As a sanity check
if(EXISTS "${PROJECT_SOURCE_DIR}/action.yml")
file(READ "${PROJECT_SOURCE_DIR}/action.yml" ACTION_YML)
string(FIND "${ACTION_YML}" "${PROJECT_VERSION}" ACTION_YML_HAS_VERSION)
if(${ACTION_YML_HAS_VERSION} EQUAL -1)
message(FATAL_ERROR
"The GitHub Action definition must set the correct version: ${PROJECT_VERSION}")
endif()
endif()
# Packaging
find_program(GIT_BIN NAMES git)
if(GIT_BIN AND JSONSCHEMA_CONTINUOUS)
execute_process(COMMAND "${GIT_BIN}" rev-parse --git-dir
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE GIT_DIR)
endif()
if(GIT_BIN AND EXISTS "${GIT_DIR}")
execute_process(
COMMAND "${GIT_BIN}" rev-parse --short=8 HEAD
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE PROJECT_GIT_SHA
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
else()
set(PROJECT_GIT_SHA "unknown")
endif()
set(CPACK_GENERATOR ZIP)
string(TOLOWER ${CMAKE_SYSTEM_NAME} LOWER_SYSTEM_NAME)
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWER_SYSTEM_PROCESSOR)
if(LOWER_SYSTEM_PROCESSOR STREQUAL "amd64")
set(LOWER_SYSTEM_PROCESSOR "x86_64")
endif()
set(PLATFORM_SUFFIX "${LOWER_SYSTEM_NAME}-${LOWER_SYSTEM_PROCESSOR}")
if(JSONSCHEMA_CONTINUOUS)
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${PROJECT_GIT_SHA}-${PLATFORM_SUFFIX}")
else()
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${PLATFORM_SUFFIX}")
endif()
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)
endif()