Skip to content

Commit

Permalink
Update test/CmakeLists.txt to not do all the things and instead link …
Browse files Browse the repository at this point in the history
…to main target godot-cpp which pulls in all the dependencies

updated ci to no longer change directory and instead use the -t option to build the godot-cpp-test target
changed the visibility of GENERATED_FILES_LIST to PRIVATE
Changed the warning flags to PUBLIC to hide when building projects that depend on godot-cpp
changed godot-cpp compile feature cxx_std_17 to PUBLIC so as to propagate to consumers.

for now I will leave the old test build code in comments until I see a valid build pass.
  • Loading branch information
enetheru committed Sep 19, 2024
1 parent ff36c25 commit 270ad45
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 94 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ jobs:
- name: Build godot-cpp
run: |
cmake -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 16 2019" .
cmake --build . --verbose
cmake --build . -t godot-cpp --verbose
- name: Build test GDExtension library
run: |
cd test && cmake -DCMAKE_BUILD_TYPE=Release -DGODOT_HEADERS_PATH="../godot-headers" -DCPP_BINDINGS_PATH=".." -G"Visual Studio 16 2019" .
cmake --build . --verbose
cmake -DCMAKE_BUILD_TYPE=Release -G"Visual Studio 16 2019" .
cmake --build . -t godot-cpp-test --verbose
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if( CMAKE_C_COMPILER)
#Silence warning from unused CMAKE_C_COMPILER from toolchain
endif ()

# Main Library
include( ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake )

# I know this doesn't look like a typical CMakeLists.txt, but as we are
Expand All @@ -29,3 +30,6 @@ include( ${PROJECT_SOURCE_DIR}/cmake/godotcpp.cmake )
godotcpp_options()

godotcpp_generate()

# Test Example
add_subdirectory( test )
5 changes: 3 additions & 2 deletions cmake/common_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ set( HOT_RELOAD "$<BOOL:${GODOT_USE_HOT_RELOAD}>")
set( DISABLE_EXCEPTIONS "$<BOOL:${GODOT_DISABLE_EXCEPTIONS}>")

target_compile_features(${PROJECT_NAME}
PRIVATE
PUBLIC
cxx_std_17
)

# These compiler options reflect what is in godot/SConstruct.
target_compile_options( ${PROJECT_NAME}
PRIVATE
PUBLIC
# MSVC only
$<${IS_MSVC}:
/W4
Expand All @@ -38,6 +38,7 @@ PRIVATE
/wd4820 # C4820 (padding added after construct)
$<${WARNING_AS_ERROR}:/WX>
>
PRIVATE

# Clang and GNU common options
$<$<OR:${IS_CLANG},${IS_GNU}>:
Expand Down
1 change: 1 addition & 0 deletions cmake/godotcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function( godotcpp_generate )
PUBLIC
${GODOTCPP_SOURCES}
${GODOTCPP_HEADERS}
PRIVATE
${GENERATED_FILES_LIST}
)

Expand Down
185 changes: 96 additions & 89 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
cmake_minimum_required(VERSION 3.13)
project(godot-cpp-test)

set(GODOT_GDEXTENSION_DIR ../gdextension/ CACHE STRING "Path to GDExtension interface header directory")
set(CPP_BINDINGS_PATH ../ CACHE STRING "Path to C++ bindings")
if( NOT CMAKE_BUILD_TYPE )
set(GODOT_CPP_BUILD_TYPE Release)
endif()

#set(GODOT_GDEXTENSION_DIR ../gdextension/ CACHE STRING "Path to GDExtension interface header directory")
#set(CPP_BINDINGS_PATH ../ CACHE STRING "Path to C++ bindings")

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(TARGET_PATH x11)
Expand All @@ -26,64 +30,59 @@ SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")

# Set the c++ standard to c++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(GODOT_COMPILE_FLAGS )
set(GODOT_LINKER_FLAGS )

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /WX") # /GF /MP
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /DTYPED_METHOD_BIND")

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi
else()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MD /O2") # /Oy /GL /Gy
STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif(CMAKE_BUILD_TYPE MATCHES Debug)

# Disable conversion warning, truncation, unreferenced var, signed mismatch
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267")

add_definitions(-DNOMINMAX)

# Unkomment for warning level 4
#if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
# string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
#endif()

else()

set(GODOT_LINKER_FLAGS "-static-libgcc -static-libstdc++ -Wl,-R,'$$ORIGIN'")

set(GODOT_COMPILE_FLAGS "-fPIC -g -Wwrite-strings")

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0")
else()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -O3")
endif(CMAKE_BUILD_TYPE MATCHES Debug)
endif()

# Disable exception handling. Godot doesn't use exceptions anywhere, and this
# saves around 20% of binary size and very significant build time (GH-80513).
option(GODOT_DISABLE_EXCEPTIONS ON "Force disabling exception handling code")
if (GODOT_DISABLE_EXCEPTIONS)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -D_HAS_EXCEPTIONS=0")
else()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-exceptions")
endif()
else()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /EHsc")
endif()
endif()
#set(GODOT_COMPILE_FLAGS )
#set(GODOT_LINKER_FLAGS )
#
#if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# # using Visual Studio C++
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /WX") # /GF /MP
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /DTYPED_METHOD_BIND")
#
# if(CMAKE_BUILD_TYPE MATCHES Debug)
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi
# else()
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MD /O2") # /Oy /GL /Gy
# STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
# endif(CMAKE_BUILD_TYPE MATCHES Debug)
#
# # Disable conversion warning, truncation, unreferenced var, signed mismatch
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267")
#
# add_definitions(-DNOMINMAX)
#
# # Unkomment for warning level 4
# #if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
# # string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# #endif()
#
#else()
#
# set(GODOT_LINKER_FLAGS "-static-libgcc -static-libstdc++ -Wl,-R,'$$ORIGIN'")
#
# set(GODOT_COMPILE_FLAGS "-fPIC -g -Wwrite-strings")
#
# if(CMAKE_BUILD_TYPE MATCHES Debug)
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0")
# else()
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -O3")
# endif(CMAKE_BUILD_TYPE MATCHES Debug)
#endif()
#
## Disable exception handling. Godot doesn't use exceptions anywhere, and this
## saves around 20% of binary size and very significant build time (GH-80513).
#option(GODOT_DISABLE_EXCEPTIONS ON "Force disabling exception handling code")
#if (GODOT_DISABLE_EXCEPTIONS)
# if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -D_HAS_EXCEPTIONS=0")
# else()
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-exceptions")
# endif()
#else()
# if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /EHsc")
# endif()
#endif()

# Get Sources
file(GLOB_RECURSE SOURCES src/*.c**)
Expand All @@ -92,13 +91,25 @@ file(GLOB_RECURSE HEADERS include/*.h**)
# Define our godot-cpp library
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})

target_include_directories(${PROJECT_NAME} SYSTEM
PRIVATE
${CPP_BINDINGS_PATH}/include
${CPP_BINDINGS_PATH}/gen/include
${GODOT_GDEXTENSION_DIR}
# Set the c++ standard to c++17
set_target_properties(${PROJECT_NAME}
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)

target_link_libraries( ${PROJECT_NAME}
PRIVATE
godot::cpp )

#target_include_directories(${PROJECT_NAME} SYSTEM
# PRIVATE
# ${CPP_BINDINGS_PATH}/include
# ${CPP_BINDINGS_PATH}/gen/include
# ${GODOT_GDEXTENSION_DIR}
#)

# Create the correct name (godot.os.build_type.system_bits)
# Synchronized with godot-cpp's CMakeLists.txt

Expand All @@ -107,11 +118,7 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITS 64)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(GODOT_CPP_BUILD_TYPE Debug)
else()
set(GODOT_CPP_BUILD_TYPE Release)
endif()


string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME)
string(TOLOWER ${GODOT_CPP_BUILD_TYPE} BUILD_TYPE)
Expand All @@ -120,24 +127,24 @@ if(ANDROID)
# Added the android abi after system name
set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI})
endif()

if(CMAKE_VERSION VERSION_GREATER "3.13")
target_link_directories(${PROJECT_NAME}
PRIVATE
${CPP_BINDINGS_PATH}/bin/
)

target_link_libraries(${PROJECT_NAME}
godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>
)
else()
target_link_libraries(${PROJECT_NAME}
${CPP_BINDINGS_PATH}/bin/libgodot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>.a
)
endif()

# Add the compile flags
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS})
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS})
#
#if(CMAKE_VERSION VERSION_GREATER "3.13")
# target_link_directories(${PROJECT_NAME}
# PRIVATE
# ${CPP_BINDINGS_PATH}/bin/
# )
#
# target_link_libraries(${PROJECT_NAME}
# godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>
# )
#else()
# target_link_libraries(${PROJECT_NAME}
# ${CPP_BINDINGS_PATH}/bin/libgodot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>.a
# )
#endif()
#
## Add the compile flags
#set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS})
#set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS})

set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME "gdexample")

0 comments on commit 270ad45

Please sign in to comment.