mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 08:20:18 -06:00
try_compile: Rename SOURCE_FROM_ARG -> SOURCE_FROM_CONTENT
Change the SOURCE_FROM_ARG keyword to try_compile to SOURCE_FROM_CONTENT (which we can do because it was recently added and hasn't been in a release yet). The new name should be clearer as to what it does, and also more consistent with the CONTENT arguments to some other commands. Also, fix a typo in an error message.
This commit is contained in:
@@ -59,10 +59,10 @@ Try Compiling Source Files
|
||||
.. code-block:: cmake
|
||||
|
||||
try_compile(<resultVar>
|
||||
<SOURCES <srcfile...>] |
|
||||
SOURCE_FROM_ARG <name> <content>] |
|
||||
SOURCE_FROM_VAR <name> <var>] |
|
||||
SOURCE_FROM_FILE <name> <path> >...
|
||||
<SOURCES <srcfile...>] |
|
||||
SOURCE_FROM_CONTENT <name> <content>] |
|
||||
SOURCE_FROM_VAR <name> <var>] |
|
||||
SOURCE_FROM_FILE <name> <path> >...
|
||||
[NO_CACHE]
|
||||
[CMAKE_FLAGS <flags>...]
|
||||
[COMPILE_DEFINITIONS <defs>...]
|
||||
@@ -194,7 +194,7 @@ The options are:
|
||||
``OUTPUT_VARIABLE <var>``
|
||||
Store the output from the build process in the given variable.
|
||||
|
||||
``SOURCE_FROM_ARG <name> <content>``
|
||||
``SOURCE_FROM_CONTENT <name> <content>``
|
||||
.. versionadded:: 3.25
|
||||
|
||||
Write ``<content>`` to a file named ``<name>`` in the operation directory.
|
||||
@@ -202,7 +202,7 @@ The options are:
|
||||
the contents of the file are dynamically specified. The specified ``<name>``
|
||||
is not allowed to contain path components.
|
||||
|
||||
``SOURCE_FROM_ARG`` may be specified multiple times.
|
||||
``SOURCE_FROM_CONTENT`` may be specified multiple times.
|
||||
|
||||
``SOURCE_FROM_FILE <name> <path>``
|
||||
.. versionadded:: 3.25
|
||||
@@ -218,10 +218,11 @@ The options are:
|
||||
.. versionadded:: 3.25
|
||||
|
||||
Write the contents of ``<var>`` to a file named ``<name>`` in the operation
|
||||
directory. This is the same as ``SOURCE_FROM_ARG``, but takes the contents
|
||||
from the specified CMake variable, rather than directly, which may be useful
|
||||
when passing arguments through a function which wraps ``try_compile``. The
|
||||
specified ``<name>`` is not allowed to contain path components.
|
||||
directory. This is the same as ``SOURCE_FROM_CONTENT``, but takes the
|
||||
contents from the specified CMake variable, rather than directly, which may
|
||||
be useful when passing arguments through a function which wraps
|
||||
``try_compile``. The specified ``<name>`` is not allowed to contain path
|
||||
components.
|
||||
|
||||
``SOURCE_FROM_VAR`` may be specified multiple times.
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ Try Compiling and Running Source Files
|
||||
.. code-block:: cmake
|
||||
|
||||
try_run(<runResultVar> <compileResultVar>
|
||||
<SOURCES <srcfile...>] |
|
||||
SOURCE_FROM_ARG <name> <content>] |
|
||||
SOURCE_FROM_VAR <name> <var>] |
|
||||
SOURCE_FROM_FILE <name> <path> >...
|
||||
<SOURCES <srcfile...>] |
|
||||
SOURCE_FROM_CONTENT <name> <content>] |
|
||||
SOURCE_FROM_VAR <name> <var>] |
|
||||
SOURCE_FROM_FILE <name> <path> >...
|
||||
[NO_CACHE]
|
||||
[CMAKE_FLAGS <flags>...]
|
||||
[COMPILE_DEFINITIONS <defs>...]
|
||||
|
||||
@@ -173,7 +173,7 @@ auto const TryCompileBaseSourcesArgParser =
|
||||
|
||||
auto const TryCompileBaseNewSourcesArgParser =
|
||||
cmArgumentParser<Arguments>{ TryCompileBaseSourcesArgParser }
|
||||
.Bind("SOURCE_FROM_ARG"_s, &Arguments::SourceFromArg)
|
||||
.Bind("SOURCE_FROM_CONTENT"_s, &Arguments::SourceFromContent)
|
||||
.Bind("SOURCE_FROM_VAR"_s, &Arguments::SourceFromVar)
|
||||
.Bind("SOURCE_FROM_FILE"_s, &Arguments::SourceFromFile)
|
||||
/* keep semicolon on own line */;
|
||||
@@ -402,10 +402,11 @@ bool cmCoreTryCompile::TryCompileCode(Arguments& arguments,
|
||||
}
|
||||
|
||||
if (this->SrcFileSignature) {
|
||||
if (arguments.SourceFromArg && arguments.SourceFromArg->size() % 2) {
|
||||
if (arguments.SourceFromContent &&
|
||||
arguments.SourceFromContent->size() % 2) {
|
||||
this->Makefile->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
"SOURCE_FROM_ARG requires exactly two arguments");
|
||||
"SOURCE_FROM_CONTENT requires exactly two arguments");
|
||||
return false;
|
||||
}
|
||||
if (arguments.SourceFromVar && arguments.SourceFromVar->size() % 2) {
|
||||
@@ -476,12 +477,12 @@ bool cmCoreTryCompile::TryCompileCode(Arguments& arguments,
|
||||
} else if (arguments.SourceDirectoryOrFile) {
|
||||
sources.emplace_back(*arguments.SourceDirectoryOrFile);
|
||||
}
|
||||
if (arguments.SourceFromArg) {
|
||||
auto const k = arguments.SourceFromArg->size();
|
||||
if (arguments.SourceFromContent) {
|
||||
auto const k = arguments.SourceFromContent->size();
|
||||
for (auto i = decltype(k){ 0 }; i < k; i += 2) {
|
||||
const auto& name = (*arguments.SourceFromArg)[i + 0];
|
||||
const auto& content = (*arguments.SourceFromArg)[i + 1];
|
||||
auto out = this->WriteSource(name, content, "SOURCES_FROM_ARG");
|
||||
const auto& name = (*arguments.SourceFromContent)[i + 0];
|
||||
const auto& content = (*arguments.SourceFromContent)[i + 1];
|
||||
auto out = this->WriteSource(name, content, "SOURCE_FROM_CONTENT");
|
||||
if (out.empty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -494,7 +495,7 @@ bool cmCoreTryCompile::TryCompileCode(Arguments& arguments,
|
||||
const auto& name = (*arguments.SourceFromVar)[i + 0];
|
||||
const auto& var = (*arguments.SourceFromVar)[i + 1];
|
||||
const auto& content = this->Makefile->GetDefinition(var);
|
||||
auto out = this->WriteSource(name, content, "SOURCES_FROM_VAR");
|
||||
auto out = this->WriteSource(name, content, "SOURCE_FROM_VAR");
|
||||
if (out.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
cm::optional<std::string> TargetName;
|
||||
cm::optional<ArgumentParser::NonEmpty<std::vector<std::string>>> Sources;
|
||||
cm::optional<ArgumentParser::NonEmpty<std::vector<std::string>>>
|
||||
SourceFromArg;
|
||||
SourceFromContent;
|
||||
cm::optional<ArgumentParser::NonEmpty<std::vector<std::string>>>
|
||||
SourceFromVar;
|
||||
cm::optional<ArgumentParser::NonEmpty<std::vector<std::string>>>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CMake Error at SourceFromBadName.cmake:[0-9]+ \(try_compile\):
|
||||
SOURCES_FROM_ARG given invalid filename "bad/name.c"
|
||||
SOURCE_FROM_CONTENT given invalid filename "bad/name.c"
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
||||
@@ -1 +1 @@
|
||||
try_compile(RESULT SOURCE_FROM_ARG bad/name.c "int main();")
|
||||
try_compile(RESULT SOURCE_FROM_CONTENT bad/name.c "int main();")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CMake Error at SourceFromOneArg.cmake:[0-9]+ \(try_compile\):
|
||||
SOURCE_FROM_ARG requires exactly two arguments
|
||||
SOURCE_FROM_CONTENT requires exactly two arguments
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
||||
@@ -1 +1 @@
|
||||
try_compile(RESULT SOURCE_FROM_ARG test.c)
|
||||
try_compile(RESULT SOURCE_FROM_CONTENT test.c)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CMake Error at SourceFromThreeArgs.cmake:[0-9]+ \(try_compile\):
|
||||
SOURCE_FROM_ARG requires exactly two arguments
|
||||
SOURCE_FROM_CONTENT requires exactly two arguments
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
||||
@@ -1 +1 @@
|
||||
try_compile(RESULT SOURCE_FROM_ARG test.c "int" "main();")
|
||||
try_compile(RESULT SOURCE_FROM_CONTENT test.c "int" "main();")
|
||||
|
||||
@@ -78,7 +78,7 @@ include(old_and_new_signature_tests.cmake)
|
||||
|
||||
# try to compile an empty source specified directly
|
||||
try_compile(SHOULD_FAIL_DUE_TO_EMPTY_SOURCE
|
||||
SOURCE_FROM_ARG empty.c "")
|
||||
SOURCE_FROM_CONTENT empty.c "")
|
||||
if(SHOULD_FAIL_DUE_TO_EMPTY_SOURCE)
|
||||
message(SEND_ERROR "Trying to compile an empty source succeeded?")
|
||||
endif()
|
||||
@@ -103,11 +103,11 @@ set(TRY_RUN_EXT_CODE
|
||||
"int answer() { return 42; }\n")
|
||||
|
||||
try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
|
||||
SOURCE_FROM_ARG main.c "${TRY_RUN_MAIN_CODE}"
|
||||
SOURCE_FROM_ARG answer.c "${TRY_RUN_EXT_CODE}"
|
||||
SOURCE_FROM_CONTENT main.c "${TRY_RUN_MAIN_CODE}"
|
||||
SOURCE_FROM_CONTENT answer.c "${TRY_RUN_EXT_CODE}"
|
||||
COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT)
|
||||
EXPECT_COMPILED("SOURCE_FROM_ARG" SHOULD_COMPILE "${COMPILE_OUTPUT}")
|
||||
EXPECT_RUN_RESULT("SOURCE_FROM_ARG" SHOULD_EXIT_WITH_ERROR 42)
|
||||
EXPECT_COMPILED("SOURCE_FROM_CONTENT" SHOULD_COMPILE "${COMPILE_OUTPUT}")
|
||||
EXPECT_RUN_RESULT("SOURCE_FROM_CONTENT" SHOULD_EXIT_WITH_ERROR 42)
|
||||
|
||||
try_run(SHOULD_EXIT_WITH_ERROR SHOULD_COMPILE
|
||||
SOURCE_FROM_VAR main.c TRY_RUN_MAIN_CODE
|
||||
|
||||
Reference in New Issue
Block a user