summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2014-03-20 14:37:12 (GMT)
committerStephen Kelly <steveire@gmail.com>2014-04-02 21:12:57 (GMT)
commit5de63265e3a22d9a8aa5ad437a5030ccfcbcd02d (patch)
tree558694f9724c696198c6be2faff1a06f98fe6de6
parentaa0a3562dd47bdd6d9ca3058bd1dfd525e79d36d (diff)
downloadCMake-5de63265e3a22d9a8aa5ad437a5030ccfcbcd02d.zip
CMake-5de63265e3a22d9a8aa5ad437a5030ccfcbcd02d.tar.gz
CMake-5de63265e3a22d9a8aa5ad437a5030ccfcbcd02d.tar.bz2
Genex: Only evaluate TARGET_OBJECTS to determine target sources.
The output of this expression may contain macros for IDEs to replace such as $(Configuration), $(CURRENT_ARCH) etc. To avoid generating content which is not usable in other contexts, report an error if there is an attempt to use it in other contexts. This commit may be reverted in the future if a solution to the above difference is implemented.
-rw-r--r--Help/manual/cmake-generator-expressions.7.rst4
-rw-r--r--Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst6
-rw-r--r--Source/cmGeneratorExpression.cxx4
-rw-r--r--Source/cmGeneratorExpression.h6
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx10
-rw-r--r--Source/cmGeneratorExpressionEvaluator.h1
-rw-r--r--Source/cmTarget.cxx1
-rw-r--r--Tests/GeneratorExpression/CMakeLists.txt14
-rw-r--r--Tests/GeneratorExpression/check_object_files.cmake48
-rw-r--r--Tests/GeneratorExpression/objlib1.c5
-rw-r--r--Tests/GeneratorExpression/objlib2.c5
-rw-r--r--Tests/RunCMake/TargetObjects/BadContext-result.txt (renamed from Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt)0
-rw-r--r--Tests/RunCMake/TargetObjects/BadContext-stderr.txt17
-rw-r--r--Tests/RunCMake/TargetObjects/BadContext.cmake (renamed from Tests/RunCMake/TargetObjects/NoTarget.cmake)2
-rw-r--r--Tests/RunCMake/TargetObjects/NoTarget-result.txt1
-rw-r--r--Tests/RunCMake/TargetObjects/NoTarget-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake4
-rw-r--r--Tests/RunCMake/TargetObjects/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/TargetObjects/empty.cpp7
20 files changed, 44 insertions, 110 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst
index 17263d4..dfda8dc 100644
--- a/Help/manual/cmake-generator-expressions.7.rst
+++ b/Help/manual/cmake-generator-expressions.7.rst
@@ -190,4 +190,6 @@ property is non-empty::
Content of ``...`` converted to a C identifier.
``$<TARGET_OBJECTS:objLib>``
List of objects resulting from build of ``objLib``. ``objLib`` must be an
- object of type ``OBJECT_LIBRARY``.
+ object of type ``OBJECT_LIBRARY``. This expression may only be used in
+ the sources of :command:`add_library` and :command:`add_executable`
+ commands.
diff --git a/Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst b/Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst
deleted file mode 100644
index 853a803..0000000
--- a/Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst
+++ /dev/null
@@ -1,6 +0,0 @@
-file-GENERATE-TARGET_OBJECTS
-----------------------------
-
-* The :command:`file(GENERATE)` subcommand learned to evaluate the
- ``TARGET_OBJECTS``
- :manual:`generator expression <cmake-generator-expressions(7)>`.
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx
index e127f3a..d09e950 100644
--- a/Source/cmGeneratorExpression.cxx
+++ b/Source/cmGeneratorExpression.cxx
@@ -90,6 +90,7 @@ const char *cmCompiledGeneratorExpression::Evaluate(
context.HadError = false;
context.HadContextSensitiveCondition = false;
context.HeadTarget = headTarget;
+ context.EvaluateForBuildsystem = this->EvaluateForBuildsystem;
context.CurrentTarget = currentTarget ? currentTarget : headTarget;
context.Backtrace = this->Backtrace;
@@ -124,7 +125,8 @@ cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
cmListFileBacktrace const& backtrace,
const std::string& input)
: Backtrace(backtrace), Input(input),
- HadContextSensitiveCondition(false)
+ HadContextSensitiveCondition(false),
+ EvaluateForBuildsystem(false)
{
cmGeneratorExpressionLexer l;
std::vector<cmGeneratorExpressionToken> tokens =
diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h
index d0a6aef..da64515 100644
--- a/Source/cmGeneratorExpression.h
+++ b/Source/cmGeneratorExpression.h
@@ -112,6 +112,11 @@ public:
return this->HadContextSensitiveCondition;
}
+ void SetEvaluateForBuildsystem(bool eval)
+ {
+ this->EvaluateForBuildsystem = eval;
+ }
+
private:
cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
const std::string& input);
@@ -131,6 +136,7 @@ private:
mutable std::set<std::string> SeenTargetProperties;
mutable std::string Output;
mutable bool HadContextSensitiveCondition;
+ bool EvaluateForBuildsystem;
};
#endif
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
index 669694c..95227d2 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -1251,6 +1251,16 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
const GeneratorExpressionContent *content,
cmGeneratorExpressionDAGChecker *) const
{
+ if (!context->EvaluateForBuildsystem)
+ {
+ cmOStringStream e;
+ e << "The evaluation of the TARGET_OBJECTS generator expression "
+ "is only suitable for consumption by CMake. It is not suitable "
+ "for writing out elsewhere.";
+ reportError(context, content->GetOriginalExpression(), e.str());
+ return std::string();
+ }
+
std::string tgtName = parameters.front();
cmGeneratorTarget* gt =
context->Makefile->FindGeneratorTargetToUse(tgtName.c_str());
diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h
index a7099cb..54a2548 100644
--- a/Source/cmGeneratorExpressionEvaluator.h
+++ b/Source/cmGeneratorExpressionEvaluator.h
@@ -34,6 +34,7 @@ struct cmGeneratorExpressionContext
bool Quiet;
bool HadError;
bool HadContextSensitiveCondition;
+ bool EvaluateForBuildsystem;
};
struct cmGeneratorExpressionDAGChecker;
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 61260be..aeb477d 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -732,6 +732,7 @@ cmSourceFile* cmTarget::AddSource(const std::string& src)
this->Makefile->GetBacktrace(lfbt);
cmGeneratorExpression ge(lfbt);
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
+ cge->SetEvaluateForBuildsystem(true);
this->Internal->SourceEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(cge));
}
diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt
index b506853..758165c 100644
--- a/Tests/GeneratorExpression/CMakeLists.txt
+++ b/Tests/GeneratorExpression/CMakeLists.txt
@@ -258,17 +258,3 @@ set(CMP0044_TYPE NEW)
add_subdirectory(CMP0044 ${CMAKE_BINARY_DIR}/CMP0044-NEW)
set(CMP0044_TYPE OLD)
add_subdirectory(CMP0044 ${CMAKE_BINARY_DIR}/CMP0044-OLD)
-
-add_library(objlib OBJECT objlib1.c objlib2.c)
-file(GENERATE
- OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/objlib_files"
- CONTENT "$<JOIN:$<TARGET_OBJECTS:objlib>,\n>\n"
-)
-add_custom_target(check_object_files ALL
- COMMAND ${CMAKE_COMMAND}
- "-DOBJLIB_LISTFILE=${CMAKE_CURRENT_BINARY_DIR}/objlib_files"
- -DTEST_CONFIGURATION=${CMAKE_BUILD_TYPE}
- -DEXPECTED_NUM_OBJECTFILES=2
- -P "${CMAKE_CURRENT_SOURCE_DIR}/check_object_files.cmake"
- DEPENDS objlib
-)
diff --git a/Tests/GeneratorExpression/check_object_files.cmake b/Tests/GeneratorExpression/check_object_files.cmake
deleted file mode 100644
index 889fe80..0000000
--- a/Tests/GeneratorExpression/check_object_files.cmake
+++ /dev/null
@@ -1,48 +0,0 @@
-
-if (NOT EXISTS ${OBJLIB_LISTFILE})
- message(SEND_ERROR "Object listing file \"${OBJLIB_LISTFILE}\" not found!")
-endif()
-
-file(STRINGS ${OBJLIB_LISTFILE} objlib_files)
-
-list(LENGTH objlib_files num_objectfiles)
-if (NOT EXPECTED_NUM_OBJECTFILES EQUAL num_objectfiles)
- message(SEND_ERROR "Unexpected number of entries in object list file (${num_objectfiles} instead of ${EXPECTED_NUM_OBJECTFILES})")
-endif()
-
-foreach(objlib_file ${objlib_files})
- set(file_exists False)
- if (EXISTS ${objlib_file})
- set(file_exists True)
- endif()
-
- if (NOT file_exists)
- if (objlib_file MATCHES ".(CURRENT_ARCH)")
- string(REPLACE "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" "*" config_file "${objlib_file}")
- string(REPLACE "$(PROJECT_NAME)" "GeneratorExpression" config_file "${config_file}")
- string(REPLACE "$(CURRENT_ARCH)" "*" config_file "${config_file}")
- file(GLOB_RECURSE files "${config_file}")
- list(LENGTH files num_files)
- if (NOT files)
- message(SEND_ERROR "Got no files for expression ${config_file}")
- endif()
- set(file_exists True)
- else()
- foreach(config_macro "$(Configuration)" "$(OutDir)" "$(IntDir)")
- string(REPLACE "${config_macro}" "${TEST_CONFIGURATION}" config_file "${objlib_file}")
- list(APPEND attempts ${config_file})
- if (EXISTS ${config_file})
- set(file_exists True)
- endif()
- endforeach()
- endif()
- endif()
-
- if (NOT file_exists)
- if(attempts)
- list(REMOVE_DUPLICATES attempts)
- set(tried " Tried ${attempts}")
- endif()
- message(SEND_ERROR "File \"${objlib_file}\" does not exist!${tried}")
- endif()
-endforeach()
diff --git a/Tests/GeneratorExpression/objlib1.c b/Tests/GeneratorExpression/objlib1.c
deleted file mode 100644
index aa8de0a..0000000
--- a/Tests/GeneratorExpression/objlib1.c
+++ /dev/null
@@ -1,5 +0,0 @@
-
-void objlib1()
-{
-
-}
diff --git a/Tests/GeneratorExpression/objlib2.c b/Tests/GeneratorExpression/objlib2.c
deleted file mode 100644
index 3c7307a..0000000
--- a/Tests/GeneratorExpression/objlib2.c
+++ /dev/null
@@ -1,5 +0,0 @@
-
-void objlib2()
-{
-
-}
diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt b/Tests/RunCMake/TargetObjects/BadContext-result.txt
index d00491f..d00491f 100644
--- a/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt
+++ b/Tests/RunCMake/TargetObjects/BadContext-result.txt
diff --git a/Tests/RunCMake/TargetObjects/BadContext-stderr.txt b/Tests/RunCMake/TargetObjects/BadContext-stderr.txt
new file mode 100644
index 0000000..92f2c91
--- /dev/null
+++ b/Tests/RunCMake/TargetObjects/BadContext-stderr.txt
@@ -0,0 +1,17 @@
+CMake Error at BadContext.cmake:2 \(file\):
+ Error evaluating generator expression:
+
+ \$<TARGET_OBJECTS:NoTarget>
+
+ The evaluation of the TARGET_OBJECTS generator expression is only suitable
+ for consumption by CMake. It is not suitable for writing out elsewhere.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_OBJECTS:NoTarget>
+
+ The evaluation of the TARGET_OBJECTS generator expression is only suitable
+ for consumption by CMake. It is not suitable for writing out elsewhere.
diff --git a/Tests/RunCMake/TargetObjects/NoTarget.cmake b/Tests/RunCMake/TargetObjects/BadContext.cmake
index f203c23..67962a4 100644
--- a/Tests/RunCMake/TargetObjects/NoTarget.cmake
+++ b/Tests/RunCMake/TargetObjects/BadContext.cmake
@@ -1,2 +1,4 @@
file(GENERATE OUTPUT test_output CONTENT $<TARGET_OBJECTS:NoTarget>)
+
+install(FILES $<TARGET_OBJECTS:NoTarget> DESTINATION objects)
diff --git a/Tests/RunCMake/TargetObjects/NoTarget-result.txt b/Tests/RunCMake/TargetObjects/NoTarget-result.txt
deleted file mode 100644
index d00491f..0000000
--- a/Tests/RunCMake/TargetObjects/NoTarget-result.txt
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt b/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt
deleted file mode 100644
index 2c4f877..0000000
--- a/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-CMake Error at NoTarget.cmake:2 \(file\):
- Error evaluating generator expression:
-
- \$<TARGET_OBJECTS:NoTarget>
-
- Objects of target "NoTarget" referenced but no such target exists.
-Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt b/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt
deleted file mode 100644
index bb83934..0000000
--- a/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-CMake Error at NotObjlibTarget.cmake:4 \(file\):
- Error evaluating generator expression:
-
- \$<TARGET_OBJECTS:StaticLib>
-
- Objects of target "StaticLib" referenced but is not an OBJECT library.
-Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake
deleted file mode 100644
index c7f8a71..0000000
--- a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake
+++ /dev/null
@@ -1,4 +0,0 @@
-
-add_library(StaticLib empty.cpp)
-
-file(GENERATE OUTPUT test_output CONTENT $<TARGET_OBJECTS:StaticLib>)
diff --git a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake
index 30b9fee..85c76e2 100644
--- a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake
+++ b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake
@@ -1,4 +1,3 @@
include(RunCMake)
-run_cmake(NoTarget)
-run_cmake(NotObjlibTarget)
+run_cmake(BadContext)
diff --git a/Tests/RunCMake/TargetObjects/empty.cpp b/Tests/RunCMake/TargetObjects/empty.cpp
deleted file mode 100644
index bfbbdde..0000000
--- a/Tests/RunCMake/TargetObjects/empty.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifdef _WIN32
-__declspec(dllexport)
-#endif
-int empty()
-{
- return 0;
-}