From 05b2b8da80037887d3e79af8a59a8f0f8ed02602 Mon Sep 17 00:00:00 2001 From: Roman Siromakha Date: Tue, 19 Jun 2018 00:11:36 +0300 Subject: [PATCH] CMake for Windows (#339) * Build with cmake in appveyor * Install content files and tests binary to bin * Install SDL2.dll on windows * Build RecastDemo as GUI application on Windows and Mac OS * Copy SDL2.dll to current binary dir --- .travis.yml | 2 +- CMakeLists.txt | 2 +- RecastDemo/CMakeLists.txt | 35 ++++++++++++++++++++++++++++------- Tests/CMakeLists.txt | 2 ++ appveyor.yml | 15 +++++++++++++-- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index f39e8c6..6044cd6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ install: # Have to cd into directory and back out since premake5 doesn't appear to accept a directory argument. before_script: - cd RecastDemo && ../premake5 gmake && cd .. - - mkdir build && cd build && cmake -DRECASTNAVIGATION_STATIC=TRUE -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} .. && cd .. + - mkdir build && cd build && cmake -D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} .. && cd .. # Run make in the directory containing generated makefiles, on the configuration specified by the environment variable. script: diff --git a/CMakeLists.txt b/CMakeLists.txt index d4fff42..d23859d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ SET(VERSION 1.0.0) option(RECASTNAVIGATION_DEMO "Build demo" ON) option(RECASTNAVIGATION_TESTS "Build tests" ON) option(RECASTNAVIGATION_EXAMPLES "Build examples" ON) -option(RECASTNAVIGATION_STATIC "Build static libraries" OFF) +option(RECASTNAVIGATION_STATIC "Build static libraries" ON) add_subdirectory(DebugUtils) add_subdirectory(Detour) diff --git a/RecastDemo/CMakeLists.txt b/RecastDemo/CMakeLists.txt index c3ee81b..ffeac6a 100644 --- a/RecastDemo/CMakeLists.txt +++ b/RecastDemo/CMakeLists.txt @@ -1,12 +1,15 @@ file(GLOB SOURCES Source/*.cpp Contrib/fastlz/fastlz.c) -LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +if(NOT SDL2_ROOT_DIR) + set(SDL2_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Contrib/SDL") +endif() find_package(OpenGL REQUIRED) find_package(SDL2 REQUIRED) include_directories(SYSTEM ${OPENGL_INCLUDE_DIR}) -include_directories(SYSTEM ${SDL2_INCLUDE_DIR}) include_directories(SYSTEM Contrib/fastlz) include_directories(SYSTEM Contrib) include_directories(../DebugUtils/Include) @@ -16,12 +19,30 @@ include_directories(../DetourTileCache/Include) include_directories(../Recast/Include) include_directories(Include) -add_executable(RecastDemo ${SOURCES}) -file(COPY Bin/Meshes DESTINATION ${CMAKE_BINARY_DIR}/RecastDemo) -file(COPY Bin/TestCases DESTINATION ${CMAKE_BINARY_DIR}/RecastDemo) -file(COPY Bin/DroidSans.ttf DESTINATION ${CMAKE_BINARY_DIR}/RecastDemo) +if (WIN32) + add_executable(RecastDemo WIN32 ${SOURCES}) +elseif(APPLE) + add_executable(RecastDemo MACOSX_BUNDLE ${SOURCES}) +else() + add_executable(RecastDemo ${SOURCES}) +endif() + +file(COPY Bin/Meshes DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY Bin/TestCases DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY Bin/DroidSans.ttf DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +if (WIN32) + file(COPY "${SDL2_RUNTIME_LIBRARY}" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endif() add_dependencies(RecastDemo DebugUtils Detour DetourCrowd DetourTileCache Recast) -target_link_libraries(RecastDemo ${OPENGL_LIBRARIES} ${SDL2_LIBRARY} DebugUtils Detour DetourCrowd DetourTileCache Recast) +target_link_libraries(RecastDemo ${OPENGL_LIBRARIES} SDL2::SDL2main DebugUtils Detour DetourCrowd DetourTileCache Recast) install(TARGETS RecastDemo RUNTIME DESTINATION bin) +install(DIRECTORY Bin/Meshes DESTINATION bin) +install(DIRECTORY Bin/TestCases DESTINATION bin) +install(FILES Bin/DroidSans.ttf DESTINATION bin) + +if (WIN32) + install(FILES "${SDL2_RUNTIME_LIBRARY}" DESTINATION bin) +endif() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index a98ccbf..7c17469 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -8,3 +8,5 @@ add_executable(Tests ${TESTS_SOURCES}) add_dependencies(Tests Recast Detour) target_link_libraries(Tests Recast Detour) add_test(Tests Tests) + +install(TARGETS Tests RUNTIME DESTINATION bin) diff --git a/appveyor.yml b/appveyor.yml index c61bf88..2d943ab 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,10 +4,13 @@ environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 PREMAKE_ACTION: vs2013 + CMAKE_GENERATOR: Visual Studio 12 2013 Win64 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 PREMAKE_ACTION: vs2015 + CMAKE_GENERATOR: Visual Studio 14 2015 Win64 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 PREMAKE_ACTION: vs2017 + CMAKE_GENERATOR: Visual Studio 15 2017 Win64 configuration: - Debug @@ -22,10 +25,10 @@ install: # Download SDL. - ps: Start-FileDownload 'https://www.libsdl.org/release/SDL2-devel-2.0.4-VC.zip' 'RecastDemo/Contrib/SDL.zip' - + # Extract it, put it in the right place, and rename it. - cd RecastDemo\Contrib && 7z x SDL.zip && ren SDL2-2.0.4 SDL && cd ..\.. - + # Generate solution files using premake. - cd RecastDemo && "../premake5.exe" %PREMAKE_ACTION% && cd .. @@ -33,5 +36,13 @@ install: build: project: RecastDemo/Build/$(PREMAKE_ACTION)/recastnavigation.sln +after_build: + - mkdir build + - cd build + - cmake -G "%CMAKE_GENERATOR%" -DCMAKE_BUILD_TYPE="%CONFIGURATION%" -D CMAKE_INSTALL_PREFIX=. .. + - cmake --build . --config "%CONFIGURATION%" --target install -- /m:%NUMBER_OF_PROCESSORS% + - ctest -V + - cd .. + after_test: - RecastDemo\Bin\Tests.exe