2023-07-27 00:53:04 +02:00
|
|
|
macro(add_imhex_plugin)
|
2023-08-22 19:29:03 +02:00
|
|
|
# Parse arguments
|
2023-12-23 21:09:41 +01:00
|
|
|
set(options LIBRARY_PLUGIN)
|
2023-07-27 00:53:04 +02:00
|
|
|
set(oneValueArgs NAME)
|
|
|
|
set(multiValueArgs SOURCES INCLUDES LIBRARIES)
|
|
|
|
cmake_parse_arguments(IMHEX_PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
2023-10-04 12:00:32 +02:00
|
|
|
|
|
|
|
if (IMHEX_STATIC_LINK_PLUGINS)
|
|
|
|
set(IMHEX_PLUGIN_LIBRARY_TYPE STATIC)
|
|
|
|
|
|
|
|
target_link_libraries(libimhex PUBLIC ${IMHEX_PLUGIN_NAME})
|
|
|
|
|
|
|
|
configure_file(${CMAKE_SOURCE_DIR}/dist/web/plugin-bundle.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/plugin-bundle.cpp @ONLY)
|
|
|
|
target_sources(main PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/plugin-bundle.cpp)
|
2023-12-23 21:09:41 +01:00
|
|
|
set(IMHEX_PLUGIN_SUFFIX ".hexplug")
|
2023-10-04 12:00:32 +02:00
|
|
|
else()
|
2023-12-23 21:09:41 +01:00
|
|
|
if (IMHEX_PLUGIN_LIBRARY_PLUGIN)
|
|
|
|
set(IMHEX_PLUGIN_LIBRARY_TYPE SHARED)
|
|
|
|
set(IMHEX_PLUGIN_SUFFIX ".hexpluglib")
|
|
|
|
else()
|
|
|
|
set(IMHEX_PLUGIN_LIBRARY_TYPE MODULE)
|
|
|
|
set(IMHEX_PLUGIN_SUFFIX ".hexplug")
|
|
|
|
endif()
|
2023-10-04 12:00:32 +02:00
|
|
|
endif()
|
|
|
|
|
2023-08-22 19:29:03 +02:00
|
|
|
# Define new project for plugin
|
2023-07-27 00:53:04 +02:00
|
|
|
project(${IMHEX_PLUGIN_NAME})
|
|
|
|
|
2023-08-22 19:29:03 +02:00
|
|
|
# Create a new shared library for the plugin source code
|
2023-10-04 12:00:32 +02:00
|
|
|
add_library(${IMHEX_PLUGIN_NAME} ${IMHEX_PLUGIN_LIBRARY_TYPE} ${IMHEX_PLUGIN_SOURCES})
|
2023-07-27 00:53:04 +02:00
|
|
|
|
2023-08-22 19:29:03 +02:00
|
|
|
# Add include directories and link libraries
|
2023-10-04 12:00:32 +02:00
|
|
|
target_include_directories(${IMHEX_PLUGIN_NAME} PUBLIC ${IMHEX_PLUGIN_INCLUDES})
|
2023-12-23 21:09:41 +01:00
|
|
|
target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE libimhex ${IMHEX_PLUGIN_LIBRARIES} ${FMT_LIBRARIES} imgui_all_includes libwolv)
|
2023-12-22 23:39:38 +01:00
|
|
|
addIncludesFromLibrary(${IMHEX_PLUGIN_NAME} libpl)
|
2023-07-27 00:53:04 +02:00
|
|
|
|
2023-08-22 19:29:03 +02:00
|
|
|
# Add IMHEX_PROJECT_NAME and IMHEX_VERSION define
|
2023-07-27 00:53:04 +02:00
|
|
|
target_compile_definitions(${IMHEX_PLUGIN_NAME} PRIVATE IMHEX_PROJECT_NAME="${IMHEX_PLUGIN_NAME}")
|
|
|
|
target_compile_definitions(${IMHEX_PLUGIN_NAME} PRIVATE IMHEX_VERSION="${IMHEX_VERSION_STRING}")
|
2023-10-04 12:00:32 +02:00
|
|
|
target_compile_definitions(${IMHEX_PLUGIN_NAME} PRIVATE IMHEX_PLUGIN_NAME=${IMHEX_PLUGIN_NAME})
|
2023-07-27 00:53:04 +02:00
|
|
|
|
2023-08-22 19:29:03 +02:00
|
|
|
# Enable required compiler flags
|
2023-07-27 00:53:04 +02:00
|
|
|
set_target_properties(${IMHEX_PLUGIN_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
2023-11-30 10:22:15 +01:00
|
|
|
enableUnityBuild(${IMHEX_PLUGIN_NAME})
|
2023-07-27 00:53:04 +02:00
|
|
|
setupCompilerFlags(${IMHEX_PLUGIN_NAME})
|
|
|
|
|
2023-08-22 19:29:03 +02:00
|
|
|
# Configure build properties
|
|
|
|
set_target_properties(${IMHEX_PLUGIN_NAME}
|
|
|
|
PROPERTIES
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins
|
|
|
|
CXX_STANDARD 23
|
|
|
|
PREFIX ""
|
2023-12-23 21:09:41 +01:00
|
|
|
SUFFIX ${IMHEX_PLUGIN_SUFFIX}
|
2023-08-22 19:29:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Setup a romfs for the plugin
|
2023-10-29 19:43:40 +01:00
|
|
|
list(APPEND LIBROMFS_RESOURCE_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/romfs)
|
2023-07-27 00:53:04 +02:00
|
|
|
set(LIBROMFS_PROJECT_NAME ${IMHEX_PLUGIN_NAME})
|
|
|
|
add_subdirectory(${IMHEX_BASE_FOLDER}/lib/external/libromfs ${CMAKE_CURRENT_BINARY_DIR}/libromfs)
|
|
|
|
set_target_properties(${LIBROMFS_LIBRARY} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|
|
|
target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE ${LIBROMFS_LIBRARY})
|
2023-07-27 02:07:36 +02:00
|
|
|
|
2023-08-22 19:29:03 +02:00
|
|
|
# Add the new plugin to the main dependency list so it gets built by default
|
2023-12-22 23:39:38 +01:00
|
|
|
if (TARGET imhex_all)
|
|
|
|
add_dependencies(imhex_all ${IMHEX_PLUGIN_NAME})
|
|
|
|
endif()
|
2023-08-22 19:29:03 +02:00
|
|
|
endmacro()
|
2023-10-29 19:43:40 +01:00
|
|
|
|
|
|
|
macro(add_romfs_resource input output)
|
|
|
|
configure_file(${input} ${CMAKE_CURRENT_BINARY_DIR}/romfs/${output} COPYONLY)
|
|
|
|
|
|
|
|
list(APPEND LIBROMFS_RESOURCE_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/romfs)
|
|
|
|
endmacro()
|