Skip to content

Commit

Permalink
Merge pull request #77 from PipeRift/feature/cpp-binding
Browse files Browse the repository at this point in the history
Added Clang
  • Loading branch information
muit authored Aug 27, 2022
2 parents aad8d4a + 3b11fd1 commit 44486c4
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 5 deletions.
23 changes: 19 additions & 4 deletions CMake/LLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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)
Expand All @@ -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})

22 changes: 22 additions & 0 deletions Libs/Bindings/Native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
18 changes: 18 additions & 0 deletions Libs/Bindings/Native/Include/NativeBinding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2015-2022 Piperift - All rights reserved

#pragma once

#include <Plugin.h>
#include <Rift.h>


namespace rift
{
class NativeBindingPlugin : public Plugin
{
CLASS(NativeBindingPlugin, Plugin)

public:
void Register(TPtr<Rift> rift) override {}
};
} // namespace rift
3 changes: 3 additions & 0 deletions Libs/Bindings/Native/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Native Binding

This plugin allows Rift to understand C and Cpp headers and use them to link against their binaries.
5 changes: 5 additions & 0 deletions Libs/Bindings/Native/Src/NativeBinding.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2015-2022 Piperift - All rights reserved

#include "NativeBinding.h"

#include <clang/Index/IndexSymbol.h>
4 changes: 4 additions & 0 deletions Libs/Bindings/Native/Src/NativeModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2015-2022 Piperift - All rights reserved

#include <Pipe/Memory/NewDelete.h>
// PIPE_OVERRIDE_NEW_DELETE
1 change: 1 addition & 0 deletions Libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Libs/Framework/Include/AST/Components/CModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Libs/Framework/Include/Rift.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace rift
template<typename T>
void AddPlugin()
{
// TODO: Ensure unique
plugins.Add(MakeOwned<T>());
}

Expand Down

0 comments on commit 44486c4

Please sign in to comment.