Skip to content

Commit 09a22bc

Browse files
author
Vano
committed
CMake test project rewrite, test script exports before running test
1 parent 450994a commit 09a22bc

File tree

3 files changed

+86
-128
lines changed

3 files changed

+86
-128
lines changed

test/CMakeLists.txt

Lines changed: 44 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,59 @@
1-
project(godot-cpp-test)
2-
cmake_minimum_required(VERSION 3.6)
1+
cmake_minimum_required(VERSION 3.24)
2+
project(gdexample)
33

4-
set(GODOT_GDEXTENSION_DIR ../gdextension/ CACHE STRING "Path to GDExtension interface header directory")
5-
set(CPP_BINDINGS_PATH ../ CACHE STRING "Path to C++ bindings")
6-
7-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
8-
set(TARGET_PATH x11)
9-
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
10-
set(TARGET_PATH win64)
11-
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
12-
set(TARGET_PATH macos)
13-
else()
14-
message(FATAL_ERROR "Not implemented support for ${CMAKE_SYSTEM_NAME}")
15-
endif()
16-
17-
# Change the output directory to the bin directory
18-
set(BUILD_PATH ${CMAKE_SOURCE_DIR}/bin/${TARGET_PATH})
19-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_PATH}")
20-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BUILD_PATH}")
21-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_PATH}")
22-
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
23-
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
24-
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
25-
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
26-
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
27-
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
28-
29-
# Set the c++ standard to c++17
30-
set(CMAKE_CXX_STANDARD 17)
31-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
32-
set(CMAKE_CXX_EXTENSIONS OFF)
33-
34-
set(GODOT_COMPILE_FLAGS )
35-
set(GODOT_LINKER_FLAGS )
36-
37-
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
38-
# using Visual Studio C++
39-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /WX") # /GF /MP
40-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /DTYPED_METHOD_BIND")
41-
42-
if(CMAKE_BUILD_TYPE MATCHES Debug)
43-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi
44-
else()
45-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MD /O2") # /Oy /GL /Gy
46-
STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
47-
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
48-
endif(CMAKE_BUILD_TYPE MATCHES Debug)
49-
50-
# Disable conversion warning, truncation, unreferenced var, signed mismatch
51-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267")
52-
53-
add_definitions(-DNOMINMAX)
54-
55-
# Unkomment for warning level 4
56-
#if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
57-
# string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
58-
#endif()
59-
60-
else()
61-
62-
set(GODOT_LINKER_FLAGS "-static-libgcc -static-libstdc++ -Wl,-R,'$$ORIGIN'")
63-
64-
set(GODOT_COMPILE_FLAGS "-fPIC -g -Wwrite-strings")
65-
66-
if(CMAKE_BUILD_TYPE MATCHES Debug)
67-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0")
68-
else()
69-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -O3")
70-
endif(CMAKE_BUILD_TYPE MATCHES Debug)
71-
endif()
72-
73-
# Disable exception handling. Godot doesn't use exceptions anywhere, and this
74-
# saves around 20% of binary size and very significant build time (GH-80513).
75-
option(GODOT_DISABLE_EXCEPTIONS ON "Force disabling exception handling code")
76-
if (GODOT_DISABLE_EXCEPTIONS)
77-
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
78-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -D_HAS_EXCEPTIONS=0")
79-
else()
80-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-exceptions")
81-
endif()
82-
else()
83-
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
84-
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /EHsc")
85-
endif()
86-
endif()
4+
add_subdirectory(
5+
../ # path to godot-cpp
6+
${CMAKE_CURRENT_BINARY_DIR}/godot-cpp # needed because godot-cpp is top directory
7+
)
878

889
# Get Sources
8910
file(GLOB_RECURSE SOURCES src/*.c**)
9011
file(GLOB_RECURSE HEADERS include/*.h**)
9112

9213
# Define our godot-cpp library
93-
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
94-
95-
target_include_directories(${PROJECT_NAME} SYSTEM
96-
PRIVATE
97-
${CPP_BINDINGS_PATH}/include
98-
${CPP_BINDINGS_PATH}/gen/include
99-
${GODOT_GDEXTENSION_DIR}
100-
)
101-
102-
# Create the correct name (godot.os.build_type.system_bits)
103-
# Synchronized with godot-cpp's CMakeLists.txt
104-
105-
set(BITS 32)
106-
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
107-
set(BITS 64)
108-
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
109-
110-
if(CMAKE_BUILD_TYPE MATCHES Debug)
111-
set(GODOT_CPP_BUILD_TYPE Debug)
14+
if(${PLATFORM} STREQUAL "WEB")
15+
# wasm libraries loaded with dlopen() are created like this in cmake
16+
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
17+
set_target_properties(${PROJECT_NAME}
18+
PROPERTIES
19+
PREFIX "lib"
20+
SUFFIX ".wasm"
21+
)
22+
elseif(${PLATFORM} STREQUAL "MACOS" OR ${PLATFORM} STREQUAL "IOS")
23+
# TODO: create framework with cmake FRAMEWORK property
24+
# or with template file
25+
message(WARNING "Mac/IOS framework configuration is not tested and may not work.")
26+
27+
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
28+
set_target_properties(${PROJECT_NAME} PROPERTIES
29+
FRAMEWORK TRUE
30+
MACOSX_FRAMEWORK_IDENTIFIER com.godotengine.${PROJECT_NAME}
31+
MACOSX_FRAMEWORK_INFO_PLIST Info.plist
32+
)
11233
else()
113-
set(GODOT_CPP_BUILD_TYPE Release)
34+
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
11435
endif()
11536

116-
string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME)
117-
string(TOLOWER ${GODOT_CPP_BUILD_TYPE} BUILD_TYPE)
37+
target_link_libraries(${PROJECT_NAME} PUBLIC godot-cpp)
11838

119-
if(ANDROID)
120-
# Added the android abi after system name
121-
set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI})
122-
endif()
39+
get_directory_property(GODOT_CC_FLAGS DIRECTORY ../ DEFINITION GODOT_CC_FLAGS)
40+
get_directory_property(GODOT_CXX_FLAGS DIRECTORY ../ DEFINITION GODOT_CXX_FLAGS)
41+
target_compile_options(${PROJECT_NAME} PRIVATE
42+
${GODOT_CC_FLAGS}
43+
${GODOT_CXX_FLAGS}
44+
)
12345

124-
if(CMAKE_VERSION VERSION_GREATER "3.13")
125-
target_link_directories(${PROJECT_NAME}
126-
PRIVATE
127-
${CPP_BINDINGS_PATH}/bin/
128-
)
46+
get_directory_property(GODOT_LINK_FLAGS DIRECTORY ../ DEFINITION GODOT_LINK_FLAGS)
47+
target_link_options(${PROJECT_NAME} PRIVATE ${GODOT_LINK_FLAGS})
12948

130-
target_link_libraries(${PROJECT_NAME}
131-
godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>
132-
)
133-
else()
134-
target_link_libraries(${PROJECT_NAME}
135-
${CPP_BINDINGS_PATH}/bin/libgodot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$<NOT:$<PLATFORM_ID:Android>>:.${BITS}>.a
136-
)
137-
endif()
13849

139-
# Add the compile flags
140-
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS})
141-
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS})
50+
get_directory_property(LIBRARY_SUFFIX DIRECTORY ../ DEFINITION LIBRARY_SUFFIX)
51+
set_target_properties(${PROJECT_NAME}
52+
PROPERTIES
53+
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
54+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
55+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
56+
57+
OUTPUT_NAME "${PROJECT_NAME}${LIBRARY_SUFFIX}"
58+
)
14259

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

test/project/export_presets.cfg

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[preset.0]
2+
3+
name="<null>"
4+
platform="Linux/X11"
5+
runnable=false
6+
dedicated_server=false
7+
custom_features=""
8+
export_filter="all_resources"
9+
include_filter=""
10+
exclude_filter=""
11+
export_path=""
12+
encryption_include_filters=""
13+
encryption_exclude_filters=""
14+
encrypt_pck=false
15+
encrypt_directory=false
16+
17+
[preset.0.options]
18+
19+
custom_template/debug=""
20+
custom_template/release=""
21+
debug/export_console_wrapper=1
22+
binary_format/embed_pck=false
23+
texture_format/bptc=true
24+
texture_format/s3tc=true
25+
texture_format/etc=false
26+
texture_format/etc2=false
27+
binary_format/architecture="x86_64"
28+
ssh_remote_deploy/enabled=false
29+
ssh_remote_deploy/host="user@host_ip"
30+
ssh_remote_deploy/port="22"
31+
ssh_remote_deploy/extra_args_ssh=""
32+
ssh_remote_deploy/extra_args_scp=""
33+
ssh_remote_deploy/run_script="#!/usr/bin/env bash
34+
export DISPLAY=:0
35+
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
36+
\"{temp_dir}/{exe_name}\" {cmd_args}"
37+
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
38+
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
39+
rm -rf \"{temp_dir}\""

test/run-tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ GODOT=${GODOT:-godot}
55
END_STRING="==== TESTS FINISHED ===="
66
FAILURE_STRING="******** FAILED ********"
77

8+
# Import to get GDExtension library working
9+
$GODOT --headless --path project --export-pack '<null>' /dev/null
10+
811
OUTPUT=$($GODOT --path project --debug --headless --quit)
912
ERRCODE=$?
1013

0 commit comments

Comments
 (0)