Skip to content

Commit

Permalink
feat(cmake): add helper function endstone_add_plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jul 28, 2024
1 parent ec181dd commit 1dee2f5
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions cmake/EndstoneHeaders.cmake
Original file line number Diff line number Diff line change
@@ -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.")
Expand All @@ -19,9 +35,9 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
endif ()


# ===============
# ===================
# Dependencies
# ===============
# ===================
include(FetchContent)
FetchContent_Declare(
fmt
Expand All @@ -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)
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()

0 comments on commit 1dee2f5

Please sign in to comment.