PCH: add target_precompile_headers command

This commit is contained in:
Daniel Pfeifer 2015-03-12 17:44:36 +01:00 committed by Cristian Adam
parent 0467a2f91b
commit 9b6797e71d
5 changed files with 84 additions and 0 deletions

View File

@ -656,6 +656,8 @@ set(SRCS
cmTargetLinkDirectoriesCommand.h
cmTargetLinkLibrariesCommand.cxx
cmTargetLinkLibrariesCommand.h
cmTargetPrecompileHeadersCommand.cxx
cmTargetPrecompileHeadersCommand.h
cmTargetPropCommandBase.cxx
cmTargetPropCommandBase.h
cmTargetSourcesCommand.cxx

View File

@ -78,6 +78,7 @@
#include "cmTargetCompileOptionsCommand.h"
#include "cmTargetIncludeDirectoriesCommand.h"
#include "cmTargetLinkLibrariesCommand.h"
#include "cmTargetPrecompileHeadersCommand.h"
#include "cmTargetSourcesCommand.h"
#include "cmTryCompileCommand.h"
#include "cmTryRunCommand.h"
@ -277,6 +278,9 @@ void GetProjectCommands(cmState* state)
state->AddBuiltinCommand("try_compile",
cm::make_unique<cmTryCompileCommand>());
state->AddBuiltinCommand("try_run", cm::make_unique<cmTryRunCommand>());
state->AddBuiltinCommand(
"target_precompile_headers",
cm::make_unique<cmTargetPrecompileHeadersCommand>());
#if !defined(CMAKE_BOOTSTRAP)
state->AddBuiltinCommand("add_compile_definitions",

View File

@ -0,0 +1,36 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTargetPrecompileHeadersCommand.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmStringAlgorithms.h"
#include "cmTarget.h"
bool cmTargetPrecompileHeadersCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
return this->HandleArguments(args, "PRECOMPILE_HEADERS");
}
void cmTargetPrecompileHeadersCommand::HandleMissingTarget(
const std::string& name)
{
const std::string e =
cmStrCat("Cannot specify precompile headers for target \"", name,
"\" which is not built by this project.");
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
}
std::string cmTargetPrecompileHeadersCommand::Join(
const std::vector<std::string>& content)
{
return cmJoin(content, ";");
}
bool cmTargetPrecompileHeadersCommand::HandleDirectContent(
cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
{
tgt->AppendProperty("PRECOMPILE_HEADERS", this->Join(content).c_str());
return true;
}

View File

@ -0,0 +1,41 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef cmTargetPrecompileHeadersCommand_h
#define cmTargetPrecompileHeadersCommand_h
#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
#include "cm_memory.hxx"
#include "cmCommand.h"
#include "cmTargetPropCommandBase.h"
class cmExecutionStatus;
class cmTarget;
class cmTargetPrecompileHeadersCommand : public cmTargetPropCommandBase
{
public:
std::unique_ptr<cmCommand> Clone() override
{
return cm::make_unique<cmTargetPrecompileHeadersCommand>();
}
bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) override;
private:
void HandleMissingTarget(const std::string& name) override;
bool HandleDirectContent(cmTarget* tgt,
const std::vector<std::string>& content,
bool prepend, bool system) override;
std::string Join(const std::vector<std::string>& content) override;
};
#endif

View File

@ -436,6 +436,7 @@ CMAKE_CXX_SOURCES="\
cmTargetCompileOptionsCommand \
cmTargetIncludeDirectoriesCommand \
cmTargetLinkLibrariesCommand \
cmTargetPrecompileHeadersCommand \
cmTargetPropCommandBase \
cmTargetPropertyComputer \
cmTargetSourcesCommand \