diff --git a/CHANGELOG.md b/CHANGELOG.md index a1a46d98..28eac903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* CMake: don't build tests when imported in another project + v6.15.1 (2020-04-08) ------- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0de4f9f5..8236a95a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,40 +6,42 @@ cmake_minimum_required(VERSION 3.0) project(ArduinoJson VERSION 6.15.1) -set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true) - -enable_testing() - -add_definitions(-DARDUINOJSON_DEBUG=1) - -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) - add_compile_options(-g -Og) - else() - add_compile_options(-g -O0) - endif() -endif() - -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) - add_compile_options(-g -Og) - else() - add_compile_options(-g -O0) - endif() -endif() - -if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) - add_compile_options(-g -Og) - else() - add_compile_options(-g -O0) - endif() -endif() - -if(${COVERAGE}) - set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage") +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) endif() add_subdirectory(src) -add_subdirectory(extras/tests) -add_subdirectory(extras/fuzzing) + +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) + + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) + add_compile_options(-g -Og) + else() + add_compile_options(-g -O0) + endif() + endif() + + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) + add_compile_options(-g -Og) + else() + add_compile_options(-g -O0) + endif() + endif() + + if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) + add_compile_options(-g -Og) + else() + add_compile_options(-g -O0) + endif() + endif() + + if(${COVERAGE}) + set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage") + endif() + + add_subdirectory(extras/tests) + add_subdirectory(extras/fuzzing) +endif() diff --git a/README.md b/README.md index 5d2c40f2..bcf90c66 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,9 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * [Visual Micro](http://www.visualmicro.com/) * [Visual Studio](https://www.visualstudio.com/) * [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/t7KP7I6dVuLhqzDl) + * [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/?utm_source=github&utm_medium=readme) * Well designed - * [Elegant API](http://127.0.0.1:4000/v6/example/) + * [Elegant API](http://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) * [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety) * Self-contained (no external dependency) * `const` friendly diff --git a/extras/ci/build.sh b/extras/ci/build.sh index 34547bee..4741963b 100755 --- a/extras/ci/build.sh +++ b/extras/ci/build.sh @@ -3,12 +3,5 @@ export CC="$_CC" export CXX="$_CXX" -if [ -n "$SANITIZE" ]; then - export CXXFLAGS="-fsanitize=$SANITIZE" - BUILD_TYPE="Debug" -else - BUILD_TYPE="Release" -fi - -cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE . +cmake -DCMAKE_BUILD_TYPE=Release . cmake --build . diff --git a/extras/ci/test.sh b/extras/ci/test.sh index 031f3eed..ce76eb69 100755 --- a/extras/ci/test.sh +++ b/extras/ci/test.sh @@ -1,4 +1,10 @@ #!/bin/sh -ex -"$(dirname "$0")/build.sh" +export CC="$_CC" +export CXX="$_CXX" + +[ -n "$SANITIZE" ] && export CXXFLAGS="-fsanitize=$SANITIZE" + +cmake -DCMAKE_BUILD_TYPE=Debug . +cmake --build . ctest --output-on-failure . diff --git a/extras/scripts/create-build-envs.sh b/extras/scripts/create-build-envs.sh deleted file mode 100755 index 3efee2f9..00000000 --- a/extras/scripts/create-build-envs.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -export PATH="$PATH:/Applications/CMake.app/Contents/bin/" - -cd $(dirname $0)/../.. -ROOT=$(pwd) - -mkdir "build" -cd build -BUILD=$(pwd) - -build-env() -{ - cd $BUILD - mkdir "$1" - cd "$1" - cmake "$ROOT" -G "$2" -} - -if [[ $(uname) == MINGW* ]] -then - build-env "Make" "MinGW Makefiles" - build-env "SublimeText" "Sublime Text 2 - Ninja" - build-env "VisualStudio" "Visual Studio 14 2015" -else - build-env "SublimeText" "Sublime Text 2 - Ninja" - build-env "Make" "Unix Makefiles" - build-env "Xcode" "Xcode" -fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26daec2f..e53a4b2a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,11 @@ target_include_directories(ArduinoJson $ ) +target_compile_definitions(ArduinoJson + INTERFACE + ARDUINOJSON_DEBUG=$ +) + # locations are provided by GNUInstallDirs install( TARGETS