Reformat CMake files

This commit is contained in:
Benoit Blanchon
2023-02-09 10:00:38 +01:00
parent e0bdc4bff1
commit 62dea9d364
24 changed files with 104 additions and 107 deletions

View File

@ -10,5 +10,9 @@
}, },
"C_Cpp.default.includePath": [ "C_Cpp.default.includePath": [
"/src" "/src"
] ],
"[cmake]": {
"editor.detectIndentation": false,
"editor.insertSpaces": false,
}
} }

View File

@ -5,15 +5,15 @@
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
if(ESP_PLATFORM) if(ESP_PLATFORM)
# Build ArduinoJson as an ESP-IDF component # Build ArduinoJson as an ESP-IDF component
idf_component_register(INCLUDE_DIRS src) idf_component_register(INCLUDE_DIRS src)
return() return()
endif() endif()
project(ArduinoJson VERSION 6.20.1) project(ArduinoJson VERSION 6.20.1)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest) include(CTest)
endif() endif()
add_subdirectory(src) add_subdirectory(src)

View File

@ -27,11 +27,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
if(${COVERAGE}) if(${COVERAGE})
set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage") set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage")
endif() endif()
endif() endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND (NOT ${COVERAGE})) if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND(NOT ${COVERAGE}))
add_compile_options(-g -Og) add_compile_options(-g -Og)
else() else()
add_compile_options(-g -O0) add_compile_options(-g -O0)
@ -65,7 +64,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif() endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND (NOT ${COVERAGE})) if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND(NOT ${COVERAGE}))
add_compile_options(-g -Og) add_compile_options(-g -Og)
else() else()
add_compile_options(-g -O0) add_compile_options(-g -O0)
@ -73,7 +72,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
endif() endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND (NOT ${COVERAGE})) if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0) AND(NOT ${COVERAGE}))
add_compile_options(-g -Og) add_compile_options(-g -Og)
else() else()
add_compile_options(-g -O0) add_compile_options(-g -O0)
@ -90,7 +89,7 @@ if(MSVC)
endif() endif()
if(MINGW) if(MINGW)
# Static link on MinGW to avoid linking with the wrong DLLs when multiple # Static link on MinGW to avoid linking with the wrong DLLs when multiple
# versions are installed. # versions are installed.
add_link_options(-static) add_link_options(-static)
endif() endif()

View File

@ -2,5 +2,7 @@
# Copyright © 2014-2022, Benoit BLANCHON # Copyright © 2014-2022, Benoit BLANCHON
# MIT License # MIT License
idf_component_register(SRCS "main.cpp" idf_component_register(
INCLUDE_DIRS "") SRCS "main.cpp"
INCLUDE_DIRS ""
)

View File

@ -22,7 +22,7 @@ target_link_libraries(json_reproducer
ArduinoJson ArduinoJson
) )
macro(add_fuzzer name) macro(add_fuzzer name)
set(FUZZER "${name}_fuzzer") set(FUZZER "${name}_fuzzer")
set(CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus") set(CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus")
set(SEED_CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_seed_corpus") set(SEED_CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_seed_corpus")
@ -33,27 +33,23 @@ macro(add_fuzzer name)
ArduinoJson ArduinoJson
) )
set_target_properties("${FUZZER}" set_target_properties("${FUZZER}"
PROPERTIES PROPERTIES
COMPILE_FLAGS COMPILE_FLAGS "-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
"-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all" LINK_FLAGS "-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
LINK_FLAGS
"-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
) )
add_test( add_test(
NAME NAME "${FUZZER}"
"${FUZZER}" COMMAND "${FUZZER}" "${CORPUS_DIR}" "${SEED_CORPUS_DIR}" -max_total_time=5 -timeout=1
COMMAND
"${FUZZER}" "${CORPUS_DIR}" "${SEED_CORPUS_DIR}" -max_total_time=5 -timeout=1
) )
set_tests_properties("${FUZZER}" set_tests_properties("${FUZZER}"
PROPERTIES PROPERTIES
LABELS "Fuzzing" LABELS "Fuzzing"
) )
endmacro() endmacro()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6)
add_fuzzer(json) add_fuzzer(json)
add_fuzzer(msgpack) add_fuzzer(msgpack)
endif() endif()

View File

@ -25,5 +25,5 @@ add_test(Cpp17 Cpp17Tests)
set_tests_properties(Cpp17 set_tests_properties(Cpp17
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -25,5 +25,5 @@ add_test(Cpp20 Cpp20Tests)
set_tests_properties(Cpp20 set_tests_properties(Cpp20
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -5,25 +5,21 @@
macro(build_should_fail target) macro(build_should_fail target)
set_target_properties(${target} set_target_properties(${target}
PROPERTIES PROPERTIES
EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_ALL TRUE
EXCLUDE_FROM_DEFAULT_BUILD TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE
) )
add_test( add_test(
NAME NAME ${target}
${target} COMMAND ${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION>
COMMAND WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION>
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}
) )
set_tests_properties(${target} set_tests_properties(${target}
PROPERTIES PROPERTIES
WILL_FAIL TRUE WILL_FAIL TRUE
LABELS "WillFail;Catch" LABELS "WillFail;Catch"
) )
endmacro() endmacro()
add_executable(Issue978 Issue978.cpp) add_executable(Issue978 Issue978.cpp)
build_should_fail(Issue978) build_should_fail(Issue978)

View File

@ -12,7 +12,7 @@ add_executable(IntegrationTests
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(IntegrationTests target_compile_options(IntegrationTests
PUBLIC PUBLIC
-fsingle-precision-constant # issue 544 -fsingle-precision-constant # issue 544
) )
endif() endif()
@ -20,5 +20,5 @@ add_test(IntegrationTests IntegrationTests)
set_tests_properties(IntegrationTests set_tests_properties(IntegrationTests
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -24,5 +24,5 @@ add_test(JsonArray JsonArrayTests)
set_tests_properties(JsonArray set_tests_properties(JsonArray
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -24,5 +24,5 @@ add_test(JsonDeserializer JsonDeserializerTests)
set_tests_properties(JsonDeserializer set_tests_properties(JsonDeserializer
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -28,5 +28,5 @@ add_test(JsonDocument JsonDocumentTests)
set_tests_properties(JsonDocument set_tests_properties(JsonDocument
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -25,5 +25,5 @@ add_test(JsonObject JsonObjectTests)
set_tests_properties(JsonObject set_tests_properties(JsonObject
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -18,5 +18,5 @@ add_test(JsonSerializer JsonSerializerTests)
set_tests_properties(JsonSerializer set_tests_properties(JsonSerializer
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -33,5 +33,5 @@ add_test(JsonVariant JsonVariantTests)
set_tests_properties(JsonVariant set_tests_properties(JsonVariant
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -2,7 +2,7 @@
# Copyright © 2014-2022, Benoit BLANCHON # Copyright © 2014-2022, Benoit BLANCHON
# MIT License # MIT License
add_executable(MemoryPoolTests add_executable(MemoryPoolTests
allocVariant.cpp allocVariant.cpp
clear.cpp clear.cpp
saveString.cpp saveString.cpp
@ -14,5 +14,5 @@ add_test(MemoryPool MemoryPoolTests)
set_tests_properties(MemoryPool set_tests_properties(MemoryPool
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -25,5 +25,5 @@ add_test(Misc MiscTests)
set_tests_properties(Misc set_tests_properties(Misc
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -29,5 +29,5 @@ add_test(MixedConfiguration MixedConfigurationTests)
set_tests_properties(MixedConfiguration set_tests_properties(MixedConfiguration
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -20,5 +20,5 @@ add_test(MsgPackDeserializer MsgPackDeserializerTests)
set_tests_properties(MsgPackDeserializer set_tests_properties(MsgPackDeserializer
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -15,5 +15,5 @@ add_test(MsgPackSerializer MsgPackSerializerTests)
set_tests_properties(MsgPackSerializer set_tests_properties(MsgPackSerializer
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -10,10 +10,9 @@ add_executable(NumbersTests
parseNumber.cpp parseNumber.cpp
) )
add_test(Numbers NumbersTests) add_test(Numbers NumbersTests)
set_tests_properties(Numbers set_tests_properties(Numbers
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -2,7 +2,7 @@
# Copyright © 2014-2022, Benoit BLANCHON # Copyright © 2014-2022, Benoit BLANCHON
# MIT License # MIT License
add_executable(TextFormatterTests add_executable(TextFormatterTests
writeFloat.cpp writeFloat.cpp
writeInteger.cpp writeInteger.cpp
writeString.cpp writeString.cpp
@ -14,5 +14,5 @@ add_test(TextFormatter TextFormatterTests)
set_tests_properties(TextFormatter set_tests_properties(TextFormatter
PROPERTIES PROPERTIES
LABELS "Catch" LABELS "Catch"
) )

View File

@ -12,7 +12,7 @@ add_library(catch
target_include_directories(catch target_include_directories(catch
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
if(MINGW) if(MINGW)

View File

@ -12,79 +12,80 @@ include(GNUInstallDirs)
# Adding the install interface generator expression makes sure that the include # Adding the install interface generator expression makes sure that the include
# files are installed to the proper location (provided by GNUInstallDirs) # files are installed to the proper location (provided by GNUInstallDirs)
target_include_directories(ArduinoJson target_include_directories(ArduinoJson
INTERFACE INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
) )
target_compile_definitions(ArduinoJson target_compile_definitions(ArduinoJson
INTERFACE INTERFACE
ARDUINOJSON_DEBUG=$<CONFIG:Debug> ARDUINOJSON_DEBUG=$<CONFIG:Debug>
) )
# locations are provided by GNUInstallDirs # locations are provided by GNUInstallDirs
install( install(
TARGETS TARGETS
ArduinoJson ArduinoJson
EXPORT EXPORT
ArduinoJson_Targets ArduinoJson_Targets
ARCHIVE DESTINATION ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR} ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR} ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR} ${CMAKE_INSTALL_BINDIR}
) )
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
if(${CMAKE_VERSION} VERSION_GREATER "3.14.0") if(${CMAKE_VERSION} VERSION_GREATER "3.14.0")
set(ARCH_INDEPENDENT "ARCH_INDEPENDENT") set(ARCH_INDEPENDENT "ARCH_INDEPENDENT")
endif() endif()
write_basic_package_version_file( write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/ArduinoJsonConfigVersion.cmake" "${PROJECT_BINARY_DIR}/ArduinoJsonConfigVersion.cmake"
VERSION VERSION
${PROJECT_VERSION} ${PROJECT_VERSION}
COMPATIBILITY COMPATIBILITY
SameMajorVersion SameMajorVersion
${ARCH_INDEPENDENT} ${ARCH_INDEPENDENT}
) )
configure_package_config_file( configure_package_config_file(
"${PROJECT_SOURCE_DIR}/extras/ArduinoJsonConfig.cmake.in" "${PROJECT_SOURCE_DIR}/extras/ArduinoJsonConfig.cmake.in"
"${PROJECT_BINARY_DIR}/ArduinoJsonConfig.cmake" "${PROJECT_BINARY_DIR}/ArduinoJsonConfig.cmake"
INSTALL_DESTINATION INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/ArduinoJson/cmake) ${CMAKE_INSTALL_DATAROOTDIR}/ArduinoJson/cmake
install(
EXPORT
ArduinoJson_Targets
FILE
ArduinoJsonTargets.cmake
DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/ArduinoJson/cmake
) )
install( install(
FILES EXPORT
"${PROJECT_BINARY_DIR}/ArduinoJsonConfig.cmake" ArduinoJson_Targets
"${PROJECT_BINARY_DIR}/ArduinoJsonConfigVersion.cmake" FILE
DESTINATION ArduinoJsonTargets.cmake
"${CMAKE_INSTALL_DATAROOTDIR}/ArduinoJson/cmake" DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/ArduinoJson/cmake
) )
install( install(
FILES FILES
ArduinoJson.h "${PROJECT_BINARY_DIR}/ArduinoJsonConfig.cmake"
ArduinoJson.hpp "${PROJECT_BINARY_DIR}/ArduinoJsonConfigVersion.cmake"
DESTINATION DESTINATION
include "${CMAKE_INSTALL_DATAROOTDIR}/ArduinoJson/cmake"
) )
install( install(
DIRECTORY FILES
"${CMAKE_CURRENT_SOURCE_DIR}/ArduinoJson" ArduinoJson.h
DESTINATION ArduinoJson.hpp
include DESTINATION
include
)
install(
DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/ArduinoJson"
DESTINATION
include
) )