diff --git a/CMakeLists.txt b/CMakeLists.txt index 0407b84..63a8aa3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,48 +1,11 @@ cmake_minimum_required(VERSION 3.25 FATAL_ERROR) # Create project -if (APPLE) - set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "" FORCE) -endif() project(godotrmlui - VERSION "0.1.0") -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Include CMake libraries -include(CheckIPOSupported) - -# Set up variables -set(GDRML_ARCH ${CMAKE_SYSTEM_PROCESSOR}) -if (APPLE) - set(GDRML_ARCH "universal") -endif() -set(GDRML_ADDON_DIR "${CMAKE_CURRENT_SOURCE_DIR}/project/addons/${PROJECT_NAME}") -set(GDRML_BIN_DIR "${GDRML_ADDON_DIR}/bin") -set(GDRML_LIB_DIR "${CMAKE_SYSTEM_NAME}_${GDRML_ARCH}") - -# Global CMake options -if(NOT PROJECT_IS_TOP_LEVEL) - message(FATAL_ERROR "${PROJECT_NAME} must be built standalone!") -endif() - -# Print a message -message(STATUS "Building ${PROJECT_NAME} for ${GDRML_ARCH} on ${CMAKE_SYSTEM_NAME}") - -# Set proper runpath -set(CMAKE_SKIP_BUILD_RPATH OFF) -set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) -set(CMAKE_INSTALL_RPATH $ORIGIN) - -# Compile with PIC -set(CMAKE_POSITION_INDEPENDENT_CODE ON) + VERSION "0.1.0" +) -# Compile with LTO if supported -set(GDRML_USE_LTO OFF) -if(NOT (CMAKE_BUILD_TYPE MATCHES "Debug")) - check_ipo_supported(RESULT GODOTSOURCE_USE_LTO) -endif() -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${GDRML_USE_LTO}) +include(cmake/boilerplate.cmake) # Hide everything by default set(CMAKE_CXX_VISIBILITY_PRESET hidden) diff --git a/cmake/boilerplate.cmake b/cmake/boilerplate.cmake new file mode 100644 index 0000000..343414c --- /dev/null +++ b/cmake/boilerplate.cmake @@ -0,0 +1,38 @@ +if (APPLE) + set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "" FORCE) +endif() + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Include CMake libraries +include(CheckIPOSupported) + +# Set up variables +set(GDRML_ARCH ${CMAKE_SYSTEM_PROCESSOR}) +if (APPLE) + set(GDRML_ARCH "universal") +endif() + +# Global CMake options +if(NOT PROJECT_IS_TOP_LEVEL) + message(FATAL_ERROR "${PROJECT_NAME} must be built standalone!") +endif() + +# Print a message +message(STATUS "Building ${PROJECT_NAME} for ${GDRML_ARCH} on ${CMAKE_SYSTEM_NAME}") + +# Set proper runpath +set(CMAKE_SKIP_BUILD_RPATH OFF) +set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) +set(CMAKE_INSTALL_RPATH $ORIGIN) + +# Compile with PIC +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# Compile with LTO if supported +set(GDRML_USE_LTO OFF) +if(NOT (CMAKE_BUILD_TYPE MATCHES "Debug")) + check_ipo_supported(RESULT GDRML_USE_LTO) +endif() +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${GDRML_USE_LTO}) diff --git a/cmake/gdextension.cmake b/cmake/gdextension.cmake index 2c71f18..fbffca3 100644 --- a/cmake/gdextension.cmake +++ b/cmake/gdextension.cmake @@ -1,3 +1,7 @@ +set(GDRML_ADDON_DIR "${CMAKE_CURRENT_SOURCE_DIR}/project/addons/${PROJECT_NAME}") +set(GDRML_BIN_DIR "${GDRML_ADDON_DIR}/bin") +set(GDRML_LIB_DIR "${CMAKE_SYSTEM_NAME}_${GDRML_ARCH}") + # Macro to set up many things at once for a given GDExtension function(godot_configure_library TARGET) # Define DEBUG macro