Skip to content

Commit

Permalink
Merge pull request #86 from Okkoma/u3d-as-submodule
Browse files Browse the repository at this point in the history
U3d as submodule
  • Loading branch information
klaussilveira authored Feb 7, 2025
2 parents 38cb8ed + 80e2f20 commit f53c1fd
Show file tree
Hide file tree
Showing 18 changed files with 1,618 additions and 747 deletions.
38 changes: 27 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,27 @@ cmake_minimum_required (VERSION 3.10.2)
# Set project name
project (Urho3D)

# indicates that we are currently in Urho3D cmakefiles, used by UrhoCommon module
set (IS_URHO3D TRUE)

# Set CMake modules search path
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
if (NOT URHO3D_CMAKE_MODULE)
list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
endif ()

# Include UrhoCommon.cmake module after setting project name
include (UrhoCommon)

# Ensure Compatibility if using old UrhoCommon module
if (NOT URHO3D_ROOT_DIR)
message (WARNING "You're using old cmake modules !/n
new urho3d cmake modules are available for better urho3d/user project separation")
set (URHO3D_ROOT_DIR ${CMAKE_SOURCE_DIR})
set (URHO3D_SOURCE_DIR ${CMAKE_SOURCE_DIR}/Source)
set (URHO3D_BUILD_DIR ${CMAKE_BINARY_DIR})
set (URHO3D_CMAKE_MODULE ${CMAKE_SOURCE_DIR}/cmake/Modules)
endif ()

# Setup SDK install destinations
set (PATH_SUFFIX Urho3D)
if (WIN32)
Expand All @@ -52,18 +67,19 @@ if (URHO3D_64BIT)
endif ()
endif ()
set (DEST_INCLUDE_DIR include/Urho3D) # The include directory path contains the 'Urho3D' suffix regardless of PATH_SUFFIX variable
set (DEST_SHARE_DIR share/${PATH_SUFFIX})
set (DEST_SHARE_DIR ${CURRENT_INSTALL_PREFIX}share/${PATH_SUFFIX})
set (DEST_BUNDLE_DIR ${DEST_SHARE_DIR}/Applications)
# Note to package maintainer: ${PATH_SUFFIX} for library could be removed if the extra path is not desired, but if so then the RPATH setting in Source's CMakeLists.txt needs to be adjusted accordingly
set (DEST_LIBRARY_DIR lib${LIB_SUFFIX}/${PATH_SUFFIX})
set (DEST_PKGCONFIG_DIR lib${LIB_SUFFIX}/pkgconfig)
set (DEST_LIBRARY_DIR ${CURRENT_INSTALL_PREFIX}lib${LIB_SUFFIX}/${PATH_SUFFIX})
set (DEST_PKGCONFIG_DIR ${CURRENT_INSTALL_PREFIX}lib${LIB_SUFFIX}/pkgconfig)
# Install application launcher scripts
file (GLOB APP_SCRIPTS ${CMAKE_SOURCE_DIR}/bin/*${SCRIPT_EXT})
install (PROGRAMS ${APP_SCRIPTS} DESTINATION ${DEST_RUNTIME_DIR}) # DEST_RUNTIME_DIR variable is set by the set_output_directories() macro call in the UrhoCommon module
# TODO : do we need install application scripts in urho3d sdk ? this part should be in user project cmakefiles
#file (GLOB APP_SCRIPTS ${CMAKE_SOURCE_DIR}/bin/*${SCRIPT_EXT})
#install (PROGRAMS ${APP_SCRIPTS} DESTINATION ${DEST_RUNTIME_DIR}) # DEST_RUNTIME_DIR variable is set by the set_output_directories() macro call in the UrhoCommon module
# Install CMake modules and toolchains provided by and for Urho3D
install (DIRECTORY ${CMAKE_SOURCE_DIR}/cmake/ DESTINATION ${DEST_SHARE_DIR}/cmake) # Note: the trailing slash is significant
install (DIRECTORY ${URHO3D_ROOT_DIR}/cmake/ DESTINATION ${DEST_SHARE_DIR}/cmake) # Note: the trailing slash is significant
# Install CMake build scripts and rakefile
file (GLOB CMAKE_SCRIPTS ${CMAKE_SOURCE_DIR}/script/*${SCRIPT_EXT})
file (GLOB CMAKE_SCRIPTS ${URHO3D_ROOT_DIR}/script/*${SCRIPT_EXT})
install (PROGRAMS ${CMAKE_SCRIPTS} DESTINATION ${DEST_SHARE_DIR}/scripts)
install (FILES rakefile DESTINATION ${DEST_SHARE_DIR})

Expand All @@ -73,15 +89,15 @@ set (CPACK_PACKAGE_DESCRIPTION_SUMMARY ${URHO3D_DESCRIPTION})
set (URHO3D_URL "https://github.com/u3d-community/U3D")
set (CPACK_PACKAGE_VENDOR ${URHO3D_URL})
set (CPACK_PACKAGE_CONTACT ${URHO3D_URL})
execute_process (COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/Modules/GetUrhoRevision.cmake WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE URHO3D_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process (COMMAND ${CMAKE_COMMAND} -P ${URHO3D_ROOT_DIR}/cmake/Modules/GetUrhoRevision.cmake WORKING_DIRECTORY ${URHO3D_ROOT_DIR} OUTPUT_VARIABLE URHO3D_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
set (CPACK_PACKAGE_VERSION ${URHO3D_VERSION})
string (REGEX MATCH "([^.]+)\\.([^.]+)\\.(.+)" MATCHED ${URHO3D_VERSION})
if (MATCHED)
set (CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
set (CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
set (CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
endif ()
set (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
set (CPACK_RESOURCE_FILE_LICENSE ${URHO3D_ROOT_DIR}/LICENSE)
set (CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
set (CPACK_GENERATOR TGZ)
if (ANDROID)
Expand Down Expand Up @@ -179,7 +195,7 @@ if (URHO3D_MACOSX_BUNDLE OR (APPLE AND ARM))
endif ()

# Setup SDK-like include dir in the build tree for building the Urho3D library
set (THIRD_PARTY_INCLUDE_DIR ${CMAKE_BINARY_DIR}/${DEST_INCLUDE_DIR}/ThirdParty)
set (THIRD_PARTY_INCLUDE_DIR ${URHO3D_BUILD_DIR}/${DEST_INCLUDE_DIR}/ThirdParty)
file (MAKE_DIRECTORY ${THIRD_PARTY_INCLUDE_DIR})

# Urho3D source
Expand Down
1 change: 1 addition & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ if (URHO3D_URHO2D)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/spine)
add_subdirectory (ThirdParty/spine)
# Add definition for Spine
set (URHO3D_SPINE TRUE)
add_definitions (-DURHO3D_SPINE)
endif ()
endif ()
Expand Down
155 changes: 78 additions & 77 deletions Source/Clang-Tools/Annotator/Annotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@ using namespace clang::tooling;
using namespace llvm;

static cl::extrahelp commonHelp(CommonOptionsParser::HelpMessage);
static cl::extrahelp moreHelp(
"\tFor example, to run Annotator on all files in a subtree of the\n"
"\tsource tree, use:\n"
"\n"
"\t find path/in/substree -name '*.cpp'|xargs Annotator -p build/path\n"
"\n"
"\tNote, that path/in/subtree and current directory should follow the\n"
"\trules described above.\n"
"\n"
"Most probably you want to invoke 'annotate' built-in target instead of invoking this tool\n"
"directly. The 'annotate' target invokes this tool in a right context prepared by build system.\n"
"\n"
);
static cl::extrahelp
moreHelp("\tFor example, to run Annotator on all files in a subtree of the\n"
"\tsource tree, use:\n"
"\n"
"\t find path/in/substree -name '*.cpp'|xargs Annotator -p build/path\n"
"\n"
"\tNote, that path/in/subtree and current directory should follow the\n"
"\trules described above.\n"
"\n"
"Most probably you want to invoke 'annotate' built-in target instead of invoking this tool\n"
"directly. The 'annotate' target invokes this tool in a right context prepared by build system.\n"
"\n");

static cl::OptionCategory annotatorCategory("Annotator options");

Expand All @@ -59,9 +58,7 @@ class PathFilter
std::copy_if(sourcePaths.begin(), sourcePaths.end(), std::back_inserter(pathList_), fn);
}

std::vector<std::string> GetPathList() {
return pathList_;
}
std::vector<std::string> GetPathList() { return pathList_; }

private:
std::vector<std::string> pathList_;
Expand All @@ -78,45 +75,46 @@ static std::unordered_map<std::string, Data> categoryData_;

class ExtractCallback : public MatchFinder::MatchCallback
{
public :
public:
virtual void run(const MatchFinder::MatchResult& result)
{
for (auto& i: categories_)
for (auto& i : categories_)
{
auto symbol = result.Nodes.getNodeAs<StringLiteral>(i);
auto symbol = result.Nodes.getNodeAs<clang::StringLiteral>(i);
if (symbol)
categoryData_[i].exposedSymbols_.insert(symbol->getString());
categoryData_[i].exposedSymbols_.insert(symbol->getString().str());
}
}

virtual void onStartOfTranslationUnit()
{
static unsigned count = sizeof("Extracting") / sizeof(char) - 1;
outs() << '.' << (++count % 100 ? "" : "\n"); // Sending a heart beat
outs() << '.' << (++count % 100 ? "" : "\n"); // Sending a heart beat
}
};

class AnnotateCallback : public MatchFinder::MatchCallback
{
public :
AnnotateCallback(Replacements& replacements) :
replacements_(replacements)
public:
AnnotateCallback(Replacements& replacements)
: replacements_(replacements)
{
}

virtual void run(const MatchFinder::MatchResult& result)
{
for (auto& i: categories_)
for (auto& i : categories_)
{
auto symbol = result.Nodes.getNodeAs<NamedDecl>(i);
auto symbol = result.Nodes.getNodeAs<clang::NamedDecl>(i);
if (symbol)
{
auto& data = categoryData_[i];
if (data.annotatedSymbols_.find(symbol->getName()) == data.annotatedSymbols_.end() &&
data.exposedSymbols_.find(symbol->getName()) == data.exposedSymbols_.end())
if (data.annotatedSymbols_.find(symbol->getName().str()) == data.annotatedSymbols_.end() &&
data.exposedSymbols_.find(symbol->getName().str()) == data.exposedSymbols_.end())
{
replacements_.insert(Replacement(*result.SourceManager, symbol->getLocation(), 0, "NONSCRIPTABLE "));
data.annotatedSymbols_.insert(symbol->getName());
auto error = replacements_.add(
Replacement(*result.SourceManager, symbol->getLocation(), 0, "NONSCRIPTABLE "));
data.annotatedSymbols_.insert(symbol->getName().str());
}
}
}
Expand All @@ -135,62 +133,65 @@ public :
int main(int argc, const char** argv)
{
// Parse the arguments and pass them to the the internal sub-tools
CommonOptionsParser optionsParser(argc, argv, annotatorCategory);
PathFilter bindingPathFilter
(optionsParser.getSourcePathList(), [](const std::string& path) { return path.find("API.cpp") != std::string::npos; });
PathFilter nonBindingPathFilter
(optionsParser.getSourcePathList(), [](const std::string& path) { return path.find("API.cpp") == std::string::npos; });
ClangTool bindingExtractor(optionsParser.getCompilations(), bindingPathFilter.GetPathList());
RefactoringTool annotator(optionsParser.getCompilations(), nonBindingPathFilter.GetPathList());
static llvm::Expected<CommonOptionsParser> optionsParser =
CommonOptionsParser::create(argc, argv, annotatorCategory);
PathFilter bindingPathFilter(optionsParser.get().getSourcePathList(),
[](const std::string& path) { return path.find("API.cpp") != std::string::npos; });
PathFilter nonBindingPathFilter(optionsParser.get().getSourcePathList(),
[](const std::string& path) { return path.find("API.cpp") == std::string::npos; });
ClangTool bindingExtractor(optionsParser.get().getCompilations(), bindingPathFilter.GetPathList());
RefactoringTool annotator(optionsParser.get().getCompilations(), nonBindingPathFilter.GetPathList());

// Setup finder to match against AST nodes from existing AngelScript binding source files
ExtractCallback extractCallback;
MatchFinder bindingFinder;
// Find exposed classes (they are registered through RegisterObjectType(), RegisterRefCounted(), RegisterObject(), etc)
bindingFinder.addMatcher(
memberCallExpr(
callee(
methodDecl(hasName("RegisterObjectType"))),
hasArgument(0, stringLiteral().bind("class"))), &extractCallback);
bindingFinder.addMatcher(
callExpr(
hasDeclaration(
functionDecl(hasParameter(1, hasName("className")))),
hasArgument(1, stringLiteral().bind("class"))), &extractCallback);
// Find exposed classes (they are registered through RegisterObjectType(), RegisterRefCounted(), RegisterObject(),
// etc)
bindingFinder.addMatcher(cxxMemberCallExpr(callee(cxxMethodDecl(hasName("RegisterObjectType"))),
hasArgument(0, stringLiteral().bind("class"))),
&extractCallback);
bindingFinder.addMatcher(callExpr(hasDeclaration(functionDecl(hasParameter(1, hasName("className")))),
hasArgument(1, stringLiteral().bind("class"))),
&extractCallback);
// Find exposed enums
bindingFinder.addMatcher(
memberCallExpr(
callee(
methodDecl(hasName("RegisterEnum"))),
hasArgument(0, stringLiteral().bind("enum"))), &extractCallback);
cxxMemberCallExpr(callee(cxxMethodDecl(hasName("RegisterEnum"))), hasArgument(0, stringLiteral().bind("enum"))),
&extractCallback);

// Setup finder to match against AST nodes for annotating Urho3D library source files
AnnotateCallback annotateCallback(annotator.getReplacements());
MatchFinder annotateFinder;
// Find exported class declarations with Urho3D namespace
annotateFinder.addMatcher(
recordDecl(
unless(hasAttr(attr::Annotate)),
bool valid = false;
for (auto& replacement : annotator.getReplacements())
{
AnnotateCallback annotateCallback(replacement.second);
MatchFinder annotateFinder;
// Find exported class declarations with Urho3D namespace
annotateFinder.addMatcher(recordDecl(unless(hasAttr(attr::Annotate)),
#ifndef _MSC_VER
hasAttr(attr::Visibility),
hasAttr(attr::Visibility),
#else
hasAttr(attr::DLLExport),
hasAttr(attr::DLLExport),
#endif
matchesName("^::Urho3D::")).bind("class"), &annotateCallback);
// Find enum declarations with Urho3D namespace
annotateFinder.addMatcher(
enumDecl(
unless(hasAttr(attr::Annotate)),
matchesName("^::Urho3D::")).bind("enum"), &annotateCallback);

// Unbuffered stdout stream to keep the Travis-CI's log flowing and thus prevent it from killing a potentially long running job
outs().SetUnbuffered();

// Success when both sub-tools are run successfully
return (outs() << "Extracting", true) &&
bindingExtractor.run(newFrontendActionFactory(&bindingFinder).get()) == EXIT_SUCCESS &&
(outs() << "\nAnnotating", true) &&
annotator.runAndSave(newFrontendActionFactory(&annotateFinder).get()) == EXIT_SUCCESS &&
(outs() << "\n", true) ?
EXIT_SUCCESS : EXIT_FAILURE;
matchesName("^::Urho3D::"))
.bind("class"),
&annotateCallback);
// Find enum declarations with Urho3D namespace
annotateFinder.addMatcher(enumDecl(unless(hasAttr(attr::Annotate)), matchesName("^::Urho3D::")).bind("enum"),
&annotateCallback);

// Unbuffered stdout stream to keep the Travis-CI's log flowing and thus prevent it from killing a potentially
// long running job
outs().SetUnbuffered();

// Success when both sub-tools are run successfully
valid = (outs() << "Extracting", true) &&
bindingExtractor.run(newFrontendActionFactory(&bindingFinder).get()) == EXIT_SUCCESS &&
(outs() << "\nAnnotating", true) &&
annotator.runAndSave(newFrontendActionFactory(&annotateFinder).get()) == EXIT_SUCCESS &&
(outs() << "\n", true);

if (!valid)
break;
}

return valid ? EXIT_SUCCESS : EXIT_FAILURE;
}
Loading

0 comments on commit f53c1fd

Please sign in to comment.