[cpp] Refactor CMake build

This commit is contained in:
Mario Zechner 2024-06-30 20:07:29 +02:00
parent a5b3bc709d
commit 75a23e8167
6 changed files with 24 additions and 234 deletions

14
flags.cmake Normal file
View File

@ -0,0 +1,14 @@
option(SPINE_SANITIZE "Build with sanitization" OFF)
if(MSVC)
message("MSCV detected")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wno-unused-parameter -std=c99")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic -Wno-unused-parameter -std=c++11 -fno-exceptions -fno-rtti")
if (${SPINE_SANITIZE})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined")
endif()
endif()

View File

@ -1,11 +1,7 @@
if(MSVC)
message("MSCV detected")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c89")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic -std=c++11 -fno-exceptions -fno-rtti")
endif()
cmake_minimum_required(VERSION 3.10)
project(spine-cpp)
include(${CMAKE_SOURCE_DIR}/../flags.cmake)
include_directories(include)
file(GLOB INCLUDES "spine-cpp/include/**/*.h")

View File

@ -1,32 +0,0 @@
project(spine_cpp_unit_test)
set(SRC src/main.cpp)
add_executable(spine_cpp_unit_test ${SRC})
target_link_libraries(spine_cpp_unit_test spine-cpp)
#########################################################
# copy resources to build output directory
#########################################################
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/spineboy/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/spineboy)
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/raptor/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/raptor)
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/goblins/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/goblins)
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/coin/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/coin)
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/tank/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/tank)
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/stretchyman/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/stretchyman)

View File

@ -1,67 +0,0 @@
# spine-cpp-unit-tests
The spine-cpp-unit-tests project is to test the [spine](http://esotericsoftware.com) skeletal animation system. It does not perform rendering. It is primarily used for regression testing and leak detection. It is designed to be run from a Continuous Integration server and to passively verify changes automatically on check-in.
## Mini CPP Unit Testing
[MiniCppUnit](https://sourceforge.net/p/minicppunit/wiki/Home/) is a minimal unit testing framework similar to JUnit. It is used here to avoid large dependancies.
Tests are sorted into Suites, Fixtures and Cases. There is one suite, it contains many fixtures and each fixture contains test cases. To turn off a fixture, edit "TestOptions.h". To turn off specific test cases, comment out the TEST_CASE() line in the fixture's header.
## Memory Leak Detection
This project includes a very minimal memory leak detector. It is based roughly on the leak detector in the [Popcap Framework](https://sourceforge.net/projects/popcapframework/?source=directory), but has been modified over the years.
## Continuous Integration
The test runner includes the ability to format output messages to signal a CI server. An example interface for [Teamcity](https://www.jetbrains.com/teamcity/) is included. To implement for another server, determine the wireformat for the messages and duplicate/edit the teamcity_messages class. [Teamcity Wire Format](https://confluence.jetbrains.com/display/TCD10/Build+Script+Interaction+with+TeamCity)
### Trigger
Your CI server should trigger on VCS check-in.
### CMake Build Step
The first build step for the CI server should be to run CMake on the 'spine-cpp-unit-tests' folder. Follow the usage directions below.
### Compile Build Step
This build step should not execute if the previous step did not successfully complete.
Depending on the test agent build environment, you should build the output solution or project from the cmake step. Debug is fine.
### Test Runner Build Step
This build step should not execute if the previous step did not successfully complete.
Again, depending on the test agent build environment, you should have produced an executable. Run this executable.
## Usage
Make sure [CMake](https://cmake.org/download/) is installed.
Create a 'build' directory in the 'spine-cpp-unit-tests' folder. Then switch to that folder and execute cmake:
mkdir build
cd build
cmake ..
### Win32 build
msbuild spine_unit_test.sln /t:spine_unit_test /p:Configuration="Debug" /p:Platform="Win32"
## Licensing
This spine Runtime may only be used for personal or internal use, typically to evaluate spine before purchasing. If you would like to incorporate a spine Runtime into your applications, distribute software containing a spine Runtime, or modify a spine Runtime, then you will need a valid [spine license](https://esotericsoftware.com/spine-purchase). Please see the [spine Runtimes Software License](https://github.com/EsotericSoftware/spine-runtimes/blob/master/LICENSE) for detailed information.
The spine Runtimes are developed with the intent to be used with data exported from spine. By purchasing spine, `Section 2` of the [spine Software License](https://esotericsoftware.com/files/license.txt) grants the right to create and distribute derivative works of the spine Runtimes.
original "walk"": 330
second "walk": 0d0
queue interrupt for original walk
queue start for second walk
drain interrupt and start
0d0 is interrupted
0d0 is ended
"run": 0c0
0d0 is interrupted
second walk becomes mixingFrom of run
0c0 is started
queue is drained
first walk: 6f0
second walk: 9c0

View File

@ -1,116 +0,0 @@
#include <spine/Debug.h>
#include <spine/spine.h>
#include <stdio.h>
#ifdef MSVC
#pragma warning(disable : 4710)
#endif
using namespace spine;
void loadBinary(const String &binaryFile, const String &atlasFile, Atlas *&atlas, SkeletonData *&skeletonData,
AnimationStateData *&stateData, Skeleton *&skeleton, AnimationState *&state) {
atlas = new (__FILE__, __LINE__) Atlas(atlasFile, NULL);
assert(atlas != NULL);
SkeletonBinary binary(atlas);
skeletonData = binary.readSkeletonDataFile(binaryFile);
assert(skeletonData);
skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData);
assert(skeleton != NULL);
stateData = new (__FILE__, __LINE__) AnimationStateData(skeletonData);
assert(stateData != NULL);
stateData->setDefaultMix(0.4f);
state = new (__FILE__, __LINE__) AnimationState(stateData);
}
void loadJson(const String &jsonFile, const String &atlasFile, Atlas *&atlas, SkeletonData *&skeletonData,
AnimationStateData *&stateData, Skeleton *&skeleton, AnimationState *&state) {
atlas = new (__FILE__, __LINE__) Atlas(atlasFile, NULL);
assert(atlas != NULL);
SkeletonJson json(atlas);
skeletonData = json.readSkeletonDataFile(jsonFile);
assert(skeletonData);
skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData);
assert(skeleton != NULL);
stateData = new (__FILE__, __LINE__) AnimationStateData(skeletonData);
assert(stateData != NULL);
stateData->setDefaultMix(0.4f);
state = new (__FILE__, __LINE__) AnimationState(stateData);
}
void dispose(Atlas *atlas, SkeletonData *skeletonData, AnimationStateData *stateData, Skeleton *skeleton,
AnimationState *state) {
delete skeleton;
delete state;
delete stateData;
delete skeletonData;
delete atlas;
}
struct TestData {
TestData(const String &jsonSkeleton, const String &binarySkeleton, const String &atlas) : _jsonSkeleton(
jsonSkeleton),
_binarySkeleton(
binarySkeleton),
_atlas(atlas) {}
String _jsonSkeleton;
String _binarySkeleton;
String _atlas;
};
void testLoading() {
Vector<TestData> testData;
testData.add(TestData("testdata/coin/coin-pro.json", "testdata/coin/coin-pro.skel", "testdata/coin/coin.atlas"));
/*testData.add(TestData("testdata/goblins/goblins-pro.json", "testdata/goblins/goblins-pro.skel",
"testdata/goblins/goblins.atlas"));
testData.add(TestData("testdata/raptor/raptor-pro.json", "testdata/raptor/raptor-pro.skel",
"testdata/raptor/raptor.atlas"));
testData.add(TestData("testdata/spineboy/spineboy-pro.json", "testdata/spineboy/spineboy-pro.skel",
"testdata/spineboy/spineboy.atlas"));
testData.add(TestData("testdata/stretchyman/stretchyman-pro.json", "testdata/stretchyman/stretchyman-pro.skel",
"testdata/stretchyman/stretchyman.atlas"));
testData.add(TestData("testdata/tank/tank-pro.json", "testdata/tank/tank-pro.skel", "testdata/tank/tank.atlas"));*/
for (size_t i = 0; i < testData.size(); i++) {
TestData &data = testData[i];
Atlas *atlas = NULL;
SkeletonData *skeletonData = NULL;
AnimationStateData *stateData = NULL;
Skeleton *skeleton = NULL;
AnimationState *state = NULL;
printf("Loading %s\n", data._jsonSkeleton.buffer());
loadJson(data._jsonSkeleton, data._atlas, atlas, skeletonData, stateData, skeleton, state);
dispose(atlas, skeletonData, stateData, skeleton, state);
printf("Loading %s\n", data._binarySkeleton.buffer());
loadBinary(data._binarySkeleton, data._atlas, atlas, skeletonData, stateData, skeleton, state);
dispose(atlas, skeletonData, stateData, skeleton, state);
}
}
namespace spine {
SpineExtension *getDefaultExtension() {
return new DefaultSpineExtension();
}
}// namespace spine
int main(int argc, char **argv) {
SP_UNUSED(argc);
SP_UNUSED(argv);
DebugExtension debug(SpineExtension::getInstance());
SpineExtension::setInstance(&debug);
testLoading();
debug.reportLeaks();
}

View File

@ -1,18 +1,13 @@
cmake_minimum_required(VERSION 3.10)
project(spine-glfw)
if(MSVC)
message("MSCV detected")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
else()
message("${CMAKE_C_FLAGS}")
message("${CMAKE_CXX_FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wno-unused-parameter -std=c99")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic -Wno-unused-parameter -std=c++11 -fno-exceptions -fno-rtti")
endif()
# Default flags
include(${CMAKE_SOURCE_DIR}/../flags.cmake)
# Add spine-cpp and spine-cpp-lite
add_subdirectory(${CMAKE_SOURCE_DIR}/../spine-cpp ${CMAKE_BINARY_DIR}/spine-cpp-build)
include(FetchContent)
# Fetch GLFW
FetchContent_Declare(
glfw