Skip to content

Commit

Permalink
Merge pull request #298 from rxbryan/metacall-refactor1
Browse files Browse the repository at this point in the history
add core plugin for cli-refactor
  • Loading branch information
viferga authored Jul 21, 2022
2 parents 8b52f1d + e8ae71d commit 863f5cd
Show file tree
Hide file tree
Showing 10 changed files with 870 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ endif()

# CLI applications
add_subdirectory(metacallcli)
add_subdirectory(plugins)
13 changes: 13 additions & 0 deletions source/cli/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Check if extension loader is enabled
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS)
return()
endif()

# Extension sub-projects
add_subdirectory(core_plugin)

#Install plugin directory
install(DIRECTORY ${PROJECT_OUTPUT_DIR}/plugins
DESTINATION ${INSTALL_LIB}
PATTERN "test[-_]*" EXCLUDE
)
212 changes: 212 additions & 0 deletions source/cli/plugins/core_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# Check if this loader is enabled
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_EXTENSIONS OR NOT OPTION_BUILD_EXTENSIONS_LOAD)
return()
endif()

#
# Plugin name and options
#

# Target name
set(target core_plugin)

# Exit here if required dependencies are not met
message(STATUS "Plugin ${target}")

# Set API export file and macro
string(TOUPPER ${target} target_upper)
set(feature_file "include/${target}/${target}_features.h")
set(export_file "include/${target}/${target}_api.h")
set(export_macro "${target_upper}_API")

#
# Compiler warnings
#

include(Warnings)

#
# Compiler security
#

include(SecurityFlags)

#
# Sources
#

set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")

set(headers
${include_path}/core_plugin.h
)

set(sources
${source_path}/core_plugin.cpp
)

# Group source files
set(header_group "Header Files (API)")
set(source_group "Source Files")
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
${header_group} ${headers})
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
${source_group} ${sources})

#
# Create library
#

# Build library
add_library(${target} MODULE
${sources}
${headers}
)

# Create namespaced alias
add_library(${META_PROJECT_NAME}::${target} ALIAS ${target})

# Export library for downstream projects
export(TARGETS ${target} NAMESPACE ${META_PROJECT_NAME}:: FILE ${PROJECT_BINARY_DIR}/cmake/${target}/${target}-export.cmake)

# Create feature detection header
# Compilers: https://cmake.org/cmake/help/v3.1/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_%3CLANG%3E_COMPILER_ID
# Feature: https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html

# Check for availability of module; use pre-generated version if not found
if (WriterCompilerDetectionHeaderFound)
write_compiler_detection_header(
FILE ${feature_file}
PREFIX ${target_upper}
COMPILERS AppleClang Clang GNU MSVC
FEATURES cxx_alignas cxx_alignof cxx_constexpr cxx_final cxx_noexcept cxx_nullptr cxx_sizeof_member cxx_thread_local
VERSION 3.2
)
else()
file(
COPY ${PROJECT_SOURCE_DIR}/codegeneration/${target}_features.h
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/${target}
USE_SOURCE_PERMISSIONS
)
endif()

# Create API export header
generate_export_header(${target}
EXPORT_FILE_NAME ${export_file}
EXPORT_MACRO_NAME ${export_macro}
)

#
# Project options
#

set_target_properties(${target}
PROPERTIES
${DEFAULT_PROJECT_OPTIONS}
FOLDER "${IDE_FOLDER}"
BUNDLE $<$<BOOL:${APPLE}>:$<$<VERSION_GREATER:${PROJECT_OS_VERSION},8>>>
)

#
# Include directories
#

target_include_directories(${target}
PRIVATE
${PROJECT_BINARY_DIR}/source/include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include

$<TARGET_PROPERTY:${META_PROJECT_NAME}::metacall,INCLUDE_DIRECTORIES> # MetaCall includes

PUBLIC
${DEFAULT_INCLUDE_DIRECTORIES}

INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)

#
# Libraries
#

target_link_libraries(${target}
PRIVATE
${META_PROJECT_NAME}::metacall # MetaCall library

PUBLIC
${DEFAULT_LIBRARIES}

INTERFACE
)

#
# Compile definitions
#

target_compile_definitions(${target}
PRIVATE

PUBLIC
$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:${target_upper}_STATIC_DEFINE>
${DEFAULT_COMPILE_DEFINITIONS}

INTERFACE
)

#
# Compile options
#

target_compile_options(${target}
PRIVATE

PUBLIC
${DEFAULT_COMPILE_OPTIONS}

INTERFACE
)

#
# Linker options
#

target_link_libraries(${target}
PRIVATE

PUBLIC
${DEFAULT_LINKER_OPTIONS}

INTERFACE
)


#
# Define dependencies
#

add_dependencies(${target}
plugin_extension
)

#
# Deployment
#

#Copy metacall-*.json
add_custom_target(${target}-create-plugin-dir ALL
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_OUTPUT_DIR}/plugins/core_plugin
COMMAND ${CMAKE_COMMAND} -E copy ${source_path}/metacall-core_plugin.json ${PROJECT_OUTPUT_DIR}/plugins/core_plugin
)

# Library
install(TARGETS ${target}
EXPORT "${target}-export" COMPONENT dev
RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT runtime
LIBRARY DESTINATION ${INSTALL_SHARED} COMPONENT runtime
ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT dev
)
20 changes: 20 additions & 0 deletions source/cli/plugins/core_plugin/include/core_plugin/core_plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef CORE_PLUGIN_H
#define CORE_PLUGIN_H 1

#include <core_plugin/core_plugin_api.h>

#include <dynlink/dynlink.h>

#ifdef __cplusplus
extern "C" {
#endif

CORE_PLUGIN_API int core_plugin(void *loader, void *handle, void *context);

DYNLINK_SYMBOL_EXPORT(core_plugin);

#ifdef __cplusplus
}
#endif

#endif /* CORE_PLUGIN_H */
Loading

0 comments on commit 863f5cd

Please sign in to comment.