mirror of https://github.com/libAthena/athena.git
Add dependency file generation to atdna
This commit is contained in:
parent
b1f73f0c33
commit
38985326f3
|
@ -152,10 +152,16 @@ endif()
|
||||||
|
|
||||||
# Super handy macro for adding atdna target
|
# Super handy macro for adding atdna target
|
||||||
macro(atdna out)
|
macro(atdna out)
|
||||||
|
# Ninja wants invocations in root binary dir for DEPFILE application
|
||||||
|
file(RELATIVE_PATH out_rel ${CMAKE_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/${out}")
|
||||||
|
|
||||||
# Make input files source-relative
|
# Make input files source-relative
|
||||||
set(ins "")
|
set(ins "")
|
||||||
|
set(ins_impdeps "")
|
||||||
foreach(arg ${ARGN})
|
foreach(arg ${ARGN})
|
||||||
list(APPEND ins ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
|
list(APPEND ins ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
|
||||||
|
list(APPEND ins_impdeps CXX)
|
||||||
|
list(APPEND ins_impdeps ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Get local include directories for atdna
|
# Get local include directories for atdna
|
||||||
|
@ -194,8 +200,22 @@ macro(atdna out)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Make target
|
# Make target
|
||||||
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
|
if(${CMAKE_GENERATOR} STREQUAL "Ninja")
|
||||||
ARGS ${extraargs} -o ${out} ${cdefcli} ${inccli} "-I${ATHENA_INCLUDE_DIR}"
|
# Use Ninja's DEPFILE parser in cooperation with atdna
|
||||||
-isystem "${CLANG_INCLUDE_DIR}" ${ins}
|
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
|
||||||
DEPENDS ${ins} COMMENT "Generating DNA ${out}")
|
ARGS ${extraargs} -o ${out_rel} -MD -MT ${out_rel} -MF ${out_rel}.d ${cdefcli} ${inccli}
|
||||||
|
"-I${ATHENA_INCLUDE_DIR}" -isystem "${CLANG_INCLUDE_DIR}" ${ins}
|
||||||
|
DEPENDS atdna ${ins} IMPLICIT_DEPENDS ${ins_impdeps}
|
||||||
|
DEPFILE "${CMAKE_CURRENT_BINARY_DIR}/${out}.d"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
COMMENT "Generating DNA ${out_rel}")
|
||||||
|
else()
|
||||||
|
# Use CMake's built-in dependency scanner for makefile targets
|
||||||
|
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
|
||||||
|
ARGS ${extraargs} -o ${out_rel} ${cdefcli} ${inccli}
|
||||||
|
"-I${ATHENA_INCLUDE_DIR}" -isystem "${CLANG_INCLUDE_DIR}" ${ins}
|
||||||
|
DEPENDS atdna ${ins} IMPLICIT_DEPENDS ${ins_impdeps}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
COMMENT "Generating DNA ${out_rel}")
|
||||||
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
|
@ -13,10 +13,16 @@ find_package(Athena REQUIRED)
|
||||||
|
|
||||||
# Super handy macro for adding atdna target
|
# Super handy macro for adding atdna target
|
||||||
macro(atdna out)
|
macro(atdna out)
|
||||||
|
# Ninja wants invocations in root binary dir for DEPFILE application
|
||||||
|
file(RELATIVE_PATH out_rel ${CMAKE_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/${out}")
|
||||||
|
|
||||||
# Make input files source-relative
|
# Make input files source-relative
|
||||||
set(ins "")
|
set(ins "")
|
||||||
|
set(ins_impdeps "")
|
||||||
foreach(arg ${ARGN})
|
foreach(arg ${ARGN})
|
||||||
list(APPEND ins ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
|
list(APPEND ins ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
|
||||||
|
list(APPEND ins_impdeps CXX)
|
||||||
|
list(APPEND ins_impdeps ${CMAKE_CURRENT_SOURCE_DIR}/${arg})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Get local include directories for atdna
|
# Get local include directories for atdna
|
||||||
|
@ -50,9 +56,23 @@ macro(atdna out)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Make target
|
# Make target
|
||||||
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
|
if(${CMAKE_GENERATOR} STREQUAL "Ninja")
|
||||||
ARGS ${extraargs} -o ${out} ${cdefcli} ${inccli} "-I${ATHENA_INCLUDE_DIR}"
|
# Use Ninja's DEPFILE parser in cooperation with atdna
|
||||||
-isystem "@CONF_CLANG_INCLUDE_DIR@" ${ins}
|
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
|
||||||
DEPENDS ${ins} COMMENT "Generating DNA ${out}")
|
ARGS ${extraargs} -o ${out_rel} -MD -MT ${out_rel} -MF ${out_rel}.d ${cdefcli} ${inccli}
|
||||||
|
"-I${ATHENA_INCLUDE_DIR}" -isystem "${CLANG_INCLUDE_DIR}" ${ins}
|
||||||
|
DEPENDS atdna ${ins} IMPLICIT_DEPENDS ${ins_impdeps}
|
||||||
|
DEPFILE "${CMAKE_CURRENT_BINARY_DIR}/${out}.d"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
COMMENT "Generating DNA ${out_rel}")
|
||||||
|
else()
|
||||||
|
# Use CMake's built-in dependency scanner for makefile targets
|
||||||
|
add_custom_command(OUTPUT ${out} COMMAND $<TARGET_FILE:atdna>
|
||||||
|
ARGS ${extraargs} -o ${out_rel} ${cdefcli} ${inccli}
|
||||||
|
"-I${ATHENA_INCLUDE_DIR}" -isystem "${CLANG_INCLUDE_DIR}" ${ins}
|
||||||
|
DEPENDS atdna ${ins} IMPLICIT_DEPENDS ${ins_impdeps}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
COMMENT "Generating DNA ${out_rel}")
|
||||||
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "clang/AST/RecursiveASTVisitor.h"
|
#include "clang/AST/RecursiveASTVisitor.h"
|
||||||
#include "clang/Frontend/CompilerInstance.h"
|
#include "clang/Frontend/CompilerInstance.h"
|
||||||
#include "clang/Frontend/FrontendAction.h"
|
#include "clang/Frontend/FrontendAction.h"
|
||||||
|
#include "clang/Frontend/Utils.h"
|
||||||
#include "clang/Tooling/Tooling.h"
|
#include "clang/Tooling/Tooling.h"
|
||||||
#include "clang/Lex/Preprocessor.h"
|
#include "clang/Lex/Preprocessor.h"
|
||||||
#include "clang/Sema/Sema.h"
|
#include "clang/Sema/Sema.h"
|
||||||
|
@ -61,6 +62,14 @@ static llvm::cl::list<std::string> SystemIncludeSearchPaths("isystem",
|
||||||
static llvm::cl::opt<std::string> StandardCXXLib("stdlib",
|
static llvm::cl::opt<std::string> StandardCXXLib("stdlib",
|
||||||
llvm::cl::desc("Standard C++ library"));
|
llvm::cl::desc("Standard C++ library"));
|
||||||
|
|
||||||
|
static llvm::cl::opt<bool> DepFile("MD", llvm::cl::desc("Make Dependency file"));
|
||||||
|
|
||||||
|
static llvm::cl::opt<std::string> DepFileOut("MF",
|
||||||
|
llvm::cl::desc("Dependency file out path"));
|
||||||
|
|
||||||
|
static llvm::cl::list<std::string> DepFileTargets("MT",
|
||||||
|
llvm::cl::desc("Dependency file targets"));
|
||||||
|
|
||||||
static llvm::cl::list<std::string> SystemIncRoot("isysroot",
|
static llvm::cl::list<std::string> SystemIncRoot("isysroot",
|
||||||
llvm::cl::desc("System include root"));
|
llvm::cl::desc("System include root"));
|
||||||
|
|
||||||
|
@ -2372,11 +2381,20 @@ class ATDNAAction : public clang::ASTFrontendAction
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<clang::DependencyFileGenerator> TheDependencyFileGenerator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ATDNAAction() {}
|
explicit ATDNAAction() = default;
|
||||||
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance& compiler,
|
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance& compiler,
|
||||||
llvm::StringRef /*filename*/)
|
llvm::StringRef /*filename*/)
|
||||||
{
|
{
|
||||||
|
clang::DependencyOutputOptions DepOpts;
|
||||||
|
DepOpts.OutputFile = DepFileOut;
|
||||||
|
DepOpts.Targets = DepFileTargets;
|
||||||
|
if (!DepOpts.OutputFile.empty())
|
||||||
|
TheDependencyFileGenerator.reset(
|
||||||
|
clang::DependencyFileGenerator::CreateAndAttachToPreprocessor(compiler.getPreprocessor(), DepOpts));
|
||||||
|
|
||||||
std::unique_ptr<StreamOut> fileout;
|
std::unique_ptr<StreamOut> fileout;
|
||||||
StreamOut* fileoutOld;
|
StreamOut* fileoutOld;
|
||||||
if (OutputFilename.size())
|
if (OutputFilename.size())
|
||||||
|
@ -2406,7 +2424,8 @@ int main(int argc, const char** argv)
|
||||||
args.push_back(argv[a]);
|
args.push_back(argv[a]);
|
||||||
|
|
||||||
llvm::IntrusiveRefCntPtr<clang::FileManager> fman(new clang::FileManager(clang::FileSystemOptions()));
|
llvm::IntrusiveRefCntPtr<clang::FileManager> fman(new clang::FileManager(clang::FileSystemOptions()));
|
||||||
clang::tooling::ToolInvocation TI(args, new ATDNAAction, fman.get());
|
ATDNAAction* action = new ATDNAAction();
|
||||||
|
clang::tooling::ToolInvocation TI(args, action, fman.get());
|
||||||
if (!TI.run())
|
if (!TI.run())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue