fix(autogen): fixed compilation on windows + clang dependency
This commit is contained in:
parent
2bf5a269d6
commit
7a1a42788e
12 changed files with 80 additions and 21 deletions
4
BUILD.md
4
BUILD.md
|
@ -38,10 +38,12 @@ Now, generate the build files with cmake via the vcpkg preset:
|
|||
|
||||
cmake -Bbuild . --preset vcpkg
|
||||
|
||||
Then, finally, build in release mode:
|
||||
Then, finally, build in release mode\*:
|
||||
|
||||
cmake --build build --config Release
|
||||
|
||||
The compiled binaries should then be placed in `./build/bin/` and should be ready for redistribution without any further work.
|
||||
|
||||
If any of the compilation steps fail, or the binaries fail to execute, please create an issue so that this can be corrected.
|
||||
|
||||
\* Release mode is necessary as debug mode copies DLLs that are not linked to the output binary
|
|
@ -4,7 +4,7 @@ project(openblocks VERSION 0.1.0)
|
|||
set(OpenGL_GL_PREFERENCE "GLVND")
|
||||
|
||||
if (MSVC)
|
||||
add_compile_options(/W4 /WX)
|
||||
add_compile_options(/W4)
|
||||
else()
|
||||
add_compile_options(-Wall -Wextra -pedantic -Wno-unused-parameter)
|
||||
endif()
|
||||
|
|
|
@ -13,5 +13,5 @@ add_executable(autogen
|
|||
)
|
||||
|
||||
set_target_properties(autogen PROPERTIES OUTPUT_NAME "autogen")
|
||||
target_link_libraries(autogen -lclang)
|
||||
target_include_directories(autogen PUBLIC "src" ${CLANG_INCLUDE_DIRS})
|
||||
target_link_libraries(autogen ${CLANG_LIBRARY})
|
||||
target_include_directories(autogen PUBLIC "src" ${CLANG_INCLUDE_DIR})
|
|
@ -12,6 +12,7 @@
|
|||
#include "object/codegen.h"
|
||||
#include "data/analysis.h"
|
||||
#include "data/codegen.h"
|
||||
#include "util.h"
|
||||
|
||||
// namespace data {
|
||||
// #include "data/analysis.h"
|
||||
|
@ -22,13 +23,17 @@ namespace fs = std::filesystem;
|
|||
|
||||
// https://clang.llvm.org/docs/LibClang.html
|
||||
int processHeader(fs::path srcRoot, fs::path srcPath, fs::path outPath) {
|
||||
const char* cargs[] = { "-x", "c++", "-I", srcRoot.c_str(), "-D__AUTOGEN__", 0 };
|
||||
std::string srcRootStr = string_of(srcRoot);
|
||||
std::string srcPathStr = string_of(srcPath);
|
||||
std::string outPathStr = string_of(outPath);
|
||||
|
||||
const char* cargs[] = { "-xc++", "-std=c++17", "-I", srcRootStr.c_str(), "-D__AUTOGEN__", 0 };
|
||||
// THANK YOU SO MUCH THIS STACKOVERFLOW ANSWER IS SO HELPFUL
|
||||
// https://stackoverflow.com/a/59206378/16255372
|
||||
CXIndex index = clang_createIndex(0, 0);
|
||||
CXTranslationUnit unit = clang_parseTranslationUnit(
|
||||
index,
|
||||
srcPath.c_str(), cargs, 5,
|
||||
srcPathStr.c_str(), cargs, 5,
|
||||
nullptr, 0,
|
||||
CXTranslationUnit_None);
|
||||
|
||||
|
@ -55,15 +60,16 @@ int processHeader(fs::path srcRoot, fs::path srcPath, fs::path outPath) {
|
|||
enum_::AnalysisState enumAnlyState;
|
||||
|
||||
fs::path relpath = fs::relative(srcPath, srcRoot);
|
||||
printf("[AUTOGEN] Processing file %s...\n", relpath.c_str());
|
||||
object::analyzeClasses(cursor, srcRoot, &objectAnlyState);
|
||||
data::analyzeClasses(cursor, srcRoot, &dataAnlyState);
|
||||
enum_::analyzeClasses(cursor, srcRoot, &enumAnlyState);
|
||||
std::string relpathStr = string_of(relpath);
|
||||
printf("[AUTOGEN] Processing file %s...\n", relpathStr.c_str());
|
||||
object::analyzeClasses(cursor, srcRootStr, &objectAnlyState);
|
||||
data::analyzeClasses(cursor, srcRootStr, &dataAnlyState);
|
||||
enum_::analyzeClasses(cursor, srcRootStr, &enumAnlyState);
|
||||
|
||||
fs::create_directories(outPath.parent_path()); // Make sure generated dir exists before we try writing to it
|
||||
|
||||
printf("[AUTOGEN] Generating file %s...\n", relpath.c_str());
|
||||
std::ofstream outStream(outPath);
|
||||
printf("[AUTOGEN] Generating file %s...\n", relpathStr.c_str());
|
||||
std::ofstream outStream(outPathStr);
|
||||
|
||||
if (!objectAnlyState.classes.empty() || !dataAnlyState.classes.empty()) {
|
||||
outStream << "/////////////////////////////////////////////////////////////////////////////////////////\n";
|
||||
|
@ -72,15 +78,15 @@ int processHeader(fs::path srcRoot, fs::path srcPath, fs::path outPath) {
|
|||
}
|
||||
|
||||
for (auto& [_, clazz] : objectAnlyState.classes) {
|
||||
object::writeCodeForClass(outStream, relpath, clazz);
|
||||
object::writeCodeForClass(outStream, relpathStr, clazz);
|
||||
}
|
||||
|
||||
for (auto& [_, clazz] : dataAnlyState.classes) {
|
||||
data::writeCodeForClass(outStream, relpath, clazz);
|
||||
data::writeCodeForClass(outStream, relpathStr, clazz);
|
||||
}
|
||||
|
||||
for (auto& [_, clazz] : enumAnlyState.classes) {
|
||||
enum_::writeCodeForClass(outStream, relpath, clazz);
|
||||
enum_::writeCodeForClass(outStream, relpathStr, clazz);
|
||||
}
|
||||
|
||||
outStream.close();
|
||||
|
|
|
@ -162,7 +162,7 @@ static void processClass(CXCursor cur, AnalysisState* state, std::string classNa
|
|||
|
||||
anly.name = className;
|
||||
anly.baseClass = baseClass;
|
||||
anly.headerPath = headerPath;
|
||||
anly.headerPath = string_of(headerPath);
|
||||
|
||||
// Add misc flags and options
|
||||
auto instanceDef = findAnnotation(cur, "OB::def_inst");
|
||||
|
|
|
@ -109,3 +109,7 @@ std::optional<std::string> findAnnotation(CXCursor cur, std::string annotationNa
|
|||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string string_of(std::filesystem::path path) {
|
||||
return path.string();
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
typedef std::function<CXChildVisitResult(CXCursor cursor, CXCursor parent)> X_CXCursorVisitor;
|
||||
|
||||
|
@ -20,3 +21,5 @@ std::string x_clang_toString(CXString string);
|
|||
std::map<std::string, std::string> parseAnnotationString(std::string src);
|
||||
|
||||
std::optional<std::string> findAnnotation(CXCursor cur, std::string annotationName);
|
||||
|
||||
std::string string_of(std::filesystem::path path);
|
42
cmake/FindClang.cmake
Normal file
42
cmake/FindClang.cmake
Normal file
|
@ -0,0 +1,42 @@
|
|||
# Modified from QGIS' FindQScintilla.cmake by Thomas Moenicke, Larry Schaffer
|
||||
|
||||
add_library(Clang::Clang UNKNOWN IMPORTED)
|
||||
|
||||
FIND_PATH(CLANG_INCLUDE_DIR
|
||||
NAMES clang-c/Index.h
|
||||
PATHS
|
||||
$ENV{LIB_DIR}/include
|
||||
/usr/local/include
|
||||
/usr/include
|
||||
${VCPKG_INSTALLED_DIR}/x64-windows/include
|
||||
"C:/Program Files/LLVM/include"
|
||||
PATH_SUFFIXES ${CLANG_PATH_SUFFIXES}
|
||||
)
|
||||
|
||||
set(CLANG_LIBRARY_NAMES
|
||||
libclang
|
||||
clang
|
||||
)
|
||||
|
||||
find_library(CLANG_LIBRARY
|
||||
NAMES ${CLANG_LIBRARY_NAMES}
|
||||
PATHS
|
||||
$ENV{LIB_DIR}/lib
|
||||
/usr/local/lib
|
||||
/usr/lib
|
||||
${VCPKG_INSTALLED_DIR}/x64-windows/lib
|
||||
"C:/Program Files/LLVM/lib"
|
||||
)
|
||||
|
||||
get_filename_component(CLANG_LIB_DIR ${CLANG_LIBRARY} DIRECTORY)
|
||||
list(TRANSFORM CLANG_LIBRARY_NAMES APPEND ".dll" OUTPUT_VARIABLE CLANG_DLL_NAMES)
|
||||
|
||||
find_file(CLANG_DLLS
|
||||
NAMES ${CLANG_DLL_NAMES}
|
||||
PATHS
|
||||
$ENV{LIB_DIR}/bin
|
||||
/usr/local/bin
|
||||
/usr/bin
|
||||
${VCPKG_INSTALLED_DIR}/x64-windows/bin
|
||||
"C:/Program Files/LLVM/bin"
|
||||
)
|
|
@ -29,7 +29,7 @@ foreach (SRC ${AUTOGEN_SOURCES})
|
|||
OUTPUT "${OUT_PATH}"
|
||||
DEPENDS autogen
|
||||
DEPENDS "${SRC_PATH}"
|
||||
COMMAND "${CMAKE_BINARY_DIR}/autogen/autogen" "${CMAKE_CURRENT_SOURCE_DIR}/src" "${SRC_PATH}" "${OUT_PATH}"
|
||||
COMMAND "$<TARGET_FILE:autogen>" "${CMAKE_CURRENT_SOURCE_DIR}/src" "${SRC_PATH}" "${OUT_PATH}"
|
||||
)
|
||||
|
||||
list(APPEND AUTOGEN_OUTS "${OUT_PATH}")
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <pugixml.hpp>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
Color3::Color3(float r, float g, float b) : r(std::clamp(r, 0.f, 1.f)), g(std::clamp(g, 0.f, 1.f)), b(std::clamp(b, 0.f, 1.f)) {};
|
||||
Color3::Color3(const glm::vec3& vec) : r(std::clamp(vec.x, 0.f, 1.f)), g(std::clamp(vec.y, 0.f, 1.f)), b(std::clamp(vec.z, 0.f, 1.f)) {};
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
#include "error/data.h"
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/geometric.hpp>
|
||||
#include <reactphysics3d/mathematics/Vector3.h>
|
||||
|
||||
namespace reactphysics3d { class Vector3; };
|
||||
// namespace reactphysics3d { class Vector3; };
|
||||
|
||||
class DEF_DATA Vector3 {
|
||||
AUTOGEN_PREAMBLE_DATA
|
||||
|
|
|
@ -73,7 +73,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
if (isDarkMode())
|
||||
QIcon::setFallbackThemeName("editor-dark");
|
||||
else
|
||||
QIcon::setFallbackThemeName("editor");
|
||||
QIcon::setThemeName("editor");
|
||||
|
||||
// qApp->setStyle(QStyleFactory::create("fusion"));
|
||||
defaultMessageHandler = qInstallMessageHandler(logQtMessage);
|
||||
|
|
Loading…
Add table
Reference in a new issue