From 3b11fd1466af169d22942a92583504580ec8b79a Mon Sep 17 00:00:00 2001 From: muit Date: Sat, 27 Aug 2022 12:32:22 +0200 Subject: [PATCH] Added Clang --- CMake/LLVM.cmake | 23 +++++++++++++++---- Libs/Bindings/Native/CMakeLists.txt | 22 ++++++++++++++++++ Libs/Bindings/Native/Include/NativeBinding.h | 18 +++++++++++++++ Libs/Bindings/Native/README.md | 3 +++ Libs/Bindings/Native/Src/NativeBinding.cpp | 5 ++++ Libs/Bindings/Native/Src/NativeModule.cpp | 4 ++++ Libs/CMakeLists.txt | 1 + .../Include/AST/Components/CModule.h | 2 +- Libs/Framework/Include/Rift.h | 1 + 9 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 Libs/Bindings/Native/CMakeLists.txt create mode 100644 Libs/Bindings/Native/Include/NativeBinding.h create mode 100644 Libs/Bindings/Native/README.md create mode 100644 Libs/Bindings/Native/Src/NativeBinding.cpp create mode 100644 Libs/Bindings/Native/Src/NativeModule.cpp diff --git a/CMake/LLVM.cmake b/CMake/LLVM.cmake index 51688899..9133a3b1 100644 --- a/CMake/LLVM.cmake +++ b/CMake/LLVM.cmake @@ -18,20 +18,30 @@ endif() # Check if RIFT_LLVM_PATH should be used if (NOT RIFT_LLVM_PATH STREQUAL "") message(STATUS "Provided explicit LLVM path: ${RIFT_LLVM_PATH}") + set(RIFT_LLVM_BIN_PATH ${RIFT_LLVM_PATH}) elseif (RIFT_DEFAULT_TO_INTERNAL_LLVM AND NOT RIFT_INTERNAL_LLVM_PATH STREQUAL "") - set(RIFT_LLVM_PATH ${RIFT_INTERNAL_LLVM_PATH}/build/${CMAKE_BUILD_TYPE}) + set(RIFT_LLVM_PATH ${RIFT_INTERNAL_LLVM_PATH}/build) + set(RIFT_LLVM_BIN_PATH ${RIFT_LLVM_PATH}/${CMAKE_BUILD_TYPE}) message(STATUS "Provided internal LLVM path: ${RIFT_LLVM_PATH}") else() message(STATUS "LLVM path not provided. Will be searched in the system") + set(RIFT_LLVM_BIN_PATH ${RIFT_LLVM_PATH}) endif() -set(LLVM_DIR "${RIFT_LLVM_PATH}/lib/cmake/llvm") +set(LLVM_DIR "${RIFT_LLVM_PATH}/lib/cmake/llvm") find_package(LLVM REQUIRED CONFIG) list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") include(AddLLVM) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") +set(Clang_DIR "${RIFT_LLVM_PATH}/lib/cmake/clang") +find_package(Clang REQUIRED CONFIG) +list(APPEND CMAKE_MODULE_PATH "${CLANG_CMAKE_DIR}") +include(AddClang) +message(STATUS "Found CLANG ${CLANG_PACKAGE_VERSION}") +message(STATUS "Using CLANGConfig.cmake in: ${Clang_DIR}") + separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS}) message(STATUS "LLVM_LIBS: ${LLVM_AVAILABLE_LIBS}") message(STATUS "LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}") @@ -43,11 +53,16 @@ add_library(RiftLLVM INTERFACE) target_include_directories(RiftLLVM INTERFACE ${LLVM_INCLUDE_DIRS}) llvm_map_components_to_libnames(llvm_libs core x86asmparser x86codegen) target_link_libraries(RiftLLVM INTERFACE ${LLVM_AVAILABLE_LIBS}) -target_compile_definitions(RiftLLVM INTERFACE ${LLVM_DEFINITIONS_LIST} -DNOMINMAX) +target_compile_definitions(RiftLLVM INTERFACE ${LLVM_DEFINITIONS_LIST} -DNOMINMAX) #if(COMPILER_CLANG) #target_compile_options(RiftLLVM INTERFACE -fms-compatibility-version=14.20) #endif() # pipe_target_disable_all_warnings(LLVM INTERFACE) +add_library(RiftClang INTERFACE) +target_include_directories(RiftClang INTERFACE ${CLANG_INCLUDE_DIRS}) +target_link_libraries(RiftClang INTERFACE ${CLANG_AVAILABLE_LIBS}) +target_compile_definitions(RiftClang INTERFACE ${CLANG_DEFINITIONS_LIST} -DNOMINMAX) +target_link_libraries(RiftClang INTERFACE RiftLLVM) # Copy LLVM linker if (PLATFORM_WINDOWS) @@ -59,6 +74,6 @@ elseif(PLATFORM_MACOS) endif() file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/Bin/llvm) -file(COPY ${RIFT_LLVM_PATH}/bin/${RIFT_LLVM_LINKER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Bin/llvm) +file(COPY ${RIFT_LLVM_BIN_PATH}/bin/${RIFT_LLVM_LINKER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Bin/llvm) set(RIFT_LLVM_LINKER_PATH llvm/${RIFT_LLVM_LINKER}) diff --git a/Libs/Bindings/Native/CMakeLists.txt b/Libs/Bindings/Native/CMakeLists.txt new file mode 100644 index 00000000..d04f5c03 --- /dev/null +++ b/Libs/Bindings/Native/CMakeLists.txt @@ -0,0 +1,22 @@ + +file(GLOB_RECURSE BACKEND_CPP_SOURCE_FILES CONFIGURE_DEPENDS Src/*.cpp Src/*.h) + +add_library(RiftBindingNative STATIC) +add_library(rift::Bindings::Native ALIAS RiftBindingNative) +target_include_directories(RiftBindingNative PUBLIC Include) +target_sources(RiftBindingNative PRIVATE ${BACKEND_CPP_SOURCE_FILES}) +pipe_target_enable_CPP20(RiftBindingNative) +set_target_properties (RiftBindingNative PROPERTIES FOLDER Rift) +pipe_target_define_platform(RiftBindingNative) +pipe_target_shared_output_directory(RiftBindingNative) + +target_link_libraries(RiftBindingNative PUBLIC rift::Rift) +target_link_libraries(RiftBindingNative PRIVATE RiftClang) + +install(TARGETS RiftBindingNative + EXPORT RiftTargets + LIBRARY DESTINATION Lib + ARCHIVE DESTINATION Lib + RUNTIME DESTINATION Bin + INCLUDES DESTINATION Include +) diff --git a/Libs/Bindings/Native/Include/NativeBinding.h b/Libs/Bindings/Native/Include/NativeBinding.h new file mode 100644 index 00000000..40e29d05 --- /dev/null +++ b/Libs/Bindings/Native/Include/NativeBinding.h @@ -0,0 +1,18 @@ +// Copyright 2015-2022 Piperift - All rights reserved + +#pragma once + +#include +#include + + +namespace rift +{ + class NativeBindingPlugin : public Plugin + { + CLASS(NativeBindingPlugin, Plugin) + + public: + void Register(TPtr rift) override {} + }; +} // namespace rift diff --git a/Libs/Bindings/Native/README.md b/Libs/Bindings/Native/README.md new file mode 100644 index 00000000..951523fb --- /dev/null +++ b/Libs/Bindings/Native/README.md @@ -0,0 +1,3 @@ +# Native Binding + +This plugin allows Rift to understand C and Cpp headers and use them to link against their binaries. diff --git a/Libs/Bindings/Native/Src/NativeBinding.cpp b/Libs/Bindings/Native/Src/NativeBinding.cpp new file mode 100644 index 00000000..456744c9 --- /dev/null +++ b/Libs/Bindings/Native/Src/NativeBinding.cpp @@ -0,0 +1,5 @@ +// Copyright 2015-2022 Piperift - All rights reserved + +#include "NativeBinding.h" + +#include diff --git a/Libs/Bindings/Native/Src/NativeModule.cpp b/Libs/Bindings/Native/Src/NativeModule.cpp new file mode 100644 index 00000000..cdc5c143 --- /dev/null +++ b/Libs/Bindings/Native/Src/NativeModule.cpp @@ -0,0 +1,4 @@ +// Copyright 2015-2022 Piperift - All rights reserved + +#include +// PIPE_OVERRIDE_NEW_DELETE diff --git a/Libs/CMakeLists.txt b/Libs/CMakeLists.txt index 80e34702..c23c55c2 100644 --- a/Libs/CMakeLists.txt +++ b/Libs/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(Pipe) add_subdirectory(Framework) add_subdirectory(Backends/LLVM) add_subdirectory(Backends/Cpp) +add_subdirectory(Bindings/Native) add_subdirectory(UI) add_subdirectory(Views/Graph) diff --git a/Libs/Framework/Include/AST/Components/CModule.h b/Libs/Framework/Include/AST/Components/CModule.h index 0d508d2f..e38eb390 100644 --- a/Libs/Framework/Include/AST/Components/CModule.h +++ b/Libs/Framework/Include/AST/Components/CModule.h @@ -20,7 +20,7 @@ namespace rift enum class ModuleType : u8 { Rift, - CBinding + Native }; } // namespace rift // TODO: Simplify enum reflection so that ENUM() is not needed diff --git a/Libs/Framework/Include/Rift.h b/Libs/Framework/Include/Rift.h index 999408b3..d69b486f 100644 --- a/Libs/Framework/Include/Rift.h +++ b/Libs/Framework/Include/Rift.h @@ -25,6 +25,7 @@ namespace rift template void AddPlugin() { + // TODO: Ensure unique plugins.Add(MakeOwned()); }