2014-08-09 16:04:38 +00:00
|
|
|
# Test if compile errors are produced where necessary.
|
|
|
|
|
2018-06-06 13:57:59 +00:00
|
|
|
cmake_minimum_required(VERSION 3.1.0)
|
2014-08-09 16:04:38 +00:00
|
|
|
|
|
|
|
include(CheckCXXSourceCompiles)
|
2018-06-06 13:57:59 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
2017-10-21 15:17:00 +00:00
|
|
|
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
|
2018-06-06 13:57:59 +00:00
|
|
|
set(CMAKE_REQUIRED_FLAGS ${CXX_STANDARD_FLAG} ${PEDANTIC_COMPILE_FLAGS})
|
2014-08-09 16:04:38 +00:00
|
|
|
|
2016-01-30 22:49:39 +00:00
|
|
|
function (generate_source result fragment)
|
|
|
|
set(${result} "
|
|
|
|
#define FMT_HEADER_ONLY 1
|
2018-05-19 14:14:13 +00:00
|
|
|
#include \"fmt/format.h\"
|
2014-08-09 16:04:38 +00:00
|
|
|
int main() {
|
2016-01-30 22:49:39 +00:00
|
|
|
${fragment}
|
2014-08-09 16:04:38 +00:00
|
|
|
}
|
2016-01-30 22:49:39 +00:00
|
|
|
" PARENT_SCOPE)
|
|
|
|
endfunction ()
|
|
|
|
|
|
|
|
function (expect_compile code)
|
|
|
|
generate_source(source "${code}")
|
|
|
|
check_cxx_source_compiles("${source}" compiles)
|
|
|
|
if (NOT compiles)
|
2016-05-03 22:33:29 +00:00
|
|
|
set(error_msg "Compile error for: ${code}")
|
2016-01-30 22:49:39 +00:00
|
|
|
endif ()
|
2014-08-09 16:04:38 +00:00
|
|
|
# Unset the CMake cache variable compiles. Otherwise the compile test will
|
|
|
|
# just use cached information next time it runs.
|
|
|
|
unset(compiles CACHE)
|
2016-05-03 22:33:29 +00:00
|
|
|
if (error_msg)
|
|
|
|
message(FATAL_ERROR ${error_msg})
|
|
|
|
endif ()
|
2016-01-30 22:49:39 +00:00
|
|
|
endfunction ()
|
|
|
|
|
|
|
|
function (expect_compile_error code)
|
|
|
|
generate_source(source "${code}")
|
|
|
|
check_cxx_source_compiles("${source}" compiles)
|
|
|
|
if (compiles)
|
2016-05-03 22:33:29 +00:00
|
|
|
set(error_msg "No compile error for: ${code}")
|
2014-08-09 16:04:38 +00:00
|
|
|
endif ()
|
2016-01-30 22:49:39 +00:00
|
|
|
# Unset the CMake cache variable compiles. Otherwise the compile test will
|
|
|
|
# just use cached information next time it runs.
|
|
|
|
unset(compiles CACHE)
|
2016-05-03 22:33:29 +00:00
|
|
|
if (error_msg)
|
|
|
|
message(FATAL_ERROR ${error_msg})
|
|
|
|
endif ()
|
2014-08-09 16:04:38 +00:00
|
|
|
endfunction ()
|
|
|
|
|
2016-01-30 22:49:39 +00:00
|
|
|
# check if the source file skeleton compiles
|
|
|
|
expect_compile("")
|
|
|
|
|
2014-08-09 16:04:38 +00:00
|
|
|
# Formatting a wide character with a narrow format string is forbidden.
|
2018-03-27 17:39:03 +00:00
|
|
|
expect_compile_error("fmt::format(\"{}\", L'a');")
|
2014-09-12 19:05:32 +00:00
|
|
|
|
2018-03-10 14:46:41 +00:00
|
|
|
# Formatting a wide string with a narrow format string is forbidden.
|
2018-03-27 17:39:03 +00:00
|
|
|
expect_compile_error("fmt::format(\"{}\", L\"foo\");")
|
2018-03-10 14:46:41 +00:00
|
|
|
|
2018-03-30 19:29:47 +00:00
|
|
|
# Formatting a narrow string with a wide format string is forbidden because
|
|
|
|
# mixing UTF-8 with UTF-16/32 can result in an invalid output.
|
|
|
|
expect_compile_error("fmt::format(L\"{}\", \"foo\");")
|
|
|
|
|
2018-05-19 14:14:13 +00:00
|
|
|
# Formatting a wide string with a narrow format string is forbidden.
|
|
|
|
expect_compile_error("
|
|
|
|
struct S {
|
|
|
|
operator std::string() const { return std::string(); }
|
|
|
|
};
|
|
|
|
fmt::format(\"{}\", S());
|
|
|
|
")
|
|
|
|
|
2016-05-02 21:51:37 +00:00
|
|
|
# Make sure that compiler features detected in the header
|
|
|
|
# match the features detected in CMake.
|
|
|
|
if (SUPPORTS_USER_DEFINED_LITERALS)
|
|
|
|
set(supports_udl 1)
|
|
|
|
else ()
|
|
|
|
set(supports_udl 0)
|
|
|
|
endif ()
|
|
|
|
expect_compile("#if FMT_USE_USER_DEFINED_LITERALS != ${supports_udl}
|
|
|
|
# error
|
|
|
|
#endif")
|