Fix macOS CMake SDL linking (#584)

* Ignore cmake intermediate build dir

* Fix C++ language version in cmake build scripts

* Set a default SDL2_ROOT_DIR value for macOS in cmake scripts

* Fixed macOS SDL framework linking in cmake scripts

* Added macos-cmake target for CI builds in github workflows

* Use C++17 for building Tests instead of 20, since we build them with VS2019 in some jobs
This commit is contained in:
Graham Pentheny 2022-11-25 20:29:11 -05:00 committed by GitHub
parent 4fef044660
commit 67ba9a2a15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 2 deletions

View File

@ -46,6 +46,33 @@ jobs:
working-directory: RecastDemo/Build/xcode4/
run: xcodebuild -scheme Tests -configuration ${{matrix.conf}} -project Tests.xcodeproj build
macos-cmake:
strategy:
matrix:
conf:
- Debug
- Release
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Download & install SDL
run: |
curl -L -o SDL2.dmg https://github.com/libsdl-org/SDL/releases/download/release-2.24.2/SDL2-2.24.2.dmg
hdiutil attach SDL2.dmg
cp -r /Volumes/SDL2/SDL2.framework ${{github.workspace}}/RecastDemo/Bin/
hdiutil detach /Volumes/SDL2
rm SDL2.dmg
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.conf}} -DSDL2_LIBRARY=${{github.workspace}}/RecastDemo/Bin/SDL2.framework
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.conf}}
linux-premake:
strategy:
matrix:

3
.gitignore vendored
View File

@ -47,6 +47,9 @@ RecastDemo/Contrib/SDL/*
## Generated doc files
Docs/html
## CMake build cache
build
## IDE files
.idea/
cmake-build-*/

View File

@ -7,6 +7,8 @@ SET(SOVERSION 1)
set(LIB_VERSION 1.5.1)
string(REPLACE "." "," LIB_VERSION_NUM "${LIB_VERSION}.0")
set_property(GLOBAL PROPERTY CXX_STANDARD 98)
option(RECASTNAVIGATION_DEMO "Build demo" ON)
option(RECASTNAVIGATION_TESTS "Build tests" ON)
option(RECASTNAVIGATION_EXAMPLES "Build examples" ON)

View File

@ -3,11 +3,22 @@ file(GLOB SOURCES Source/*.cpp Contrib/fastlz/fastlz.c)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(NOT SDL2_ROOT_DIR)
if(WIN32)
set(SDL2_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Contrib/SDL")
elseif(APPLE)
set(SDL2_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
endif()
endif()
find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
if(APPLE)
find_library(SDL2_LIBRARY
NAMES SDL2
PATHS ${SDL2_ROOT_DIR}
REQUIRED)
else()
find_package(SDL2 REQUIRED)
endif()
include_directories(SYSTEM ${OPENGL_INCLUDE_DIR})
include_directories(SYSTEM Contrib/fastlz)
@ -19,6 +30,9 @@ include_directories(../DetourTileCache/Include)
include_directories(../Recast/Include)
include_directories(Include)
include_directories(Contrib/SDL/include)
if(APPLE)
include_directories(${SDL2_LIBRARY}/Headers)
endif()
if (WIN32)
add_executable(RecastDemo WIN32 ${SOURCES})
@ -54,7 +68,12 @@ endif()
add_dependencies(RecastDemo DebugUtils Detour DetourCrowd DetourTileCache Recast)
target_link_libraries(RecastDemo ${OPENGL_LIBRARIES} SDL2::SDL2main DebugUtils Detour DetourCrowd DetourTileCache Recast)
if(APPLE)
target_link_libraries(RecastDemo ${OPENGL_LIBRARIES} ${SDL2_LIBRARY} DebugUtils Detour DetourCrowd DetourTileCache Recast)
else()
target_link_libraries(RecastDemo ${OPENGL_LIBRARIES} SDL2::SDL2main DebugUtils Detour DetourCrowd DetourTileCache Recast)
endif()
install(TARGETS RecastDemo
RUNTIME DESTINATION bin

View File

@ -6,6 +6,9 @@ include_directories(./Contrib/Catch)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(Tests ${TESTS_SOURCES})
set_property(TARGET Tests PROPERTY CXX_STANDARD 17)
add_dependencies(Tests Recast Detour)
target_link_libraries(Tests Recast Detour)
add_test(Tests Tests)