[CMake] check_cxx_symbol_exists for std::literals works in one project, not in another
Martijn Otto
motto at transip.nl
Tue Oct 17 04:53:17 EDT 2017
Hi,
I'm struggling to understand the following behaviour. I need to test
whether std::literals is available in my project, for which I have the
following test:
SET(CMAKE_REQUIRED_FLAGS "-std=c++14")
check_cxx_symbol_exists("std::literals::string_literals::operator\"\"s(
const char*, std::size_t)" "string" HAVE_STD_LITERALS)
I then use the resulting HAVE_STD_LITERALS to configure an include
file. In one project this works well, in another it does not. The
project where it does work generates the following test file:
#include <string>
int main() {
#ifndef std::literals::string_literals::operator""s
const char* arg0;
std::size_t arg1;
(void)std::literals::string_literals::operator""s(arg0, arg1);
#endif
return 0;
}
This compiles with only a warning about extra tokens after the #ifndef
directive. In another project I try to use the same and it never
detects support, because it generates different test-code, that doesn't
compile at all:
/* */
#include <string>
int main(int argc, char** argv)
{
(void)argv;
#ifndef std::literals::string_literals::operator""s(const char*,
std::size_t)
return ((int*)(&std::literals::string_literals::operator""s(const
char*, std::size_t)))[argc];
#else
(void)argc;
return 0;
#endif
}
Can anybody explain why different code is generated and how I can avoid
generating this incorrect code?
With regards,
Martijn Otto
More information about the CMake
mailing list