Skip to content

Fix CMake #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 0 additions & 106 deletions .github/workflows/builds.yml

This file was deleted.

21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,23 @@ bin/*
*.exp

# Build configuarion.
/custom.py
/custom.py
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
*.sln
*.vcxproj
*.vcxproj.filters
gen/
x64/
openvic2.dir/
Debug/
.vs/
112 changes: 112 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
cmake_minimum_required( VERSION 3.22 )

message( STATUS "Using CMake ${CMAKE_VERSION}" )

# Add paths to modules
list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" )

# Turn on link time optimization for everything
set( CMAKE_INTERPROCEDURAL_OPTIMIZATION ON )

# Output compile commands to compile_commands.json (for debugging CMake issues)
set( CMAKE_EXPORT_COMPILE_COMMANDS ON )

# Build universal lib on macOS
# Note that CMAKE_OSX_ARCHITECTURES must be set before project().
if ( APPLE )
set( CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "" )
endif()

# Main project information
project( openvic2
LANGUAGES
CXX
C
VERSION
0.1.0
)

# Create our library
add_library( ${PROJECT_NAME} SHARED )

target_compile_features( ${PROJECT_NAME}
PRIVATE
cxx_std_17
)

# LIB_ARCH is the architecture being built. It is set to the build system's architecture.
# For macOS, we build a universal library (both arm64 and x86_64).
set( LIB_ARCH ${CMAKE_SYSTEM_PROCESSOR} )
if ( APPLE )
set( LIB_ARCH "universal" )
endif()

# LIB_DIR is where the actual library ends up. This is used in both the build directory and the
# install directory and needs to be consistent with the paths in the gdextension file.
# e.g. linux.release.x86_64 = "lib/Linux-x86_64/libopenvic2.so"
set( LIB_DIR "lib/${CMAKE_SYSTEM_NAME}-${LIB_ARCH}" )

message( STATUS "Building ${PROJECT_NAME} for ${LIB_ARCH} on ${CMAKE_SYSTEM_NAME}")

# BUILD_OUTPUT_DIR is where we put the resulting library (in the build directory)
set( BUILD_OUTPUT_DIR "${PROJECT_BINARY_DIR}/${PROJECT_NAME}/" )

set_target_properties( ${PROJECT_NAME}
PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN true
DEBUG_POSTFIX "-d"
RUNTIME_OUTPUT_DIRECTORY "${BUILD_OUTPUT_DIR}/${LIB_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_DIR}/${LIB_DIR}"
)

# Warnings
if( MSVC )
target_compile_options( ${PROJECT_NAME} PRIVATE /W4 )
else()
target_compile_options( ${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic )
endif()

add_subdirectory( extension/src )

# Install library and extension file in ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}
set( INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/" )

install( TARGETS ${PROJECT_NAME}
LIBRARY
DESTINATION ${INSTALL_DIR}/${LIB_DIR}
RUNTIME
DESTINATION ${INSTALL_DIR}/${LIB_DIR}
)

add_subdirectory( game/bin )

# ccache
find_program( CCACHE_FOUND ccache )
if( CCACHE_FOUND )
set_property( GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache )
set_property( GLOBAL PROPERTY RULE_LAUNCH_LINK ccache )
endif( CCACHE_FOUND )

# godot-cpp
# From here: https://github.com/godotengine/godot-cpp
if ( NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/godot-cpp/Makefile" )
message(
FATAL_ERROR
"[${PROJECT_NAME}] The godot-cpp submodule was not downloaded. Please update submodules: git submodule update --init --recursive."
)
endif()

set( GODOT_CPP_SYSTEM_HEADERS ON CACHE BOOL "" FORCE )

add_subdirectory( godot-cpp )

set_target_properties( godot-cpp
PROPERTIES
CXX_VISIBILITY_PRESET hidden # visibility needs to be the same as the main library
)

target_link_libraries( ${PROJECT_NAME}
PRIVATE
godot-cpp
)
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ Main Repo for the OpenVic2 Project

## Required
* [Godot 4 Beta 16](https://downloads.tuxfamily.org/godotengine/4.0/beta16/)
* [scons](https://scons.org/)
* [cmake](https://www.cmake.org/)

## Build/Run Instructions
1. Install [Godot 4 Beta 16](https://downloads.tuxfamily.org/godotengine/4.0/beta16/) and [scons](https://scons.org/) for your system.
2. Run the command `git submodule update --init --recursive` to retrieve all related submodules.
3. Run `scons` in the project root, you should see a libopenvic2 file in `game/bin/openvic2`.
4. Open with Godot 4 Beta 16, click import and navigate to the `game` directory.
5. Import and edit.
6. Once loaded, click the play button at the top right, if you see `Hello GDExtension Singleton!` in the output at the bottom then it is working.
1. Install [Godot 4 Beta 16](https://downloads.tuxfamily.org/godotengine/4.0/beta16/) and [cmake](https://www.cmake.org/) for your system.
3. Create a build folder inside the project folder and CD to it.
4. Run "cmake .." from the build folder, specify cmake options if you need to, and specify the CMAKE_BUILD_TYPE to either Release or Debug (-DCMAKE_BUILD_TYPE=Release) etc
5. Run the build script based on your platform (Makefile, Ninja, Xcode, Visual Studio etc) to build the project
6. Open with Godot 4 Beta 16, click import and navigate to the `game` directory.
7. Import and edit.
8. Once loaded, click the play button at the top right, if you see `Hello GDExtension Singleton!` in the output at the bottom then it is working.

## Project Export
1. Build the extension with `scons` or `scons target=template_debug`. (or `scons target=template_release` for release)
1. Build the extension (^^^)
2. Open `game/project.godot` with Godot 4 Beta 16.
3. Click `Project` at the top left, click `Export`.
4. If you do not have the templates, you must download the templates, there is highlighted white text at the bottom of the Export subwindow that opens up the template manager for you to download.
Expand All @@ -26,7 +27,6 @@ Main Repo for the OpenVic2 Project
* On Linux x86_64 run `game/export/Linux-x86_64/OpenVic2.sh`.

## Extension Debugging
1. If in a clean build, build the extension with `scons`.
2. Build with `scons dev_build=yes`.
1. If in a clean build, build the extension.
3. [Setup your IDE](https://godotengine.org/qa/108346/how-can-i-debug-runtime-errors-of-native-library-in-godot) so your Command/Host/Launching App is your Godot 4 binary and the Working Directory is the `game` directory.
4. Start the debugger.
87 changes: 0 additions & 87 deletions SConstruct

This file was deleted.

Loading