Files
toml11/tests/CMakeLists.txt

234 lines
8.8 KiB
CMake
Raw Normal View History

include(ExternalProject)
ExternalProject_Add(toml
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/toml
GIT_REPOSITORY https://github.com/toml-lang/toml
GIT_TAG v0.5.0
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND "")
2017-04-19 22:47:40 +09:00
set(TEST_NAMES
2018-12-11 21:51:39 +09:00
test_datetime
2019-06-29 20:20:31 +09:00
test_string
2018-12-11 21:51:39 +09:00
test_utility
test_result
test_traits
test_value
2018-12-04 20:30:21 +09:00
test_lex_boolean
test_lex_integer
test_lex_floating
test_lex_datetime
test_lex_string
test_lex_key_comment
2018-12-11 21:51:39 +09:00
test_parse_boolean
test_parse_integer
test_parse_floating
2018-12-11 23:25:44 +09:00
test_parse_string
2018-12-12 20:55:30 +09:00
test_parse_datetime
2018-12-11 23:31:24 +09:00
test_parse_array
2018-12-13 13:07:48 +09:00
test_parse_table
2018-12-11 23:38:57 +09:00
test_parse_inline_table
2018-12-11 23:25:44 +09:00
test_parse_key
2018-12-12 01:31:36 +09:00
test_parse_table_key
2019-03-20 00:36:46 +09:00
test_literals
2019-06-15 17:13:25 +09:00
test_comments
2018-12-12 17:23:06 +09:00
test_get
2019-06-22 16:39:01 +09:00
test_get_or
2019-06-20 14:34:14 +09:00
test_find
2019-06-22 16:58:45 +09:00
test_find_or
2019-06-22 16:59:21 +09:00
test_expect
test_parse_file
2019-02-13 13:51:36 +09:00
test_serialize_file
test_parse_unicode
test_error_detection
test_format_error
test_extended_conversions
)
2017-04-19 22:47:40 +09:00
CHECK_CXX_COMPILER_FLAG("-Wall" COMPILER_SUPPORTS_WALL)
CHECK_CXX_COMPILER_FLAG("-Wextra" COMPILER_SUPPORTS_WEXTRA)
CHECK_CXX_COMPILER_FLAG("-Wpedantic" COMPILER_SUPPORTS_WPEDANTIC)
CHECK_CXX_COMPILER_FLAG("-Werror" COMPILER_SUPPORTS_WERROR)
2020-01-13 00:16:33 +09:00
CHECK_CXX_COMPILER_FLAG("-Wsign-conversion" COMPILER_SUPPORTS_WSIGN_CONVERSION)
CHECK_CXX_COMPILER_FLAG("-Wconversion" COMPILER_SUPPORTS_WCONVERSION)
CHECK_CXX_COMPILER_FLAG("-Wduplicated-cond" COMPILER_SUPPORTS_WDUPLICATED_COND)
CHECK_CXX_COMPILER_FLAG("-Wduplicated-branches" COMPILER_SUPPORTS_WDUPLICATED_BRANCHES)
CHECK_CXX_COMPILER_FLAG("-Wlogical-op" COMPILER_SUPPORTS_WLOGICAL_OP)
CHECK_CXX_COMPILER_FLAG("-Wuseless-cast" COMPILER_SUPPORTS_WUSELESS_CAST)
CHECK_CXX_COMPILER_FLAG("-Wdouble-promotion" COMPILER_SUPPORTS_WDOUBLE_PROMOTION)
CHECK_CXX_COMPILER_FLAG("-Wrange-loop-analysis" COMPILER_SUPPORTS_WRANGE_LOOP_ANALYSIS)
2020-02-11 06:25:10 -06:00
CHECK_CXX_COMPILER_FLAG("-Wundef" COMPILER_SUPPORTS_WUNDEF)
CHECK_CXX_COMPILER_FLAG("-Wshadow" COMPILER_SUPPORTS_WSHADOW)
2020-01-13 00:16:33 +09:00
if(COMPILER_SUPPORTS_WALL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
if(COMPILER_SUPPORTS_WEXTRA)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
endif()
if(COMPILER_SUPPORTS_WPEDANTIC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic")
endif()
if(COMPILER_SUPPORTS_WERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()
if(COMPILER_SUPPORTS_WSHADOW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
2021-05-04 17:50:14 +09:00
endif()
2020-01-13 00:16:33 +09:00
if(COMPILER_SUPPORTS_WSIGN_CONVERSION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion")
endif()
if(COMPILER_SUPPORTS_WCONVERSION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion")
endif()
if(COMPILER_SUPPORTS_WDUPLICATED_COND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wduplicated-cond")
endif()
if(COMPILER_SUPPORTS_WDUPLICATED_BRANCHES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wduplicated-branches")
endif()
if(COMPILER_SUPPORTS_WLOGICAL_OP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op")
endif()
if(COMPILER_SUPPORTS_WUSELESS_CAST)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuseless-cast")
endif()
if(COMPILER_SUPPORTS_WDOUBLE_PROMOTION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion")
endif()
if(COMPILER_SUPPORTS_WRANGE_LOOP_ANALYSIS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wrange-loop-analysis")
endif()
2020-02-11 06:25:10 -06:00
if(COMPILER_SUPPORTS_WUNDEF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wundef")
endif()
2017-04-19 22:47:40 +09:00
option(TOML11_USE_UNRELEASED_TOML_FEATURES
"use features in toml-lang/toml master while testing" OFF)
if(TOML11_USE_UNRELEASED_TOML_FEATURES)
message(STATUS "adding TOML11_USE_UNRELEASED_TOML_FEATURES flag")
add_definitions("-DTOML11_USE_UNRELEASED_TOML_FEATURES")
endif()
2017-05-15 11:38:46 +02:00
# Disable some MSVC warnings
if(MSVC)
# conversion from 'double' to 'unsigned int', possible loss of data
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244")
# conversion from 'int' to 'unsigned int', signed/unsigned mismatch
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4365")
# layout of class may have changed from a previous version of the compiler
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4371")
# enumerator in switch of enum is not explicitly handled by a case label
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4061")
# unreferenced inline function has been removed
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4514")
# constructor is not implicitly called
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4582")
# destructor is not implicitly called
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4583")
# pragma warning: there is no warning number <x>
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4619")
# default constructor was implicitly defined as deleted
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4623")
# copy constructor was implicitly defined as deleted
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4625")
# assignment operator was implicitly defined as deleted
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4626")
# move assignment operator was implicitly defined as deleted
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4627")
# <X> is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4668")
# function not inlined
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4710")
# function selected for automatic inlining
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4711")
# <x> bytes padding added after data member
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4820")
# pragma warning(pop): likely mismatch, popping warning state pushed in different file
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd5031")
endif()
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
add_definitions(-DBOOST_TEST_DYN_LINK)
add_definitions(-DUNITTEST_FRAMEWORK_LIBRARY_EXIST)
2017-04-19 22:47:40 +09:00
# check which standard library implementation is used. If libstdc++ is used,
# it will fail to compile. It compiles if libc++ is used.
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#include <cstddef>
#ifdef __GLIBCXX__
static_assert(false);
#endif
int main() {
return 0;
}" TOML11_WITH_LIBCXX_LIBRARY)
# LLVM 8 requires -lc++fs if compiled with libc++ to use <filesystem>.
# LLVM 9+ does not require any special library.
# GCC 8 requires -lstdc++fs. GCC 9+ does not require it.
#
# Yes, we can check the version of the compiler used in the current build
# directly in CMake. But, in most cases, clang build uses libstdc++ as the
# standard library implementation and it makes the condition complicated.
# In many environment, the default installed C++ compiler is GCC and libstdc++
# is installed along with it. In most build on such an environment, even if we
# chose clang as the C++ compiler, still libstdc++ is used. Checking default
# gcc version makes the condition complicated.
# The purpose of this file is to compile tests. We know the environment on which
# the tests run. We can set this option and, I think, it is easier and better.
option(TOML11_REQUIRE_FILESYSTEM_LIBRARY "need to link -lstdc++fs or -lc++fs" OFF)
2017-04-19 22:47:40 +09:00
foreach(TEST_NAME ${TEST_NAMES})
add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
target_link_libraries(${TEST_NAME} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} toml11::toml11)
# to compile tests with <filesystem>...
if(TOML11_REQUIRE_FILESYSTEM_LIBRARY)
if(TOML11_WITH_LIBCXX_LIBRARY)
target_link_libraries(${TEST_NAME} "c++fs")
else()
target_link_libraries(${TEST_NAME} "stdc++fs")
endif()
endif()
target_include_directories(${TEST_NAME} PRIVATE ${Boost_INCLUDE_DIRS})
2020-01-08 23:07:05 +09:00
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(toml11_TEST_WITH_ASAN)
set_target_properties(${TEST_NAME} PROPERTIES
COMPILE_FLAGS "-fsanitize=address -fno-omit-frame-pointer"
LINK_FLAGS "-fsanitize=address -fno-omit-frame-pointer")
elseif(toml11_TEST_WITH_UBSAN)
set_target_properties(${TEST_NAME} PROPERTIES
COMPILE_FLAGS "-fsanitize=undefined"
LINK_FLAGS "-fsanitize=undefined")
endif()
endif()
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
2017-05-15 14:00:51 +02:00
# Set the PATH to be able to find Boost DLL
if(WIN32)
STRING(REPLACE ";" "\\;" PATH_STRING "$ENV{PATH}")
set_tests_properties(${TEST_NAME}
PROPERTIES ENVIRONMENT "PATH=${PATH_STRING}\;${Boost_LIBRARY_DIRS}"
)
endif()
2017-04-19 22:47:40 +09:00
endforeach(TEST_NAME)
# this test is to check it compiles. it will not run
add_executable(test_multiple_translation_unit
test_multiple_translation_unit_1.cpp
test_multiple_translation_unit_2.cpp)
2019-06-19 16:53:45 +09:00
target_link_libraries(test_multiple_translation_unit toml11::toml11)
2020-07-10 15:11:14 +09:00
if(WIN32)
add_executable(test_windows test_windows.cpp)
target_link_libraries(test_windows toml11::toml11)
endif()