-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add a new project to catch missing includes
- Loading branch information
1 parent
223c516
commit b78ec05
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
cmake_minimum_required (VERSION 3.2) | ||
project(sjson-cpp_validate_includes CXX) | ||
|
||
# The goal of this project is to generate a single cpp file for every public header | ||
# This will allow us to detect if we are missing an include file during development | ||
|
||
include_directories("${PROJECT_SOURCE_DIR}/../../includes") | ||
|
||
# Grab all of our public header files | ||
file(GLOB ALL_PUBLIC_HEADER_FILES LIST_DIRECTORIES false | ||
${PROJECT_SOURCE_DIR}/../../includes/sjson/*.h) | ||
|
||
# Generate the single include cpp files | ||
foreach(HEADER_FILE ${ALL_PUBLIC_HEADER_FILES}) | ||
# Find the root include directory position | ||
string(FIND ${HEADER_FILE} "sjson" HEADER_FILE_SJSON_CPP_POS REVERSE) | ||
|
||
# Strip the root of the include path | ||
string(SUBSTRING ${HEADER_FILE} ${HEADER_FILE_SJSON_CPP_POS} -1 HEADER_INCLUDE_PATH) | ||
|
||
# Configure our cpp file content | ||
set(SJSON_CPP_SINGLE_INCLUDE_NAME ${HEADER_INCLUDE_PATH}) | ||
|
||
# Sanitize our filename so we can generate a unique cpp file for it | ||
string(REPLACE "/" "_" HEADER_SANITIZED_FILENAME ${HEADER_INCLUDE_PATH}) | ||
string(REPLACE "\\" "_" HEADER_SANITIZED_FILENAME ${HEADER_SANITIZED_FILENAME}) | ||
|
||
# Generate our single include cpp file | ||
configure_file(${PROJECT_SOURCE_DIR}/single_include.cpp.in single_include_${HEADER_SANITIZED_FILENAME}.cpp @ONLY) | ||
endforeach(HEADER_FILE) | ||
|
||
# Grab all of our main source files | ||
file(GLOB_RECURSE ALL_MAIN_SOURCE_FILES LIST_DIRECTORIES false | ||
${PROJECT_SOURCE_DIR}/*.cpp | ||
${PROJECT_BINARY_DIR}/*.cpp) | ||
|
||
create_source_groups("${ALL_MAIN_SOURCE_FILES}" ${PROJECT_SOURCE_DIR}) | ||
|
||
add_library(${PROJECT_NAME} STATIC ${ALL_MAIN_SOURCE_FILES}) | ||
|
||
setup_default_compiler_flags(${PROJECT_NAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Nicholas Frechette, Cody Jones, and sjson-cpp contributors | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
// We define a single symbol here to avoid a warning when we build our static library | ||
// to validate includes | ||
void some_function() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Nicholas Frechette, Cody Jones, and sjson-cpp contributors | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include <@SJSON_CPP_SINGLE_INCLUDE_NAME@> |