CMake: don't build tests when imported in another project

This commit is contained in:
Benoit Blanchon
2020-04-11 12:25:38 +02:00
parent 1f7a5e6943
commit ae9b7926a2
7 changed files with 56 additions and 73 deletions

View File

@ -1,6 +1,11 @@
ArduinoJson: change log ArduinoJson: change log
======================= =======================
HEAD
----
* CMake: don't build tests when imported in another project
v6.15.1 (2020-04-08) v6.15.1 (2020-04-08)
------- -------

View File

@ -6,40 +6,42 @@ cmake_minimum_required(VERSION 3.0)
project(ArduinoJson VERSION 6.15.1) project(ArduinoJson VERSION 6.15.1)
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
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")
endif() endif()
add_subdirectory(src) 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()

View File

@ -62,8 +62,9 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* [Visual Micro](http://www.visualmicro.com/) * [Visual Micro](http://www.visualmicro.com/)
* [Visual Studio](https://www.visualstudio.com/) * [Visual Studio](https://www.visualstudio.com/)
* [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/t7KP7I6dVuLhqzDl) * [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 * 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) * [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety)
* Self-contained (no external dependency) * Self-contained (no external dependency)
* `const` friendly * `const` friendly

View File

@ -3,12 +3,5 @@
export CC="$_CC" export CC="$_CC"
export CXX="$_CXX" export CXX="$_CXX"
if [ -n "$SANITIZE" ]; then cmake -DCMAKE_BUILD_TYPE=Release .
export CXXFLAGS="-fsanitize=$SANITIZE"
BUILD_TYPE="Debug"
else
BUILD_TYPE="Release"
fi
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .
cmake --build . cmake --build .

View File

@ -1,4 +1,10 @@
#!/bin/sh -ex #!/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 . ctest --output-on-failure .

View File

@ -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

View File

@ -17,6 +17,11 @@ target_include_directories(ArduinoJson
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
) )
target_compile_definitions(ArduinoJson
INTERFACE
ARDUINOJSON_DEBUG=$<CONFIG:Debug>
)
# locations are provided by GNUInstallDirs # locations are provided by GNUInstallDirs
install( install(
TARGETS TARGETS