try_compile: Preserve special characters in COMPILE_DEFINITIONS

When generating the `CMakeLists.txt` file, we pass the values given
to our `COMPILE_DEFINITIONS` option in an `add_definitions` call.
Pass them as bracket arguments to preserve special characters
like `#`.
This commit is contained in:
Brad King 2019-01-21 10:07:20 -05:00
parent 15ad830062
commit 8c5221fb1f

View File

@ -599,7 +599,9 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
fprintf(fout, "link_directories(${LINK_DIRECTORIES})\n");
// handle any compile flags we need to pass on
if (!compileDefs.empty()) {
fprintf(fout, "add_definitions(%s)\n", cmJoin(compileDefs, " ").c_str());
// Pass using bracket arguments to preserve content.
fprintf(fout, "add_definitions([==[%s]==])\n",
cmJoin(compileDefs, "]==] [==[").c_str());
}
/* Use a random file name to avoid rapid creation and deletion