Skip to content

Commit

Permalink
CMake: don't build tests when imported in another project
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Apr 11, 2020
1 parent 1f7a5e6 commit d315fbf
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 65 deletions.
5 changes: 5 additions & 0 deletions 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)
-------

Expand Down
56 changes: 29 additions & 27 deletions CMakeLists.txt
Expand Up @@ -6,40 +6,42 @@ cmake_minimum_required(VERSION 3.0)

project(ArduinoJson VERSION 6.15.1)

set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
endif()

enable_testing()
add_subdirectory(src)

add_definitions(-DARDUINOJSON_DEBUG=1)
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)
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()
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)
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()
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)
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()
endif()

if(${COVERAGE})
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
endif()
if(${COVERAGE})
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
endif()

add_subdirectory(src)
add_subdirectory(extras/tests)
add_subdirectory(extras/fuzzing)
add_subdirectory(extras/tests)
add_subdirectory(extras/fuzzing)
endif()
9 changes: 1 addition & 8 deletions extras/ci/build.sh
Expand Up @@ -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 .
8 changes: 7 additions & 1 deletion 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 .
29 changes: 0 additions & 29 deletions extras/scripts/create-build-envs.sh

This file was deleted.

5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -17,6 +17,11 @@ target_include_directories(ArduinoJson
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_compile_definitions(ArduinoJson
INTERFACE
ARDUINOJSON_DEBUG=$<CONFIG:Debug>
)

# locations are provided by GNUInstallDirs
install(
TARGETS
Expand Down

0 comments on commit d315fbf

Please sign in to comment.