diff options
author | Brad King <brad.king@kitware.com> | 2017-10-25 12:11:03 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2017-10-25 12:11:19 (GMT) |
commit | b5dd256d948947467b3059218a9347d0cf2c513b (patch) | |
tree | c26dff384b0716296217a44433a15eef8e4508c0 | |
parent | 53d8be41183e663d340c0bc210dfe1f4ec97e711 (diff) | |
parent | 4e7f67383f297d708efbb6640c9bee188a127d4e (diff) | |
download | CMake-b5dd256d948947467b3059218a9347d0cf2c513b.zip CMake-b5dd256d948947467b3059218a9347d0cf2c513b.tar.gz CMake-b5dd256d948947467b3059218a9347d0cf2c513b.tar.bz2 |
Merge topic 'defer-target-source-check'
4e7f6738 Defer check for sources within a target until generation.
6e4e7c65 Tests: Exclude bad RunCMake.add_executable case on multi-arch Xcode
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1242
25 files changed, 100 insertions, 76 deletions
diff --git a/Help/command/add_executable.rst b/Help/command/add_executable.rst index c088796..6763620 100644 --- a/Help/command/add_executable.rst +++ b/Help/command/add_executable.rst @@ -7,14 +7,15 @@ Add an executable to the project using the specified source files. add_executable(<name> [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] - source1 [source2 ...]) + [source1] [source2 ...]) Adds an executable target called ``<name>`` to be built from the source -files listed in the command invocation. The ``<name>`` corresponds to the -logical target name and must be globally unique within a project. The -actual file name of the executable built is constructed based on -conventions of the native platform (such as ``<name>.exe`` or just -``<name>``). +files listed in the command invocation. (The source files can be omitted +here if they are added later using :command:`target_sources`.) The +``<name>`` corresponds to the logical target name and must be globally +unique within a project. The actual file name of the executable built is +constructed based on conventions of the native platform (such as +``<name>.exe`` or just ``<name>``). By default the executable file will be created in the build tree directory corresponding to the source tree directory in which the diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst index de5335e..78b316d 100644 --- a/Help/command/add_library.rst +++ b/Help/command/add_library.rst @@ -14,13 +14,14 @@ Normal Libraries add_library(<name> [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] - source1 [source2 ...]) + [source1] [source2 ...]) Adds a library target called ``<name>`` to be built from the source files -listed in the command invocation. The ``<name>`` corresponds to the -logical target name and must be globally unique within a project. The -actual file name of the library built is constructed based on -conventions of the native platform (such as ``lib<name>.a`` or +listed in the command invocation. (The source files can be omitted here +if they are added later using :command:`target_sources`.) The ``<name>`` +corresponds to the logical target name and must be globally unique within +a project. The actual file name of the library built is constructed based +on conventions of the native platform (such as ``lib<name>.a`` or ``<name>.lib``). ``STATIC``, ``SHARED``, or ``MODULE`` may be given to specify the type of diff --git a/Help/release/dev/defer-target-source-check.rst b/Help/release/dev/defer-target-source-check.rst new file mode 100644 index 0000000..65f5488 --- /dev/null +++ b/Help/release/dev/defer-target-source-check.rst @@ -0,0 +1,6 @@ +defer-target-source-check +------------------------- + +* :command:`add_library` and :command:`add_executable` commands can now be + called without any sources and will not complain as long as sources will + be added later via :command:`target_sources`. diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index 1d0376f..262e3a1 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -18,7 +18,7 @@ class cmExecutionStatus; bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args, cmExecutionStatus&) { - if (args.size() < 2) { + if (args.empty()) { this->SetError("called with incorrect number of arguments"); return false; } @@ -191,12 +191,6 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args, } } - if (s == args.end()) { - this->SetError( - "called with incorrect number of arguments, no sources provided"); - return false; - } - std::vector<std::string> srclists(s, args.end()); cmTarget* tgt = this->Makefile->AddExecutable(exename.c_str(), srclists, excludeFromAll); diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index ebf1763..31c2ecf 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -362,14 +362,6 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args, return true; } - if (s == args.end()) { - std::string msg = "You have called ADD_LIBRARY for library "; - msg += args[0]; - msg += " without any source files. This typically indicates a problem "; - msg += "with your CMakeLists.txt file"; - cmSystemTools::Message(msg.c_str(), "Warning"); - } - srclists.insert(srclists.end(), s, args.end()); this->Makefile->AddLibrary(libName, type, srclists, excludeFromAll); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index e6d389e..e0100ce 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -281,6 +281,43 @@ void cmGlobalGenerator::ForceLinkerLanguages() { } +bool cmGlobalGenerator::CheckTargetsForMissingSources() const +{ + bool failed = false; + for (cmLocalGenerator* localGen : this->LocalGenerators) { + const std::vector<cmGeneratorTarget*>& targets = + localGen->GetGeneratorTargets(); + + for (cmGeneratorTarget* target : targets) { + if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET || + target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY || + target->GetType() == cmStateEnums::TargetType::UTILITY) { + continue; + } + + std::vector<std::string> configs; + target->Makefile->GetConfigurations(configs); + std::vector<cmSourceFile*> srcs; + if (configs.empty()) { + target->GetSourceFiles(srcs, ""); + } else { + for (std::vector<std::string>::const_iterator ci = configs.begin(); + ci != configs.end() && srcs.empty(); ++ci) { + target->GetSourceFiles(srcs, *ci); + } + } + if (srcs.empty()) { + std::ostringstream e; + e << "No SOURCES given to target: " << target->GetName(); + this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(), + target->GetBacktrace()); + failed = true; + } + } + } + return failed; +} + bool cmGlobalGenerator::IsExportedTargetsFile( const std::string& filename) const { @@ -1319,6 +1356,11 @@ bool cmGlobalGenerator::Compute() localGen->TraceDependencies(); } + // Make sure that all (non-imported) targets have source files added! + if (this->CheckTargetsForMissingSources()) { + return false; + } + this->ForceLinkerLanguages(); // Compute the manifest of main targets generated. diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index abbc001..c5a5297 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -542,6 +542,8 @@ private: virtual void ForceLinkerLanguages(); + bool CheckTargetsForMissingSources() const; + void CreateLocalGenerators(); void CheckCompilerIdCompatibility(cmMakefile* mf, diff --git a/Tests/RunCMake/add_executable/NoSources-stderr.txt b/Tests/RunCMake/add_executable/NoSources-stderr.txt index 5985905..4fcfd49 100644 --- a/Tests/RunCMake/add_executable/NoSources-stderr.txt +++ b/Tests/RunCMake/add_executable/NoSources-stderr.txt @@ -1,4 +1,4 @@ ^CMake Error at NoSources.cmake:[0-9]+ \(add_executable\): - add_executable called with incorrect number of arguments + No SOURCES given to target: TestExeWithoutSources Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_executable/NoSourcesButLinkObjects-stderr.txt b/Tests/RunCMake/add_executable/NoSourcesButLinkObjects-stderr.txt index c8afadb..5561daa 100644 --- a/Tests/RunCMake/add_executable/NoSourcesButLinkObjects-stderr.txt +++ b/Tests/RunCMake/add_executable/NoSourcesButLinkObjects-stderr.txt @@ -1,11 +1,4 @@ ^CMake Error at NoSourcesButLinkObjects.cmake:[0-9]+ \(add_executable\): - add_executable called with incorrect number of arguments -Call Stack \(most recent call first\): - CMakeLists.txt:[0-9]+ \(include\) - - -CMake Error at NoSourcesButLinkObjects.cmake:[0-9]+ \(target_link_libraries\): - Cannot specify link libraries for target \"TestExeWithoutSources\" which is - not built by this project. + No SOURCES given to target: TestExeWithoutSources Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_executable/OnlyObjectSources-result.txt b/Tests/RunCMake/add_executable/OnlyObjectSources-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/add_executable/OnlyObjectSources-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/add_executable/OnlyObjectSources-stderr.txt b/Tests/RunCMake/add_executable/OnlyObjectSources-stderr.txt deleted file mode 100644 index ea72d5d..0000000 --- a/Tests/RunCMake/add_executable/OnlyObjectSources-stderr.txt +++ /dev/null @@ -1,11 +0,0 @@ -^CMake Error at OnlyObjectSources.cmake:[0-9]+ \(add_executable\): - add_executable called with incorrect number of arguments -Call Stack \(most recent call first\): - CMakeLists.txt:[0-9]+ \(include\) - - -CMake Error at OnlyObjectSources.cmake:[0-9]+ \(target_sources\): - Cannot specify sources for target \"TestExeWithoutSources\" which is not - built by this project. -Call Stack \(most recent call first\): - CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_executable/RunCMakeTest.cmake b/Tests/RunCMake/add_executable/RunCMakeTest.cmake index 70a68f2..88916b7 100644 --- a/Tests/RunCMake/add_executable/RunCMakeTest.cmake +++ b/Tests/RunCMake/add_executable/RunCMakeTest.cmake @@ -2,4 +2,6 @@ include(RunCMake) run_cmake(NoSources) run_cmake(OnlyObjectSources) -run_cmake(NoSourcesButLinkObjects) +if(NOT RunCMake_GENERATOR STREQUAL "Xcode" OR NOT "$ENV{CMAKE_OSX_ARCHITECTURES}" MATCHES "[;$]") + run_cmake(NoSourcesButLinkObjects) +endif() diff --git a/Tests/RunCMake/add_library/MODULEwithNoSources-stderr.txt b/Tests/RunCMake/add_library/MODULEwithNoSources-stderr.txt index 5cf0b1e..41da381 100644 --- a/Tests/RunCMake/add_library/MODULEwithNoSources-stderr.txt +++ b/Tests/RunCMake/add_library/MODULEwithNoSources-stderr.txt @@ -1,3 +1,4 @@ -^You have called ADD_LIBRARY for library TestModuleLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file( -CMake Error: CMake can not determine linker language for target: TestModuleLibWithoutSources)+( -CMake Error: Cannot determine link language for target \"TestModuleLibWithoutSources\".)?$ +^CMake Error at MODULEwithNoSources.cmake:[0-9]+ \(add_library\): + No SOURCES given to target: TestModuleLibWithoutSources +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_library/MODULEwithNoSourcesButLinkObjects-stderr.txt b/Tests/RunCMake/add_library/MODULEwithNoSourcesButLinkObjects-stderr.txt index 951594a..67dd87c 100644 --- a/Tests/RunCMake/add_library/MODULEwithNoSourcesButLinkObjects-stderr.txt +++ b/Tests/RunCMake/add_library/MODULEwithNoSourcesButLinkObjects-stderr.txt @@ -1,3 +1,4 @@ -^You have called ADD_LIBRARY for library TestModuleLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file( -CMake Error: CMake can not determine linker language for target: TestModuleLibWithoutSources)+( -CMake Error: Cannot determine link language for target \"TestModuleLibWithoutSources\".)*$ +^CMake Error at MODULEwithNoSourcesButLinkObjects.cmake:[0-9]+ \(add_library\): + No SOURCES given to target: TestModuleLibWithoutSources +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_library/MODULEwithOnlyObjectSources-stderr.txt b/Tests/RunCMake/add_library/MODULEwithOnlyObjectSources-stderr.txt deleted file mode 100644 index de83755..0000000 --- a/Tests/RunCMake/add_library/MODULEwithOnlyObjectSources-stderr.txt +++ /dev/null @@ -1 +0,0 @@ -^You have called ADD_LIBRARY for library TestModuleLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file$ diff --git a/Tests/RunCMake/add_library/OBJECTwithNoSources-result.txt b/Tests/RunCMake/add_library/OBJECTwithNoSources-result.txt index 9c558e3..d00491f 100644 --- a/Tests/RunCMake/add_library/OBJECTwithNoSources-result.txt +++ b/Tests/RunCMake/add_library/OBJECTwithNoSources-result.txt @@ -1 +1 @@ -. +1 diff --git a/Tests/RunCMake/add_library/OBJECTwithNoSources-stderr.txt b/Tests/RunCMake/add_library/OBJECTwithNoSources-stderr.txt index 099ec4f..20d3a8a 100644 --- a/Tests/RunCMake/add_library/OBJECTwithNoSources-stderr.txt +++ b/Tests/RunCMake/add_library/OBJECTwithNoSources-stderr.txt @@ -1,2 +1,4 @@ -^You have called ADD_LIBRARY for library TestObjectLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file( -CMake Error: CMake can not determine linker language for target: TestObjectLibWithoutSources)*$ +^CMake Error at OBJECTwithNoSources.cmake:[0-9]+ \(add_library\): + No SOURCES given to target: TestObjectLibWithoutSources +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_library/OBJECTwithNoSourcesButLinkObjects-stderr.txt b/Tests/RunCMake/add_library/OBJECTwithNoSourcesButLinkObjects-stderr.txt index 8f20096..cd6f1e0 100644 --- a/Tests/RunCMake/add_library/OBJECTwithNoSourcesButLinkObjects-stderr.txt +++ b/Tests/RunCMake/add_library/OBJECTwithNoSourcesButLinkObjects-stderr.txt @@ -1,5 +1,4 @@ -^You have called ADD_LIBRARY for library TestObjectLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file -CMake Error at OBJECTwithNoSourcesButLinkObjects.cmake:[0-9]+ \(target_link_libraries\): +^CMake Error at OBJECTwithNoSourcesButLinkObjects.cmake:[0-9]+ \(target_link_libraries\): Object library target \"TestObjectLibWithoutSources\" may not link to anything. Call Stack \(most recent call first\): diff --git a/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-stderr.txt b/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-stderr.txt index f9cbf6b..77a72f1 100644 --- a/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-stderr.txt +++ b/Tests/RunCMake/add_library/OBJECTwithOnlyObjectSources-stderr.txt @@ -1,5 +1,4 @@ -^You have called ADD_LIBRARY for library TestObjectLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file -CMake Error at OBJECTwithOnlyObjectSources.cmake:[0-9]+ \(add_library\): +^CMake Error at OBJECTwithOnlyObjectSources.cmake:[0-9]+ \(add_library\): OBJECT library \"TestObjectLibWithoutSources\" contains: [^ diff --git a/Tests/RunCMake/add_library/SHAREDwithNoSources-stderr.txt b/Tests/RunCMake/add_library/SHAREDwithNoSources-stderr.txt index 228d1cc..5cedd62 100644 --- a/Tests/RunCMake/add_library/SHAREDwithNoSources-stderr.txt +++ b/Tests/RunCMake/add_library/SHAREDwithNoSources-stderr.txt @@ -1,3 +1,4 @@ -^You have called ADD_LIBRARY for library TestSharedLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file( -CMake Error: CMake can not determine linker language for target: TestSharedLibWithoutSources)+( -CMake Error: Cannot determine link language for target \"TestSharedLibWithoutSources\".)*$ +^CMake Error at SHAREDwithNoSources.cmake:[0-9]+ \(add_library\): + No SOURCES given to target: TestSharedLibWithoutSources +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_library/SHAREDwithNoSourcesButLinkObjects-stderr.txt b/Tests/RunCMake/add_library/SHAREDwithNoSourcesButLinkObjects-stderr.txt index 228d1cc..d621e76 100644 --- a/Tests/RunCMake/add_library/SHAREDwithNoSourcesButLinkObjects-stderr.txt +++ b/Tests/RunCMake/add_library/SHAREDwithNoSourcesButLinkObjects-stderr.txt @@ -1,3 +1,4 @@ -^You have called ADD_LIBRARY for library TestSharedLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file( -CMake Error: CMake can not determine linker language for target: TestSharedLibWithoutSources)+( -CMake Error: Cannot determine link language for target \"TestSharedLibWithoutSources\".)*$ +^CMake Error at SHAREDwithNoSourcesButLinkObjects.cmake:[0-9]+ \(add_library\): + No SOURCES given to target: TestSharedLibWithoutSources +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_library/SHAREDwithOnlyObjectSources-stderr.txt b/Tests/RunCMake/add_library/SHAREDwithOnlyObjectSources-stderr.txt deleted file mode 100644 index ec350cd..0000000 --- a/Tests/RunCMake/add_library/SHAREDwithOnlyObjectSources-stderr.txt +++ /dev/null @@ -1 +0,0 @@ -^You have called ADD_LIBRARY for library TestSharedLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file$ diff --git a/Tests/RunCMake/add_library/STATICwithNoSources-stderr.txt b/Tests/RunCMake/add_library/STATICwithNoSources-stderr.txt index 830eb22..10b2112 100644 --- a/Tests/RunCMake/add_library/STATICwithNoSources-stderr.txt +++ b/Tests/RunCMake/add_library/STATICwithNoSources-stderr.txt @@ -1,3 +1,4 @@ -^You have called ADD_LIBRARY for library TestStaticLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file( -CMake Error: Cannot determine link language for target \"TestStaticLibWithoutSources\".)?( -CMake Error: CMake can not determine linker language for target: TestStaticLibWithoutSources)+$ +^CMake Error at STATICwithNoSources.cmake:[0-9]+ \(add_library\): + No SOURCES given to target: TestStaticLibWithoutSources +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_library/STATICwithNoSourcesButLinkObjects-stderr.txt b/Tests/RunCMake/add_library/STATICwithNoSourcesButLinkObjects-stderr.txt index 830eb22..33c23b2 100644 --- a/Tests/RunCMake/add_library/STATICwithNoSourcesButLinkObjects-stderr.txt +++ b/Tests/RunCMake/add_library/STATICwithNoSourcesButLinkObjects-stderr.txt @@ -1,3 +1,4 @@ -^You have called ADD_LIBRARY for library TestStaticLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file( -CMake Error: Cannot determine link language for target \"TestStaticLibWithoutSources\".)?( -CMake Error: CMake can not determine linker language for target: TestStaticLibWithoutSources)+$ +^CMake Error at STATICwithNoSourcesButLinkObjects.cmake:[0-9]+ \(add_library\): + No SOURCES given to target: TestStaticLibWithoutSources +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/add_library/STATICwithOnlyObjectSources-stderr.txt b/Tests/RunCMake/add_library/STATICwithOnlyObjectSources-stderr.txt deleted file mode 100644 index 5cd10d4..0000000 --- a/Tests/RunCMake/add_library/STATICwithOnlyObjectSources-stderr.txt +++ /dev/null @@ -1 +0,0 @@ -^You have called ADD_LIBRARY for library TestStaticLibWithoutSources without any source files. This typically indicates a problem with your CMakeLists.txt file$ |