Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/build-mingw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build using msys2+mingw(32|64)
on:
pull_request:
push:
release:
types: published
jobs:
build-mingw:
strategy:
matrix:
arch: ['i686', 'x86_64']
platform: ['gl3-glfw', 'gl3-sdl2', 'd3d9']
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: "Calculate variables"
id: "variables"
shell: python
run: |
cmake_args = {
"gl3-glfw": "-DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=GLFW",
"gl3-sdl2": "-DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=SDL2",
"d3d9": "-DLIBRW_PLATFORM=D3D9"
}["${{ matrix.platform }}"]
print("::set-output name=cmake_args::{}".format(cmake_args))
msystem = {
"i686": "MINGW32",
"x86_64": "MINGW64",
}["${{ matrix.arch }}"]
print("::set-output name=msystem::{}".format(msystem))
- uses: msys2/setup-msys2@v2
with:
msystem: ${{ steps.variables.outputs.msystem }}
install: >-
mingw-w64-${{ matrix.arch }}-gcc
mingw-w64-${{ matrix.arch }}-cmake
mingw-w64-${{ matrix.arch }}-make
mingw-w64-${{ matrix.arch }}-glfw
mingw-w64-${{ matrix.arch }}-SDL2
- name: "Build files (CMake)"
shell: "msys2 {0}"
run: |
cmake -S. -Bbuild ${{ steps.variables.outputs.cmake_args }} -DLIBRW_INSTALL=True -G "MinGW Makefiles"
cmake --build build --parallel
- name: "Create binary package (CPack)"
shell: "msys2 {0}"
working-directory: ./build
run: |
cpack
- name: "Archive binary package (github artifacts)"
uses: actions/upload-artifact@v2
with:
name: "mingw-${{ matrix.platform }}-${{ matrix.arch }}"
path: build/*.tar.xz
if-no-files-found: error
57 changes: 37 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
set(librw_SUBPROJECT OFF)
set(librw_MAINPROJECT ON)
if(DEFINED PROJECT_NAME)
set(librw_SUBPROJECT ON)
set(librw_MAINPROJECT OFF)
endif()

Expand All @@ -12,22 +14,22 @@ set(librw_AUTHOR aap)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

set(LIBRW_STATIC_RUNTIME_DEFAULT OFF)

if(WIN32)
set(LIBRW_PLATFORMS "NULL" "GL3" "D3D9")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/win")
include(WinFunctions)
elseif(NINTENDO_SWITCH)
set(LIBRW_PLATFORMS "NULL" "GL3")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/nx")
include(NXFunctions)
elseif(PS2)
set(LIBRW_PLATFORMS "PS2")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
set(LIBRW_PLATFORMS "NULL" "PS2")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/ps2")
include(PS2Functions)
else()
set(LIBRW_PLATFORMS "NULL" "GL3")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
endif()
list(GET LIBRW_PLATFORMS 0 LIBRW_PLATFORM_DEFAULT)
set(LIBRW_PLATFORM "${LIBRW_PLATFORM_DEFAULT}" CACHE STRING "Platform")
Expand Down Expand Up @@ -61,7 +63,12 @@ include(CMakeDependentOption)

option(LIBRW_TOOLS "Build librw tools" ${librw_MAINPROJECT})
option(LIBRW_INSTALL "Install librw files" ${librw_MAINPROJECT})
cmake_dependent_option(LIBRW_EXAMPLES "Build librw examples" ON "LIBRW_TOOLS;NOT LIBRW_PLATFORM_NULL" OFF)
cmake_dependent_option(LIBRW_EXAMPLES "Build librw examples" ON "NOT LIBRW_PLATFORM_PS2;NOT LIBRW_PLATFORM_NULL" OFF)
option(LIBRW_STATIC_RUNTIME "Try very hard to link to static libraries" ${LIBRW_STATIC_RUNTIME_DEFAULT})

if(LIBRW_STATIC_RUNTIME)
include(UseStaticRuntime)
endif()

if(LIBRW_INSTALL)
include(GNUInstallDirs)
Expand All @@ -70,7 +77,7 @@ endif()

add_subdirectory(src)

if(LIBRW_TOOLS AND NOT LIBRW_PLATFORM_PS2 AND NOT LIBRW_PLATFORM_NULL)
if(NOT LIBRW_PLATFORM_PS2 AND NOT LIBRW_PLATFORM_NULL)
add_subdirectory(skeleton)
endif()

Expand All @@ -90,12 +97,12 @@ if(LIBRW_INSTALL)
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

if(LIBRW_GL3_GFXLIB STREQUAL "SDL2")
install(
FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/FindSDL2.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
)
endif()
install(
FILES
"${CMAKE_CURRENT_LIST_DIR}/cmake/Findglfw3.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/FindSDL2.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
)

string(REPLACE "." ";" cmake_c_compiler_version_list "${CMAKE_C_COMPILER_VERSION}")
list(GET cmake_c_compiler_version_list 0 cmake_c_compiler_version_major)
Expand All @@ -114,7 +121,7 @@ if(LIBRW_INSTALL)
set(compiler "-appleclang${cmake_c_compiler_version_major}")
else()
set(compiler "-UNK")
message(WARNING "Unknown compiler. Created cpack package will be wrong. (override using cpack -P)")
message(WARNING "Unknown compiler. Name of created cpack package will be wrong. (override using cpack -P)")
endif()
endif()
if(LIBRW_PLATFORM_NULL)
Expand All @@ -133,21 +140,31 @@ if(LIBRW_INSTALL)
if(NOT LIBRW_PLATFORM_PS2)
if(WIN32)
set(os "-win")
elseif(NINTENDO_SWITCH)
set(os "-switch")
elseif(PS2)
set(os "-ps2")
elseif(APPLE)
set(os "-apple")
elseif(UNIX)
set(os "-linux")
elseif(NINTENDO_SWITCH)
set(os "-switch")
else()
set(compiler "-UNK")
message(WARNING "Unknown os. Created cpack package will be wrong. (override using cpack -P)")
message(WARNING "Unknown os. Name of created cpack package will be wrong. (override using cpack -P)")
endif()
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|amd64|[xX]86(_64)?|i[3-6]86)$")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(processor "-x86")
else()
set(processor "-x64")
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|AARCH64)$")
set(processor "-aarch64")
else()
set(processor "-UNK")
message(WARNING "Unknown processor (${CMAKE_SYSTEM_PROCESSOR}). Name of created cpack package will be wrong. (override using cpack -P)")
endif()

set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${platform}${os}${compiler}")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${platform}${os}${processor}${compiler}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A (partial) re-implementation of RenderWare Graphics")
set(CPACK_PACKAGE_VENDOR "aap")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/LICENSE")
Expand Down
107 changes: 86 additions & 21 deletions cmake/FindSDL2.cmake
Original file line number Diff line number Diff line change
@@ -1,38 +1,103 @@
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(SDL2 IMPORTED_TARGET "sdl2")
if(TARGET PkgConfig::SDL2 AND NOT TARGET SDL2::SDL2)
add_library(SDL2::SDL2 INTERFACE IMPORTED)
set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES PkgConfig::SDL2)
# This script supports shared and static SDL2 simultaneously.

if(NOT DEFINED SDL2_STATIC_INIT)
set(SDL2_STATIC_INIT OFF)
endif()
option(SDL2_STATIC "By default, use static SDL2." ${SDL2_STATIC_INIT})

if(MSVC)
set(_lib_prefix )
set(_lib_static_suffix .lib)
set(_lib_shared_suffix .dll.lib)
else()
set(_lib_prefix lib)
if(WIN32)
set(_lib_static_suffix .a)
set(_lib_shared_suffix .dll.a)
else()
set(_lib_static_suffix .a)
if(APPLE)
set(_lib_shared_suffix .dylib)
else()
set(_lib_shared_suffix .so)
endif()
endif()
endif()

find_library(SDL2main_LIBRARY SDL2main)
find_path(SDL2_INCLUDE_DIR SDL.h PATH_SUFFIXES SDL2)
find_library(SDL2_STATIC_LIBRARY NAMES ${_lib_prefix}SDL2${_lib_static_suffix})
find_library(SDL2_SHARED_LIBRARY NAMES ${_lib_prefix}SDL2${_lib_shared_suffix})

# SDL2main is always a static library
find_library(SDL2_SDL2main_LIBRARY ${_lib_prefix}SDL2main${_lib_static_suffix})

set(_sdl2_required_variables )
if(SDL2_STATIC)
list(APPEND _sdl2_required_variables SDL2_STATIC_LIBRARY)
else()
list(APPEND _sdl2_required_variables SDL2_SHARED_LIBRARY)
endif()
list(APPEND _sdl2_required_variables SDL2_INCLUDE_DIR)

if(NOT SDL2_FOUND)
find_path(SDL2_INCLUDE_DIR sdl2.h)
find_library(SDL2_LIBRARY SDL2 SDL2d)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SDL2
REQUIRED_VARS ${_sdl2_required_variables}
)

find_library(SDL2main_LIBRARY SDL2main)
set(SDL2_SHARED_EXTRA_LIBRARIES CACHE STRING "SDL2 extra shared libraries")
if(WIN32)
set(SDL2_STATIC_EXTRA_LIBRARIES imm32 setupapi version winmm CACHE STRING "SDL2 extra static libraries")
else()
set(SDL2_STATIC_EXTRA_LIBRARIES CACHE STRING "SDL2 extra static libraries")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(libuv
REQUIRED_VARS SDL2_INCLUDE_DIR SDL2_LIBRARY
if(SDL2_INCLUDE_DIR AND SDL2_STATIC_LIBRARY AND NOT TARGET SDL2::SDL2_static)
add_library(SDL2::SDL2_static STATIC IMPORTED)
set_target_properties(SDL2::SDL2_static PROPERTIES
IMPORTED_LOCATION "${SDL2_STATIC_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${SDL2_STATIC_EXTRA_LIBRARIES}"
)
endif()

if(NOT TARGET SDL2::SDL2)
add_library(SDL2::SDL2 UNKNOWN IMPORTED)
if(SDL2_INCLUDE_DIR AND SDL2_SHARED_LIBRARY AND NOT TARGET SDL2::SDL2_shared)
add_library(SDL2::SDL2_shared SHARED IMPORTED)
set_target_properties(SDL2::SDL2_shared PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${SDL2_SHARED_EXTRA_LIBRARIES}"
)
if(WIN32)
set_target_properties(SDL2::SDL2_shared PROPERTIES
IMPORTED_IMPLIB "${SDL2_SHARED_LIBRARY}"
)
else()
set_target_properties(SDL2::SDL2_shared PROPERTIES
IMPORTED_LOCATION "${SDL2_SHARED_LIBRARY}"
)
endif()
endif()

if(SDL2_FOUND AND NOT TARGET SDL2::SDL2)
add_library(SDL2::SDL2 INTERFACE IMPORTED)
if(SDL2_STATIC)
set_target_properties(SDL2::SDL2 PROPERTIES
INTERFACE_LINK_LIBRARIES "SDL2::SDL2_static"
)
else()
set_target_properties(SDL2::SDL2 PROPERTIES
IMPORTED_LOCATION "${SDL2_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "SDL2::SDL2_shared"
)
endif()
endif()

if(SDL2main_LIBRARY AND NOT TARGET SDL2::SDL2main)
add_library(SDL2::SDL2main UNKNOWN IMPORTED)
if(SDL2_SDL2main_LIBRARY AND NOT TARGET SDL2::SDL2main)
message(STATUS "SDL2main is available")
add_library(SDL2::SDL2main STATIC IMPORTED)
set_target_properties(SDL2::SDL2main PROPERTIES
IMPORTED_LOCATION "${SDL2main_LIBRARY}"
IMPORTED_LOCATION "${SDL2_SDL2main_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
)
else()
message(STATUS "SDL2main is NOT available")
endif()

79 changes: 79 additions & 0 deletions cmake/Findglfw3.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This script supports shared and static libglfw3 simultaneously.

if(NOT DEFINED GLFW3_STATIC_INIT)
set(GLFW3_STATIC_INIT OFF)
endif()
option(GLFW3_STATIC "By default, use static glfw3." ${GLFW3_STATIC_INIT})

if(MSVC)
set(_lib_prefix )
set(_lib_static_suffix .lib)
set(_lib_shared_suffix .dll.lib)
else()
set(_lib_prefix lib)
if(WIN32)
set(_lib_static_suffix .a)
set(_lib_shared_suffix .dll.a)
else()
set(_lib_static_suffix .a)
if(APPLE)
set(_lib_shared_suffix .dylib)
else()
set(_lib_shared_suffix .so)
endif()
endif()
endif()

find_path(GLFW3_INCLUDE_DIR glfw3.h PATH_SUFFIXES GLFW)
find_library(GLFW3_STATIC_LIBRARY NAMES ${_lib_prefix}glfw3${_lib_static_suffix} ${_lib_prefix}glfw${_lib_static_suffix})
find_library(GLFW3_SHARED_LIBRARY NAMES ${_lib_prefix}glfw3${_lib_shared_suffix} ${_lib_prefix}glfw${_lib_shared_suffix})

set(_glfw3_required_variables )
if(GLFW3_STATIC)
list(APPEND _glfw3_required_variables GLFW3_STATIC_LIBRARY)
else()
list(APPEND _glfw3_required_variables GLFW3_SHARED_LIBRARY)
endif()
list(APPEND _glfw3_required_variables GLFW3_INCLUDE_DIR)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(glfw3
REQUIRED_VARS ${_glfw3_required_variables}
)

if(GLFW3_INCLUDE_DIR AND GLFW3_STATIC_LIBRARY AND NOT TARGET glfw_static)
add_library(glfw_static STATIC IMPORTED)
set_target_properties(glfw_static PROPERTIES
IMPORTED_LOCATION "${GLFW3_STATIC_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${GLFW3_INCLUDE_DIR}"
)
endif()

if(GLFW3_INCLUDE_DIR AND GLFW3_SHARED_LIBRARY AND NOT TARGET glfw_shared)
add_library(glfw_shared SHARED IMPORTED)
set_target_properties(glfw_shared PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GLFW3_INCLUDE_DIR}"
)
if(WIN32)
set_target_properties(glfw_shared PROPERTIES
IMPORTED_IMPLIB "${GLFW3_SHARED_LIBRARY}"
)
else()
set_target_properties(glfw_shared PROPERTIES
IMPORTED_LOCATION "${GLFW3_SHARED_LIBRARY}"
)
endif()
endif()

if(glfw3_FOUND AND NOT TARGET glfw)
add_library(glfw INTERFACE IMPORTED)
if(GLFW3_STATIC)
set_target_properties(glfw PROPERTIES
INTERFACE_LINK_LIBRARIES "glfw_static"
)
else()
set_target_properties(glfw PROPERTIES
INTERFACE_LINK_LIBRARIES "glfw_shared"
)
endif()
endif()
7 changes: 7 additions & 0 deletions cmake/UseStaticRuntime.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if(CMAKE_C_COMPILER_ID MATCHES "^MSVC$")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

if(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang)$")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
Loading