Skip to content

Commit

Permalink
Refactor to use mnxdom (#6)
Browse files Browse the repository at this point in the history
* wip (not working)

* fix issues from tests

* use main branch for mnxdom FetchContent

* latest make file

* update the github action with correct test options for windows
  • Loading branch information
rpatters1 authored Feb 9, 2025
1 parent f51689c commit 170a16f
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 222 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ jobs:
if: matrix.os == 'windows-latest'
run: cmake --build build --config Release

# Run Tests
- name: Run Tests
- name: Run Tests on Windows
if: runner.os == 'Windows'
run: ctest --test-dir build/tests -C Release --output-on-failure

- name: Run Tests on Linux/macOS
if: runner.os != 'Windows'
run: ctest --test-dir build/tests --output-on-failure

53 changes: 28 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ set(GENERATED_DIR "${CMAKE_BINARY_DIR}/generated")

# Set output directory for compiled executable
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})
set(BUILD_TESTING OFF CACHE BOOL "Disable testing for external dependencies" FORCE)

# Save the current state and disable deprecation warnings
set(_original_WARN_DEPRECATED ${CMAKE_WARN_DEPRECATED})
Expand All @@ -97,30 +96,35 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(miniz-cpp)

# Disable building tests for nlohmann_json
set(JSON_BuildTests OFF CACHE BOOL "Do not build tests for nlohmann_json")
# Define the version of nlohmann_json to use
set(NLOHMANN_JSON_VERSION v3.11.3)
# Fetch nlohmann_json
FetchContent_Declare(
nlohmann_json
URL https://github.com/nlohmann/json/releases/download/${NLOHMANN_JSON_VERSION}/json.tar.xz
URL_HASH SHA256=d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d # Verify the hash matches the tarball
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(nlohmann_json)
# Define a cache variable for the local MNX C++ DOM path relative to the source directory.
set(MNXDOM_LOCAL_PATH "" CACHE STRING "Path to local MNX C++ DOM checkout relative to the source directory (if provided)")

# Disable building tests for json_schema_validator
set(JSON_VALIDATOR_BUILD_TESTS OFF CACHE BOOL "Do not build tests for json_schema_validator")
# Fetch json_schema_validator from your fork
set(nlohmann_json_VERSION ${NLOHMANN_JSON_VERSION})
if(MNXDOM_LOCAL_PATH)
# Combine the source directory with the relative path to get an absolute path.
get_filename_component(MNXDOM_LOCAL_PATH_ABS "${CMAKE_SOURCE_DIR}/${MNXDOM_LOCAL_PATH}" ABSOLUTE)
if(EXISTS "${MNXDOM_LOCAL_PATH_ABS}/CMakeLists.txt")
message(STATUS "Local MNX C++ DOM found at ${MNXDOM_LOCAL_PATH_ABS}")
# Set the FetchContent source directory to the computed absolute path.
set(FETCHCONTENT_SOURCE_DIR_MNXDOM "${MNXDOM_LOCAL_PATH_ABS}" CACHE INTERNAL "")
else()
message(FATAL_ERROR "Local MNX C++ DOM not found at ${MNXDOM_LOCAL_PATH_ABS}")
endif()
else()
message(STATUS "Using GitHub for MNX C++ DOM")
endif()

option(mnxdom_BUILD_TESTING "Enable testing mnxdom" ON)
# Fetch mnxdom
FetchContent_Declare(
json_schema_validator
GIT_REPOSITORY https://github.com/pboettch/json-schema-validator
GIT_TAG 40af3ec39670e768fc3f01f935140af311d71024
mnxdom
GIT_REPOSITORY https://github.com/rpatters1/mnxdom.git
GIT_TAG main
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(json_schema_validator)
FetchContent_MakeAvailable(mnxdom)

FetchContent_GetProperties(mnxdom)
message(STATUS "mnxdom Source Directory: ${mnxdom_SOURCE_DIR}")

# Restore the original state
set(CMAKE_WARN_DEPRECATED ${_original_WARN_DEPRECATED} CACHE BOOL "Restore original deprecation warnings setting" FORCE)
Expand All @@ -129,7 +133,6 @@ add_custom_target(PrintConfig ALL
COMMAND ${CMAKE_COMMAND} -E echo "Active build configuration: $<CONFIG>"
)

include("${CMAKE_SOURCE_DIR}/cmake/GenerateMnxSchemaXxd.cmake")
include("${CMAKE_SOURCE_DIR}/cmake/GenerateLicenseXxd.cmake")

# Add executable target
Expand Down Expand Up @@ -158,16 +161,15 @@ set(MUSX_DISPLAY_NODE_NAMES ON CACHE BOOL "Write node names to std::cout as they
#set(MUSX_THROW_ON_INTEGRITY_CHECK_FAIL ON CACHE BOOL "Enable throwing integrity check failures" FORCE)

# Ensure the include directories are added
add_dependencies(mnxvalidate GenerateMnxSchemaXxd GenerateLicenseXxd)
add_dependencies(mnxvalidate GenerateLicenseXxd)
target_include_directories(mnxvalidate PRIVATE "${FETCHCONTENT_BASE_DIR}/ezgz-src")
target_include_directories(mnxvalidate SYSTEM PRIVATE "${FETCHCONTENT_BASE_DIR}/miniz-cpp-src")
target_include_directories(mnxvalidate PRIVATE ${GENERATED_DIR})
target_include_directories(mnxvalidate PRIVATE ${MUSX_OBJECT_MODEL_DIR})
target_include_directories(mnxvalidate PRIVATE ${CMAKE_SOURCE_DIR}/src)

# Ensure the libraries are added
target_link_libraries(mnxvalidate PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(mnxvalidate PRIVATE nlohmann_json_schema_validator)
target_link_libraries(mnxvalidate PRIVATE mnxdom)

# Define an interface library for precompiled headers
add_library(mnxvalidate_pch INTERFACE)
Expand All @@ -178,6 +180,7 @@ target_precompile_headers(mnxvalidate_pch INTERFACE
<functional>
<string>
<memory>
<mnxdom.h>
)

# Link the interface library to mnxvalidate
Expand Down
3 changes: 2 additions & 1 deletion cmake/GenerateLicenseXxd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
set(LICENSE_FILES
"${CMAKE_SOURCE_DIR}/LICENSE"
"${nlohmann_json_SOURCE_DIR}/LICENSE.MIT"
"${json_schema_validator_SOURCE_DIR}/LICENSE"
"${nlohmann_json_schema_validator_SOURCE_DIR}/LICENSE"
"${miniz-cpp_SOURCE_DIR}/LICENSE.md"
)

Expand All @@ -29,6 +29,7 @@ foreach(INDEX RANGE 0 ${LAST_INDEX})
list(GET LICENSE_FILES ${INDEX} LICENSE_FILE)
list(GET LICENSE_PREFIXES ${INDEX} SAFE_NAME_PREFIX)

message(STATUS "Processing LICENSE_FILE: ${LICENSE_FILE}")
set(GENERATED_XXD "${GENERATED_DIR}/${SAFE_NAME_PREFIX}_license.xxd")

# Extract the directory of the license file
Expand Down
24 changes: 0 additions & 24 deletions cmake/GenerateMnxSchemaXxd.cmake

This file was deleted.

Loading

0 comments on commit 170a16f

Please sign in to comment.