🔀 merge branch 'cotire' of https://github.com/tusharpm/json into tusharpm-cotire

This commit is contained in:
Niels Lohmann 2017-02-22 19:45:10 +01:00
commit a646c9c599
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
7 changed files with 4067 additions and 9 deletions

1
.gitignore vendored
View file

@ -7,6 +7,7 @@ fuzz-testing
*.gcno *.gcno
*.gcda *.gcda
build
working working
doc/xml doc/xml

View file

@ -228,6 +228,14 @@ install:
# make sure CXX is correctly set # make sure CXX is correctly set
- if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi - if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi
# get CMake (only for systems with brew - macOS)
- |
if [[ !(-x $(which cmake)) && (-x $(which brew)) ]]; then
brew update
brew install cmake
cmake --version
fi
# install LLVM/clang when LLVM_VERSION is set # install LLVM/clang when LLVM_VERSION is set
- | - |
if [[ "${LLVM_VERSION}" != "" ]]; then if [[ "${LLVM_VERSION}" != "" ]]; then
@ -266,7 +274,10 @@ script:
- $CXX --version - $CXX --version
# compile and execute unit tests # compile and execute unit tests
- make check - mkdir -p build && cd build
- cmake .. && cmake --build . --config Release -- -j4
- ctest -C Release -V
- cd ..
# check if homebrew works (only checks develop branch) # check if homebrew works (only checks develop branch)
- if [ `which brew` ]; then - if [ `which brew` ]; then

View file

@ -16,6 +16,8 @@ set(JSON_CONFIGVERSION_FILENAME "${JSON_PACKAGE_NAME}ConfigVersion.cmake")
set(JSON_CONFIG_DESTINATION "cmake") set(JSON_CONFIG_DESTINATION "cmake")
set(JSON_INCLUDE_DESTINATION "include/nlohmann") set(JSON_INCLUDE_DESTINATION "include/nlohmann")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# create and configure the library target # create and configure the library target
add_library(${JSON_TARGET_NAME} INTERFACE) add_library(${JSON_TARGET_NAME} INTERFACE)
target_include_directories(${JSON_TARGET_NAME} INTERFACE target_include_directories(${JSON_TARGET_NAME} INTERFACE

4008
cmake/cotire.cmake Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,16 @@
add_library(catch_main OBJECT
"src/unit.cpp"
)
set_target_properties(catch_main PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
)
target_include_directories(catch_main PRIVATE "thirdparty/catch")
# The unit test executable. # The unit test executable.
set(JSON_UNITTEST_TARGET_NAME "json_unit") set(JSON_UNITTEST_TARGET_NAME "json_unit")
add_executable(${JSON_UNITTEST_TARGET_NAME} add_executable(${JSON_UNITTEST_TARGET_NAME}
"thirdparty/catch/catch.hpp" $<TARGET_OBJECTS:catch_main>
"src/unit.cpp"
"src/unit-algorithms.cpp" "src/unit-algorithms.cpp"
"src/unit-allocator.cpp" "src/unit-allocator.cpp"
"src/unit-capacity.cpp" "src/unit-capacity.cpp"
@ -43,13 +51,33 @@ add_executable(${JSON_UNITTEST_TARGET_NAME}
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
CXX_STANDARD 11 CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
) )
if(MSVC)
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
COMPILE_DEFINITIONS "_SCL_SECURE_NO_WARNINGS"
COMPILE_OPTIONS "/EHsc;$<$<CONFIG:Release>:/Od>"
)
endif()
target_include_directories(${JSON_UNITTEST_TARGET_NAME} PRIVATE "src" "thirdparty/catch") target_include_directories(${JSON_UNITTEST_TARGET_NAME} PRIVATE "src" "thirdparty/catch")
target_link_libraries(${JSON_UNITTEST_TARGET_NAME} ${JSON_TARGET_NAME}) target_link_libraries(${JSON_UNITTEST_TARGET_NAME} ${JSON_TARGET_NAME})
include(cotire OPTIONAL)
if(COMMAND cotire)
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
COTIRE_ADD_UNITY_BUILD FALSE
COTIRE_CXX_PREFIX_HEADER_INIT "src/prefix.hpp"
)
# HACK - CMAKE_INCLUDE_SYSTEM_FLAG_CXX has a trailing space, which Cotire doesn't strip
# Technically, this fix should go in cotire.cmake. TODO - submit a pull request upstream.
if (CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_CXX}" CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
endif()
cotire(${JSON_UNITTEST_TARGET_NAME})
endif()
add_test(NAME "${JSON_UNITTEST_TARGET_NAME}_default" add_test(NAME "${JSON_UNITTEST_TARGET_NAME}_default"
COMMAND ${JSON_UNITTEST_TARGET_NAME} COMMAND ${JSON_UNITTEST_TARGET_NAME}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}

7
test/src/prefix.hpp Normal file
View file

@ -0,0 +1,7 @@
#pragma once
#include "catch.hpp"
#define private public
#include "json.hpp"
using nlohmann::json;

View file

@ -26,16 +26,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <array>
#include <map>
#include <string>
#include <memory>
#include "catch.hpp" #include "catch.hpp"
#include "json.hpp" #include "json.hpp"
using nlohmann::json; using nlohmann::json;
#include <array>
#include <map>
#include <string>
#include <memory>
namespace udt namespace udt
{ {
enum class country enum class country