Skip to content

Commit

Permalink
Make the project embeddable from a CMake point of view (#139)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jul 26, 2024
1 parent e5596ff commit 403c70a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 49 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ jobs:
env:
HOMEBREW_NO_ANALYTICS: 1
HOMEBREW_NO_AUTO_UPDATE: 1
- name: Install dependencies (Windows)
if: runner.os == 'windows'
run: choco install shellcheck

- run: cmake --version

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
-DCMAKE_BUILD_TYPE:STRING=Release
-DJSONSCHEMA_TESTS:BOOL=ON
-DJSONSCHEMA_TESTS_CI:BOOL=ON
-DJSONSCHEMA_DEVELOPMENT:BOOL=ON
-DBUILD_SHARED_LIBS:BOOL=OFF
-DCMAKE_COMPILE_WARNING_AS_ERROR:BOOL=ON
- run: cmake --build ./build --config Release --target clang_format_test
Expand Down
95 changes: 50 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,70 @@ 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(Hydra REQUIRED)
add_subdirectory(src)

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)
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()

# 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}")
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()
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()
# 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}")
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()
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ configure: .always
-DJSONSCHEMA_TESTS:BOOL=ON \
-DJSONSCHEMA_TESTS_CI:BOOL=OFF \
-DJSONSCHEMA_CONTINUOUS:BOOL=ON \
-DJSONSCHEMA_DEVELOPMENT:BOOL=ON \
-DBUILD_SHARED_LIBS:BOOL=$(SHARED)

compile: .always
Expand Down
2 changes: 1 addition & 1 deletion src/configure.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string_view> // std::string_view

namespace intelligence::jsonschema::cli {
constexpr std::string_view PROJECT_VERSION{"@CMAKE_PROJECT_VERSION@"};
constexpr std::string_view PROJECT_VERSION{"@PROJECT_VERSION@"};
}

#endif
19 changes: 19 additions & 0 deletions vendorpull.mask
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
assets
bin
docs
test
vendor/hydra
vendor/jsontoolkit
vendor/vendorpull
.ackrc
.editorconfig
action.yml
Brewfile
CONTRIBUTING.markdown
DEPENDENCIES
Dockerfile
install
Makefile
npm-deploy.sh
README.markdown
cmake

0 comments on commit 403c70a

Please sign in to comment.