Skip to content

Commit

Permalink
[cpp]: update CMate and CMakefiles to allow FetchContent (#244)
Browse files Browse the repository at this point in the history
* chore: new CMate YAML files

* chore: updated to CMate with full templates

* cpp: update cmate tool

* cpp: fixed amalgamated template define order

* cpp: updated to latest CMate
  • Loading branch information
chybz authored Aug 19, 2024
1 parent c3f942b commit 936cbb1
Show file tree
Hide file tree
Showing 8 changed files with 1,759 additions and 445 deletions.
128 changes: 116 additions & 12 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,144 @@
###
#
# Project
# name and version
#
###
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(cucumber_messages VERSION 0.1.0 LANGUAGES C CXX)

###
#
# Main project check
#
###
set(cucumber_messages_MAIN_PROJECT OFF)

if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(cucumber_messages_MAIN_PROJECT ON)
endif()

###
#
# Options
#
###
if(${CUCUMBER_MESSAGES_MAIN_PROJECT})
set(CUCUMBER_MESSAGES_BUILD_TESTS_INIT ON)
set(CUCUMBER_MESSAGES_EXPORT_COMPILE_INIT ON)
else()
set(CUCUMBER_MESSAGES_BUILD_TESTS_INIT OFF)
set(CUCUMBER_MESSAGES_EXPORT_COMPILE_INIT OFF)
endif()

option(
CUCUMBER_MESSAGES_BUILD_TESTS
"Build the unit tests."
${CUCUMBER_MESSAGES_BUILD_TESTS_INIT}
)

option(
CUCUMBER_MESSAGES_EXPORT_COMPILE
"Export compile commands."
${CUCUMBER_MESSAGES_EXPORT_COMPILE_INIT}
)

option(
CUCUMBER_MESSAGES_FETCH_DEPS
"Fetch dependencies via FetchContent."
${CUCUMBER_MESSAGES_FETCH_DEPS}
)

###
#
# Configuration
#
###
include(GNUInstallDirs)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS)
endif()

if(CUCUMBER_MESSAGES_EXPORT_COMPILE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()

###
#
# CMake dependencies
#
###
if(CUCUMBER_MESSAGES_FETCH_DEPS)
include(FetchContent)

FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
OVERRIDE_FIND_PACKAGE
)

set(JSON_BuildTests "OFF")
set(JSON_Install "ON")

if(WIN32)
add_definitions(-DUNICODE -D_UNICODE -DSTRICT -DNOMINMAX)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
FetchContent_MakeAvailable(nlohmann_json)
endif()

find_package(nlohmann_json CONFIG REQUIRED)

###
#
# Targets
#
###
add_subdirectory(src/lib/messages)

###
#
# Installation support
#
###
include(CMakePackageConfigHelpers)

configure_package_config_file(
"cmake/cucumber_messages-config.cmake.in"
"${PROJECT_BINARY_DIR}/cucumber_messages-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cucumber_messages"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
)

write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/cucumber_messages-config-version.cmake"
COMPATIBILITY AnyNewerVersion
)

install(
TARGETS
cucumber_messages_lib
EXPORT cucumber_messages-config
EXPORT cucumber_messages-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(
EXPORT cucumber_messages-config
FILE cucumber_messages-config.cmake
EXPORT cucumber_messages-targets
FILE cucumber_messages-targets.cmake
NAMESPACE cucumber::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cucumber_messages
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cucumber_messages"
)

install(
FILES
"${PROJECT_BINARY_DIR}/cucumber_messages-config.cmake"
"${PROJECT_BINARY_DIR}/cucumber_messages-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cucumber_messages"
)


install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/messages/"
DIRECTORY "${PROJECT_SOURCE_DIR}/include/messages"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cucumber
)
Loading

0 comments on commit 936cbb1

Please sign in to comment.