diff --git a/cmake/EndstoneHeaders.cmake b/cmake/EndstoneHeaders.cmake index eac725fa2..7a7243265 100644 --- a/cmake/EndstoneHeaders.cmake +++ b/cmake/EndstoneHeaders.cmake @@ -1,6 +1,22 @@ -# =============== +# EndstoneHeaders.cmake -- Build system for endstone plugins +# +# Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# =================== # Compiler Check -# =============== +# =================== if (WIN32) if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") message(FATAL_ERROR "MSVC is required on Windows.") @@ -19,9 +35,9 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") endif () -# =============== +# =================== # Dependencies -# =============== +# =================== include(FetchContent) FetchContent_Declare( fmt @@ -31,10 +47,27 @@ FetchContent_Declare( FetchContent_MakeAvailable(fmt) -# =============== +# =================== # Endstone API -# =============== +# =================== add_library(endstone_headers INTERFACE) add_library(endstone::headers ALIAS endstone_headers) target_include_directories(endstone_headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_link_libraries(endstone_headers INTERFACE fmt::fmt) \ No newline at end of file +target_link_libraries(endstone_headers INTERFACE fmt::fmt) + +# =================== +# Endstone Add Plugin +# =================== +function(endstone_add_plugin target_name) + cmake_parse_arguments(PARSE_ARGV 1 ARG "" "" "") + + add_library(${target_name} SHARED ${ARG_UNPARSED_ARGUMENTS}) + target_include_directories(${target_name} PUBLIC include) + target_link_libraries(${target_name} PRIVATE endstone::headers) + set_target_properties(${target_name} PROPERTIES PREFIX "endstone_") + + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(${target_name} PRIVATE -stdlib=libc++ -fPIC) + target_link_libraries(${target_name} PRIVATE -static-libgcc -static-libstdc++ libc++.a libc++abi.a) + endif () +endfunction()