Skip to content

Commit

Permalink
Merge pull request #924 from yvt/patch-vcpkg
Browse files Browse the repository at this point in the history
Adopt vcpkg and streamline the build process
  • Loading branch information
yvt authored Dec 18, 2020
2 parents e782211 + 2a72668 commit 4d078e7
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 2,759 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: CI
on:
pull_request:
push:

jobs:
build-windows:
name: Build (Windows)
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v1
with:
submodules: true
path: openspades

- name: Cache vcpkg and dependencies
uses: actions/cache@v2
with:
path: |
vcpkg/installed
!.git
key: ${{ runner.os }}-${{ hashFiles('vcpkg_x86-windows.txt', '.gitmodules') }}

- name: Bootstrap vcpkg
run: vcpkg/bootstrap-vcpkg.bat

- name: Build dependencies
run: vcpkg/vcpkg install @vcpkg_x86-windows.txt

- name: Build application
uses: ashutoshvarma/action-cmake-build@master
with:
build-dir: ${{ runner.workspace }}/openspades.mk
build-type: RelWithDebInfo
configure-options: -A Win32 -D CMAKE_BUILD_TYPE=RelWithDebInfo -D CMAKE_TOOLCHAIN_FILE=${{ runner.workspace }}/openspades/vcpkg/scripts/buildsystems/vcpkg.cmake -D VCPKG_TARGET_TRIPLET=x86-windows-static
parallel: 8

build-macos:
name: Build (macOS)
runs-on: macos-10.15
steps:
- name: Checkout
uses: actions/checkout@v1
with:
submodules: true
path: openspades

- name: Cache vcpkg and dependencies
uses: actions/cache@v2
with:
path: |
vcpkg/installed
!.git
key: ${{ runner.os }}-${{ hashFiles('vcpkg_x86_64-darwin.txt', '.gitmodules') }}

- name: Bootstrap vcpkg
run: vcpkg/bootstrap-vcpkg.sh

- name: Build dependencies
run: vcpkg/vcpkg install @vcpkg_x86_64-darwin.txt

- name: Build application
uses: ashutoshvarma/action-cmake-build@master
with:
build-dir: ${{ runner.workspace }}/openspades.mk
build-type: RelWithDebInfo
configure-options: -D CMAKE_BUILD_TYPE=RelWithDebInfo -D CMAKE_TOOLCHAIN_FILE=${{ runner.workspace }}/openspades/vcpkg/scripts/buildsystems/vcpkg.cmake -D VCPKG_TARGET_TRIPLET=x64-osx -D CMAKE_OSX_ARCHITECTURES=x86_64
parallel: 8
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ CMakeCache.txt
*CMakeFiles/
*.cmake

# cmake input dir (optional)
Sources/Externals/include/
Sources/Externals/lib/

# mac related
*.DS_Store

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "flatpak/shared-modules"]
path = flatpak/shared-modules
url = https://github.com/flathub/shared-modules.git
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git
186 changes: 128 additions & 58 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,91 @@ set(OPENSPADES_FULL_VERSION "${OpenSpades_VERSION_MAJOR}.${OpenSpades_VERSION_MI

set(OS_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_PREFIX_PATH Sources/Externals)
if(VCPKG_TARGET_TRIPLET)
set(USE_VCPKG ON)
else()
set(USE_VCPKG OFF)
endif()

# Prefer GLVND OpenGL
if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif()

include(cmake/FindSDL2.cmake)
if(NOT SDL2_FOUND)
message(FATAL_ERROR "SDL 2.0 not found, set ENV{SDL2DIR} to point to SDL 2.0, and optionally set the cmake var SDL2_LIBRARY_TEMP to the lib dir")
endif()
if(USE_VCPKG)
find_package(Ogg CONFIG REQUIRED)
find_package(Opus CONFIG REQUIRED)
find_package(sdl2-image CONFIG REQUIRED)
find_package(SDL2 CONFIG REQUIRED)
find_package(freetype CONFIG REQUIRED)

if(NOT APPLE)
find_package(GLEW REQUIRED)
set(GLEW_LIBRARY GLEW::GLEW)

find_package(CURL REQUIRED)
set(CURL_LIBRARY CURL::libcurl)
endif()

set(SDL2_LIBRARY SDL2::SDL2main SDL2::SDL2-static)
set(SDL2_IMAGE_LIBRARY SDL2::SDL2_image)
set(FREETYPE_LIBRARIES freetype)

if(APPLE)
# Use system libraries
include(FindOpenGL)
include(FindCURL)
endif()

FIND_LIBRARY(OpusFile_LIBRARY
NAMES opusfile
PATH_SUFFIXES lib64 lib
PATHS ${CMAKE_PREFIX_PATH}
)
else()
include(cmake/FindSDL2.cmake)
if(NOT SDL2_FOUND)
message(FATAL_ERROR "SDL 2.0 not found, set ENV{SDL2DIR} to point to SDL 2.0, and optionally set the cmake var SDL2_LIBRARY_TEMP to the lib dir")
endif()

include(cmake/FindSDL2_image.cmake)
if(NOT SDL2_IMAGE_FOUND)
message(FATAL_ERROR "SDL_image 2.0 not found, set ENV{SDL2DIR} to point to SDL 2.0, and optionally set the cmake var SDL2_LIBRARY_TEMP to the lib dir")
endif()
include(cmake/FindSDL2_image.cmake)
if(NOT SDL2_IMAGE_FOUND)
message(FATAL_ERROR "SDL_image 2.0 not found, set ENV{SDL2DIR} to point to SDL 2.0, and optionally set the cmake var SDL2_LIBRARY_TEMP to the lib dir")
endif()

include(FindOpenGL)
if(NOT OPENGL_FOUND AND NOT OPENGL_XMESA_FOUND AND NOT OPENGL_GLU_FOUND)
message(FATAL_ERROR "OpenGL not found, please install it")
endif()
if(NOT APPLE)
include(cmake/FindGLEW2.cmake)
if(NOT GLEW_FOUND)
message(FATAL_ERROR "GLEW not found, please install it and make sure CMake can find it (add it to the PATH)")
include(FindOpenGL)
if(NOT OPENGL_FOUND AND NOT OPENGL_XMESA_FOUND AND NOT OPENGL_GLU_FOUND)
message(FATAL_ERROR "OpenGL not found, please install it")
endif()
if(NOT APPLE)
include(cmake/FindGLEW2.cmake)
if(NOT GLEW_FOUND)
message(FATAL_ERROR "GLEW not found, please install it and make sure CMake can find it (add it to the PATH)")
endif()
endif()
endif()

include(FindZLIB)
if(NOT ZLIB_FOUND)
message(FATAL_ERROR "ZLIB not found, manually set ZLIB_ROOT in CMake")
endif()
include(FindZLIB)
if(NOT ZLIB_FOUND)
message(FATAL_ERROR "ZLIB not found, manually set ZLIB_ROOT in CMake")
endif()

include(FindCURL)
if(NOT CURL_FOUND)
message(FATAL_ERROR "cURL not found, please install it (and make sure it's in your path)")
endif()
include(FindCURL)
if(NOT CURL_FOUND)
message(FATAL_ERROR "cURL not found, please install it (and make sure it's in your path)")
endif()

include(FindFreetype)
if(NOT FREETYPE_FOUND)
message(FATAL_ERROR "FreeType not found, please install it (and make sure it's in your path)")
endif()
include(FindFreetype)
if(NOT FREETYPE_FOUND)
message(FATAL_ERROR "FreeType not found, please install it (and make sure it's in your path)")
endif()

include(cmake/FindOpus.cmake)
if(NOT OpusFile_FOUND)
message(FATAL_ERROR "libopus/libopusfile not found, please install it (and make sure it's in your path)")
include(cmake/FindOpus.cmake)
if(NOT OpusFile_FOUND)
message(FATAL_ERROR "libopus/libopusfile not found, please install it (and make sure it's in your path)")
endif()
endif()


if(CMAKE_COMPILER_IS_GNUCXX)
# GCC C++11 support
# from http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake
Expand Down Expand Up @@ -193,24 +230,27 @@ endif()
configure_file("${PROJECT_SOURCE_DIR}/OpenSpades.h.in" "${PROJECT_BINARY_DIR}/OpenSpades.h")
configure_file("${PROJECT_SOURCE_DIR}/OpenSpades.rc.in" "${PROJECT_BINARY_DIR}/OpenSpades.rc")
include_directories(BEFORE "${PROJECT_BINARY_DIR}")
include_directories("${SDL2_INCLUDE_DIR}")
include_directories("${SDL2_IMAGE_INCLUDE_DIR}")
if(OPENGL_INCLUDE_DIR)
include_directories("${OPENGL_INCLUDE_DIR}")
endif()
if(NOT APPLE)
include_directories("${GLEW_INCLUDE_DIR}")
if(USE_VCPKG)
include_directories("${PROJECT_SOURCE_DIR}/vcpkg/installed/${VCPKG_TARGET_TRIPLET}/include")
else()
include_directories("${SDL2_INCLUDE_DIR}")
include_directories("${SDL2_IMAGE_INCLUDE_DIR}")
if(OPENGL_INCLUDE_DIR)
include_directories("${OPENGL_INCLUDE_DIR}")
endif()
if(NOT APPLE)
include_directories("${GLEW_INCLUDE_DIR}")
endif()
include_directories("${ZLIB_INCLUDE_DIR}")
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${FREETYPE_INCLUDE_DIRS})
include_directories(${OpusFile_INCLUDE_DIR})
endif()
include_directories("${ZLIB_INCLUDE_DIR}")
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${FREETYPE_INCLUDE_DIRS})
include_directories(${OpusFile_INCLUDE_DIR})

add_subdirectory(Resources)
add_subdirectory(Sources)


if(UNIX)
if(UNIX AND NOT APPLE)
# various texts
INSTALL(FILES AUTHORS LICENSE README.md DESTINATION ${OPENSPADES_INSTALL_DOC}/)

Expand All @@ -228,15 +268,7 @@ if(UNIX)

if(OPENSPADES_RESOURCES)
# install asset paks (including non-GPL one)
install(FILES
${CMAKE_BINARY_DIR}/Resources/pak000-Nonfree.pak
${CMAKE_BINARY_DIR}/Resources/pak002-Base.pak
${CMAKE_BINARY_DIR}/Resources/pak005-Models.pak
${CMAKE_BINARY_DIR}/Resources/pak010-BaseSkin.pak
${CMAKE_BINARY_DIR}/Resources/pak050-Locales.pak
${CMAKE_BINARY_DIR}/Resources/pak999-References.pak
${CMAKE_BINARY_DIR}/Resources/font-unifont.pak
DESTINATION ${OPENSPADES_INSTALL_RESOURCES})
install(FILES ${PAK_FILES} DESTINATION ${OPENSPADES_INSTALL_RESOURCES})
endif(OPENSPADES_RESOURCES)

# Package info (used for automatic update check)
Expand All @@ -259,9 +291,47 @@ if(UNIX)
# Currently there is no files in lib/openspades. But if you reading this message in future and want to
# place somewhere libs, binaries or other non-media stuff, place them in lib/openspades. Thank you.

endif(UNIX)


endif(UNIX AND NOT APPLE)

if(APPLE)
# Create a macOS application bundle
set_target_properties(OpenSpades PROPERTIES
MACOSX_BUNDLE ON
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/XSpades/XSpades-Info.plist
MACOSX_BUNDLE_BUNDLE_VERSION ${OPENSPADES_FULL_VERSION}
MACOSX_BUNDLE_LONG_VERSION_STRING ${OPENSPADES_FULL_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${OPENSPADES_FULL_VERSION}
MACOSX_BUNDLE_GUI_IDENTIFIER jp.yvt.openspades
MACOSX_BUNDLE_BUNDLE_NAME OpenSpades)

set(BUNDLE_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Icons/OpenSpades.icns)
list(APPEND BUNDLE_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
if(OPENSPADES_RESOURCES)
list(APPEND BUNDLE_RESOURCES ${PAK_FILES})
set_source_files_properties(${PAK_FILES}
PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
add_dependencies(OpenSpades OpenSpades_Resources_DevPaks OpenSpades_Resources)
endif(OPENSPADES_RESOURCES)
list(APPEND BUNDLE_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Resources/PackageInfo.json)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/Resources/PackageInfo.json
PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
list(APPEND BUNDLE_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/libysrspades.dylib)
set_target_properties(OpenSpades PROPERTIES RESOURCE "${BUNDLE_RESOURCES}")

target_sources(OpenSpades PRIVATE "${BUNDLE_RESOURCES}")

# Download `libysrspades.dylib` automatically
add_dependencies(OpenSpades OpenSpades_YSRSpades_Prebuilt)
add_custom_target(OpenSpades_YSRSpades_Prebuilt ALL COMMENT "Downloading libysrspades.dylib"
DEPENDS ${PROJECT_BINARY_DIR}/libysrspades.dylib)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/libysrspades.dylib
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND
wget -c
https://openspadesmedia.yvt.jp/development-packages/YSRSpades/libysrspades.dylib
)
endif(APPLE)

#see http://www.cmake.org/cmake/help/v2.8.11/cpack.html
set(CPACK_PACKAGE_NAME "OpenSpades")
Expand Down
17 changes: 0 additions & 17 deletions OpenSpades.h

This file was deleted.

Loading

0 comments on commit 4d078e7

Please sign in to comment.