Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Dec 29, 2020
1 parent c9632ab commit e553e6c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .cmake/taocpp-json-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(pegtl @PEGTL_MIN_VERSION@ CONFIG)
find_dependency(pegtl @TAOCPP_JSON_PEGTL_MIN_VERSION@ CONFIG)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
23 changes: 10 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ cmake_minimum_required(VERSION 3.8...3.19)

project(taocpp-json VERSION 1.0.0 LANGUAGES CXX)

# Determine if taocpp-json is built as a subproject (using add_subdirectory)
# or if it is the master project.
set(MASTER_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MASTER_PROJECT ON)
get_directory_property(TAOCPP_JSON_HAS_PARENT PARENT_DIRECTORY)
if(TAOCPP_JSON_HAS_PARENT)
set(TAOCPP_JSON_IS_MAIN_PROJECT OFF)
else()
set(TAOCPP_JSON_IS_MAIN_PROJECT ON)
endif()


# installation directories
include(GNUInstallDirs)

Expand All @@ -28,13 +27,11 @@ target_include_directories(json INTERFACE
target_compile_features(json INTERFACE cxx_std_17)

# find a suitable PEGTL
set(PEGTL_MIN_VERSION 3.1.0)
set(TAOCPP_JSON_PEGTL_MIN_VERSION 3.1.0)
find_package(pegtl ${PEGTL_MIN_VERSION} QUIET CONFIG)
if(NOT pegtl_FOUND)
# if a compatible version of PEGTL is not already installed, build and install it from the submodule directory
message(STATUS "Adding PEGTL as submodule from external/PEGTL.")
set(PEGTL_BUILD_TESTS OFF CACHE BOOL "Disable PEGTL tests")
set(PEGTL_BUILD_EXAMPLES OFF CACHE BOOL "Disable PEGTL examples")
message(STATUS "Adding PEGTL as submodule from external/PEGTL")
set(PEGTL_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING "Override PEGTL include install directory")
set(PEGTL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_DATAROOTDIR}/pegtl/cmake CACHE STRING "Override PEGTL cmake install directory")
add_subdirectory(external/PEGTL)
Expand All @@ -44,19 +41,19 @@ endif()
target_link_libraries(json INTERFACE taocpp::pegtl)

# testing
option(TAOCPP_JSON_BUILD_TESTS "Build test programs" ${MASTER_PROJECT})
option(TAOCPP_JSON_BUILD_TESTS "Build test programs" ${TAOCPP_JSON_IS_MAIN_PROJECT})
if(TAOCPP_JSON_BUILD_TESTS)
enable_testing()
add_subdirectory(src/test/json)
endif()

# examples
option(TAOCPP_JSON_BUILD_EXAMPLES "Build example programs" ${MASTER_PROJECT})
option(TAOCPP_JSON_BUILD_EXAMPLES "Build example programs" ${TAOCPP_JSON_IS_MAIN_PROJECT})
if(TAOCPP_JSON_BUILD_EXAMPLES)
add_subdirectory(src/example/json)
endif()

option(TAOCPP_JSON_INSTALL "Generate the install target" ${MASTER_PROJECT})
option(TAOCPP_JSON_INSTALL "Generate the install target" ${TAOCPP_JSON_IS_MAIN_PROJECT})
if(TAOCPP_JSON_INSTALL)
include(CMakePackageConfigHelpers)

Expand Down
6 changes: 3 additions & 3 deletions src/example/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.8...3.19)

set(examplesources
cbor_to_jaxn.cpp
Expand Down Expand Up @@ -58,10 +58,10 @@ foreach(examplesourcefile ${examplesources})
else()
target_compile_options(${exename} PRIVATE -pedantic -Wall -Wextra -Wshadow -Werror)
endif()
endforeach(examplesourcefile)
endforeach()

if(glob_example_sources)
foreach(ignored_source_file ${glob_example_sources})
message(SEND_ERROR "File ${ignored_source_file} in src/example/json is ignored")
endforeach(ignored_source_file)
endforeach()
endif()
6 changes: 3 additions & 3 deletions src/test/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.8...3.19)

set(testsources
big_list_of_naughty_strings.cpp
Expand Down Expand Up @@ -88,10 +88,10 @@ foreach(testsourcefile ${testsources})
target_compile_options(${exename} PRIVATE -pedantic -Wall -Wextra -Wshadow -Werror)
endif()
add_test(NAME ${exename} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${exename})
endforeach(testsourcefile)
endforeach()

if(glob_test_sources)
foreach(ignored_source_file ${glob_test_sources})
message(SEND_ERROR "File ${ignored_source_file} in src/test/json is ignored")
endforeach(ignored_source_file)
endforeach()
endif()

0 comments on commit e553e6c

Please sign in to comment.