Skip to content

Commit

Permalink
Update build spine to shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 3, 2024
1 parent 52ddc5f commit c204b00
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ jobs:
cd Assets
python BuildAssetBundles.py
cd ..
cmake -S . -B ./PrjVisualStudio -G "Visual Studio 17 2022" -A x64 -DBUILD_SHARED_LIBS=ON -DBUILD_IMGUI=OFF -DBUILD_FREETYPE=OFF -DBUILD_SKYLICHT_AUDIO=OFF -DBUILD_SKYLICHT_COMPONENTS=OFF -DBUILD_SKYLICHT_COLLISION=OFF -DBUILD_SKYLICHT_UI=OFF -DBUILD_SKYLICHT_CRYPTO=OFF -DBUILD_SKYLICHT_NETWORK=OFF -DBUILD_SKYLICHT_PHYSIC=OFF -DBUILD_EXAMPLES=OFF -DBUILD_ENGINE_TOOL=OFF
cmake -S . -B ./PrjVisualStudio -G "Visual Studio 17 2022" -A x64 -DBUILD_SHARED_LIBS=ON -DBUILD_IMGUI=OFF -DBUILD_FREETYPE=OFF -DBUILD_SKYLICHT_AUDIO=OFF -DBUILD_SKYLICHT_COMPONENTS=OFF -DBUILD_SKYLICHT_COLLISION=OFF -DBUILD_SKYLICHT_UI=OFF -DBUILD_SKYLICHT_CRYPTO=OFF -DBUILD_SKYLICHT_NETWORK=OFF -DBUILD_SKYLICHT_PHYSIC=OFF -DBUILD_SPINE_RUNTIMES=OFF -DBUILD_EXAMPLES=OFF -DBUILD_ENGINE_TOOL=OFF
cmake --build ./PrjVisualStudio --config "Release"
- name: Unit Test
run: |
Expand Down
3 changes: 3 additions & 0 deletions BuildCommand/InstallSharedLibVCPrj2022.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd ..
cmake -S . -B ./PrjVisualStudio -G "Visual Studio 17 2022" -A x64 -DINSTALL_LIBS=ON -DBUILD_SHARED_LIBS=ON
cmake --build ./PrjVisualStudio --target install --config Debug
6 changes: 1 addition & 5 deletions Projects/Irrlicht/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,9 @@ install (DIRECTORY ${SKYLICHT_ENGINE_PROJECT_DIR}/Irrlicht/Include
FILES_MATCHING PATTERN "*.h*")

install (DIRECTORY ${SKYLICHT_ENGINE_PROJECT_DIR}/Irrlicht/Source/Angle
DESTINATION ${SKYLICHT_INCLUDE_INSTALL_DIR}/Irrlicht/Source
DESTINATION ${SKYLICHT_INCLUDE_INSTALL_DIR}/Irrlicht
FILES_MATCHING PATTERN "*.h*")

if(BUILD_MACOS OR BUILD_IOS)
install (DIRECTORY ${SKYLICHT_ENGINE_PROJECT_DIR}/Angle DESTINATION ${SKYLICHT_INCLUDE_INSTALL_DIR})
endif()

install(EXPORT IrrlichtTargets
FILE IrrlichtTargets.cmake
NAMESPACE Skylicht::
Expand Down
39 changes: 32 additions & 7 deletions Projects/SpineCpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,49 @@ cmake_minimum_required(VERSION 3.10)
include(flags.cmake)

include_directories(
${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp/spine-cpp/include
${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp
${SKYLICHT_ENGINE_PROJECT_DIR}/Irrlicht/Include
${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/System
${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/Engine
)

file(GLOB INCLUDES "spine-cpp/include/**/*.h")
file(GLOB SOURCES "spine-cpp/src/**/*.cpp")
file(GLOB SL_INCLUDES "*.h")
file(GLOB SL_SOURCES "*.cpp")
file(GLOB SP_INCLUDES "spine-cpp/include/**/*.h")
file(GLOB SP_SOURCES "spine-cpp/src/**/*.cpp")
file(GLOB SL_INCLUDES "spine-runtimes/*.h")
file(GLOB SL_SOURCES "spine-runtimes/*.cpp")

add_library(SpineRuntimes ${ENGINE_SHARED_OR_STATIC_LIB} ${SP_SOURCES} ${SP_INCLUDES} ${SL_SOURCES} ${SL_INCLUDES})

if (BUILD_SHARED_LIBS)
if (BUILD_LINUX OR BUILD_MACOS)
add_compile_options(-fpic)
endif()

set_target_properties(SpineRuntimes PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true)
add_definitions(-DSPINE_EXPORTS)
endif()

add_library(SpineRuntimes STATIC ${SOURCES} ${INCLUDES} ${SL_SOURCES} ${SL_INCLUDES})
target_link_libraries(SpineRuntimes Engine)

if (INSTALL_LIBS)
install(TARGETS SpineRuntimes
EXPORT SpineRuntimesTargets
RUNTIME DESTINATION ${SKYLICHT_LIBRARY_INSTALL_DIR}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

target_include_directories(SpineRuntimes PUBLIC spine-cpp/include)
install (DIRECTORY ${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp/spine-runtimes
DESTINATION ${SKYLICHT_INCLUDE_INSTALL_DIR}/SpineCpp
FILES_MATCHING PATTERN "*.h*")

target_link_libraries(SpineRuntimes Engine)
install (DIRECTORY ${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp/spine-cpp/include/spine
DESTINATION ${SKYLICHT_INCLUDE_INSTALL_DIR}/SpineCpp
FILES_MATCHING PATTERN "*.h*")

install(EXPORT SpineRuntimesTargets
FILE SpineRuntimesTargets.cmake
NAMESPACE Skylicht::
DESTINATION ${SKYLICHT_LIBRARY_INSTALL_DIR}/cmake
)
endif()
36 changes: 25 additions & 11 deletions Projects/SpineCpp/spine-cpp/include/spine/dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,36 @@
#ifndef SPINE_SHAREDLIB_H
#define SPINE_SHAREDLIB_H

#ifdef _WIN32
#define DLLIMPORT __declspec(dllimport)
#define DLLEXPORT __declspec(dllexport)
#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)

#ifdef _SKYLICHT_STATIC_LIB_
#define SP_API
#else
#ifndef DLLIMPORT
#define DLLIMPORT
#endif
#ifndef DLLEXPORT
#define DLLEXPORT

#ifdef _MSC_VER
// Visual studio
#define SP_API
#else
// Cygwin & MinGW
#ifdef SPINE_EXPORTS
#define SP_API __declspec(dllexport)
#else
#define SP_API __declspec(dllimport)
#endif
#endif

#endif

#ifdef SPINEPLUGIN_API
#define SP_API SPINEPLUGIN_API
#else
#define SP_API

// GCC or OTHER
// Force symbol export in shared libraries built with gcc.
#if (__GNUC__ >= 4) && !defined(_SKYLICHT_STATIC_LIB_) && defined(SPINE_EXPORTS)
#define SP_API __attribute__ ((visibility("default")))
#else
#define SP_API
#endif

#endif

#endif /* SPINE_SHAREDLIB_H */
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Skylicht

namespace spine
{
class CSkeletonDrawable
class SP_API CSkeletonDrawable
{
protected:
spine::Skeleton* m_skeleton;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This file is part of the "Skylicht Engine".

namespace spine
{
class CSpineResource
class SP_API CSpineResource
{
protected:
CTextureLoader* m_textureLoader;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace spine
class AtlasPage;
class String;

class CTextureLoader : public spine::TextureLoader
class SP_API CTextureLoader : public spine::TextureLoader
{
public:
CTextureLoader();
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Samples/Spine2D/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif()
if (BUILD_SPINE_RUNTIMES)
include_directories(
${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp/spine-cpp/include
${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp
${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp/spine-runtimes
)
endif()

Expand Down
2 changes: 1 addition & 1 deletion Scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ endif()
if (BUILD_SPINE_RUNTIMES)
include_directories(
${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp/spine-cpp/include
${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp
${SKYLICHT_ENGINE_PROJECT_DIR}/SpineCpp/spine-runtimes
)
endif()

Expand Down

0 comments on commit c204b00

Please sign in to comment.