Skip to content

Commit

Permalink
Merge pull request OpenApoc#527 from SupSuper/cmake-only
Browse files Browse the repository at this point in the history
Use CMake for Windows builds
  • Loading branch information
SupSuper authored Mar 11, 2019
2 parents b89e884 + 29d5845 commit 344a16d
Show file tree
Hide file tree
Showing 70 changed files with 248 additions and 7,703 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Icon
[Ii]pch/
.vs/
*.VC.*
CMakeSettings.json
#Dependencies build information
[Dd]ependencies/x64/

Expand Down
13 changes: 13 additions & 0 deletions .vs/launch.vs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "OpenApoc.exe (bin\\OpenApoc.exe)",
"name": "OpenApoc.exe (bin\\OpenApoc.exe)",
"currentDir": "${workspaceRoot}"
}
]
}
44 changes: 24 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ INCLUDE(CheckCCompilerFlag)
string(TOLOWER "${CMAKE_BUILD_TYPE}" lower_build_type)

option(LTO "Build using link-time-optimisations" OFF)
option(MSVC_PDB "Always generate PDB files" OFF)
option(ENABLE_TESTS "Build some unit tests" ON)
option(EXTRACT_DATA "Run the data extractor as part of the default target" ON)

Expand All @@ -37,11 +38,6 @@ set(CMAKE_C_FLAGS_QUICK "-O1 -g0")
set(CMAKE_CXX_FLAGS_QUICK "-O1 -g0")


CHECK_CXX_COMPILER_FLAG("-flto"
COMPILER_SUPPORTS_LTO)
CHECK_CXX_COMPILER_FLAG("-flto=4"
COMPILER_SUPPORTS_LTO4)

CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden"
CXX_COMPILER_SUPPORTS_HIDDEN_VISIBILITY)
CHECK_C_COMPILER_FLAG("-fvisibility=hidden"
Expand All @@ -55,11 +51,20 @@ if (C_COMPILER_SUPPORTS_HIDDEN_VISIBILITY)
endif()

if (LTO)
CHECK_CXX_COMPILER_FLAG("-flto"
COMPILER_SUPPORTS_LTO)
CHECK_CXX_COMPILER_FLAG("-flto=4"
COMPILER_SUPPORTS_LTO4)

if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
set(CMAKE_AR gcc-ar)
set(CMAKE_RANLIB gcc-ranlib)
endif()
if (COMPILER_SUPPORTS_LTO4)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTGC")
elseif (COMPILER_SUPPORTS_LTO4)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=4")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto=4")
elseif(COMPILER_SUPPORTS_LTO)
Expand All @@ -77,21 +82,27 @@ CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)

if (COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
elseif (COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif (COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
# Other compilers may use different option flags, or not support switching standard versions, so try anyway
message(WARNING "Couldn't find a c++ version this compiler supports, trying with default options")
# Other compilers may use different option flags, or not support switching standard versions, so try anyway
message(WARNING "Couldn't find a c++ version this compiler supports, trying with default options")
endif()

# MSVC has default flags that CMake doesn't set
if (MSVC)
add_definitions(-DUNICODE -D_UNICODE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /permissive-")
if (MSVC_VERSION GREATER_EQUAL 1910)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /permissive-")
endif()
if (MSVC_PDB)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif()
endif()

# Clang whines about unused arguments, which is annoying (for example) when
Expand Down Expand Up @@ -188,13 +199,6 @@ add_dependencies(format format-aliases)

set(CLANG_FORMAT clang-format CACHE STRING "clang-format executable name in PATH")

foreach(FORMAT_SOURCE ${FORMAT_SOURCES})
string(MAKE_C_IDENTIFIER ${FORMAT_SOURCE} FORMAT_SOURCE_STRIPPED)
add_custom_target(format-source-${FORMAT_SOURCE_STRIPPED} ${CLANG_FORMAT} -i ${FORMAT_SOURCE} DEPENDS ${FORMAT_SOURCE} .clang-format)
add_dependencies(format-sources
format-source-${FORMAT_SOURCE_STRIPPED})
endforeach()

file(GLOB_RECURSE XML_FILES ${CMAKE_SOURCE_DIR}/data/*.xml)

file(GLOB_RECURSE FONT_FILES ${CMAKE_SOURCE_DIR}/data/fonts/*.font)
Expand Down
Binary file removed OpenApoc - Extract.lnk
Binary file not shown.
Binary file removed OpenApoc - Play.lnk
Binary file not shown.
248 changes: 0 additions & 248 deletions OpenApoc.sln

This file was deleted.

32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ The following libraries are also used, but are shipped as submodules in the repo
* [GLM](https://glm.g-truc.net) - Math library.
* [libsmacker](https://sourceforge.net/projects/libsmacker/) - Decoder for .smk video files.
* [lodepng](https://github.com/lvandeve/lodepng) - Reading/writing PNG image files.
* [Lua](https://www.lua.org/) - Scripting language.
* [miniz](https://github.com/richgel999/miniz) - Zlib-comptible compression library.
* [physfs](https://icculus.org/physfs/) - Library for reading data from .iso files or directory trees (Note: We use a patched version, available on [GitHub](https://github.com/JonnyH/physfs-hg-import/tree/fix-iso) - required to read the .iso files we use).
* [pugixml](https://pugixml.org) - XML library used for reading/writing the game data files.
Expand All @@ -127,14 +128,30 @@ The following libraries are also used, but are shipped as submodules in the repo
* If you are using the GitHub client for Windows, the submodules should already be setup at first checkout. If not using the github client, or if the submodules have been updated, run the following commands in the 'git shell' from the root of the OpenApoc repository. This should reset the submodule checkouts to the latest versions (NOTE: This will overwrite any changes to code in the dependencies/ directory).

```cmd
git submodule init
git submodule update -f
git submodule update --init --recursive
```

* All the other dependencies (Boost, SDL2) need to be supplied separately. Install [Vcpkg](https://github.com/Microsoft/vcpkg) and run the following command:

```cmd
vcpkg install sdl2 boost-locale boost-system boost-program-options boost-filesystem boost-uuid boost-crc
```

* All the other dependencies (Boost, SDL2) are provided automatically by nuget packages, and Visual Studio should automatically download and install these at the first build.
* Copy the original XCom:Apocalypse .iso file into the "data/" directory. This could also be a directory containing all the extracted files from the CD, and it should be named the same (IE the directory should be data/cd.iso/). This is used during the build to extract some data tables.
* Open openapoc.sln in Visual Studio.
* Build (Release/Debug x86/x64 should all work).
* Open the Git directory in Visual Studio (if you don't have an Open Folder option, generate a project from CMake).
* Visual Studio should automatically detect and configure CMake appropriately. To add your Vcpkg dependencies, edit your CMake Settings file and add:

```json
"variables": [
{
"name": "CMAKE_TOOLCHAIN_FILE",
"value": "<path to vcpkg>\\scripts\\buildsystems\\vcpkg.cmake"
}
]
```

* If you get errors, clear your cache from the CMake menu and generate again.
* Build (Release/Debug x86/x64 should all work). Release is recommended as Debug is very slow.
* When running from the Visual Studio UI, the working directory is set to the root of the project, so the data folder should already be in the right place. If you want to run outside of Visual Studio, you need to copy the whole 'data' folder (including the cd.iso file) into the folder openapoc.exe resides in.

### Building on Linux
Expand All @@ -157,11 +174,10 @@ urpmi "cmake(sdl2)" libstdc++-static-devel boost-devel boost unwind-devel task-c
* Fetch the dependencies from git with the following terminal command (run from the just-created OpenApoc folder).

```sh
git submodule init
git submodule update
git submodule update --init --recursive
```

* Copy the cd.iso file to the 'data' directory under the repository root (Note - despite dosbox having good linux support, the steam version of X-Com Apocalypse refuses to install in steam for linux - you may need to snatch the cd.iso file off a windows steam install).
* Copy the cd.iso file to the 'data' directory under the repository root (Note - despite dosbox having good linux support, the steam version of X-Com Apocalypse will only install if Steam Play is enabled).

```sh
cp /path/to/cd.iso data/
Expand Down
77 changes: 49 additions & 28 deletions appveyor-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,55 @@ configuration:
platform:
- x64
# - Win32
environment:
APPVEYOR_SAVE_CACHE_ON_ERROR: true
init:
- if "%PLATFORM%"=="x64" (set VCPKG_DEFAULT_TRIPLET=x64-windows)
- if "%PLATFORM%"=="x64" (set VCVARS_ARCH=amd64)
- if "%PLATFORM%"=="Win32" (set VCPKG_DEFAULT_TRIPLET=x86-windows)
- if "%PLATFORM%"=="Win32" (set VCVARS_ARCH=amd64_x86)
#clone_depth: 10
cache: c:\tools\vcpkg\installed
before_build:
- git submodule init
- git submodule update
- nuget restore OpenApoc.sln
- curl http://s2.jonnyh.net/pub/cd_minimal.iso.xz -o data\cd.iso.xz
- 7z e data\cd.iso.xz -odata\
build:
project: OpenApoc.sln
verbosity: normal
- vcpkg install sdl2 boost-locale boost-system boost-program-options boost-filesystem boost-uuid boost-crc
- vcpkg upgrade --no-dry-run
- git submodule update --init --recursive
- curl http://s2.jonnyh.net/pub/cd_minimal.iso.xz -o temp\cd.iso.xz
- 7z e temp\cd.iso.xz -odata\
- choco install ninja
- call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %VCVARS_ARCH%
build_script:
- cmake -DMSVC_PDB=ON . -GNinja -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE="%CONFIGURATION%"
- cmake --build .
after_build:
- git describe --tags > build-id
- set /p OPENAPOC_VERSION= < build-id
- set OPENAPOC_FILENAME=OpenApoc-%PLATFORM%-%OPENAPOC_VERSION%.7z
- set OPENAPOC_DEBUG_FILENAME=OpenApoc-debug-%PLATFORM%-%OPENAPOC_VERSION%.7z
- mkdir OpenApoc-%OPENAPOC_VERSION%
- echo %APPVEYOR_REPO_COMMIT% > OpenApoc-%OPENAPOC_VERSION%\git-commit
- echo %OPENAPOC_VERSION% > OpenApoc-%OPENAPOC_VERSION%\build-id
- copy bin\%PLATFORM%\%CONFIGURATION%\*.dll OpenApoc-%OPENAPOC_VERSION%\
- copy bin\%PLATFORM%\%CONFIGURATION%\OpenApoc.exe OpenApoc-%OPENAPOC_VERSION%\
- del data\cd.iso
- del data\cd.iso.xz
- xcopy /E data OpenApoc-%OPENAPOC_VERSION%\data\
- copy portable.txt OpenApoc-%OPENAPOC_VERSION%\
- copy README.md OpenApoc-%OPENAPOC_VERSION%\
- copy README_HOTKEYS.txt OpenApoc-%OPENAPOC_VERSION%\
- 7z a %OPENAPOC_FILENAME% OpenApoc-%OPENAPOC_VERSION% -mx=9 -myx=7
- copy bin\%PLATFORM%\%CONFIGURATION%\OpenApoc.pdb OpenApoc-%OPENAPOC_VERSION%\
- 7z a %OPENAPOC_DEBUG_FILENAME% OpenApoc-%OPENAPOC_VERSION%\*.pdb -mx=9 -myx=7
- appveyor PushArtifact %OPENAPOC_FILENAME%
- appveyor PushArtifact %OPENAPOC_DEBUG_FILENAME%
- git describe --tags > build-id
- set /p OPENAPOC_VERSION= < build-id
- set OPENAPOC_FILENAME=OpenApoc-%PLATFORM%-%OPENAPOC_VERSION%.7z
- set OPENAPOC_DEBUG_FILENAME=OpenApoc-debug-%PLATFORM%-%OPENAPOC_VERSION%.7z
- mkdir OpenApoc-%OPENAPOC_VERSION%
- echo %APPVEYOR_REPO_COMMIT% > OpenApoc-%OPENAPOC_VERSION%\git-commit
- echo %OPENAPOC_VERSION% > OpenApoc-%OPENAPOC_VERSION%\build-id
- copy bin\*.dll OpenApoc-%OPENAPOC_VERSION%\
- copy bin\OpenApoc.exe OpenApoc-%OPENAPOC_VERSION%\
- del data\cd.iso
- xcopy /E data OpenApoc-%OPENAPOC_VERSION%\data\
- copy portable.txt OpenApoc-%OPENAPOC_VERSION%\
- copy README.md OpenApoc-%OPENAPOC_VERSION%\README.txt
- copy README_HOTKEYS.txt OpenApoc-%OPENAPOC_VERSION%\
- 7z a %OPENAPOC_FILENAME% OpenApoc-%OPENAPOC_VERSION% -mx=9 -myx=7
- copy bin\OpenApoc.pdb OpenApoc-%OPENAPOC_VERSION%\
- 7z a %OPENAPOC_DEBUG_FILENAME% OpenApoc-%OPENAPOC_VERSION%\*.pdb -mx=9 -myx=7
- appveyor PushArtifact %OPENAPOC_FILENAME%
- appveyor PushArtifact %OPENAPOC_DEBUG_FILENAME%
before_test:
- 7z e temp\cd.iso.xz -odata\
test_script:
- ctest -T Test -V --no-compress-output -C %CONFIGURATION%
on_finish:
- ps: |
$testFile = ".\Testing\$(Get-Content Testing\TAG -TotalCount 1)\Test.xml"
$XSLInputElement = New-Object System.Xml.Xsl.XslCompiledTransform
$XSLInputElement.Load((Resolve-Path .\tests\ctest-to-junit.xsl))
$XSLInputElement.Transform((Resolve-Path $testFile), (Join-Path (Resolve-Path .) "ctest-to-junit-results.xml"))
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\ctest-to-junit-results.xml))
49 changes: 35 additions & 14 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@ configuration:
platform:
- x64
- Win32
environment:
APPVEYOR_SAVE_CACHE_ON_ERROR: true
init:
- if "%PLATFORM%"=="x64" (set VCPKG_DEFAULT_TRIPLET=x64-windows)
- if "%PLATFORM%"=="x64" (set VCVARS_ARCH=amd64)
- if "%PLATFORM%"=="Win32" (set VCPKG_DEFAULT_TRIPLET=x86-windows)
- if "%PLATFORM%"=="Win32" (set VCVARS_ARCH=amd64_x86)
#clone_depth: 10
cache: c:\tools\vcpkg\installed
before_build:
- git submodule init
- git submodule update
- nuget restore OpenApoc.sln
- curl http://s2.jonnyh.net/pub/cd_minimal.iso.xz -o data\cd.iso.xz
- 7z e data\cd.iso.xz -odata\
build:
project: OpenApoc.sln
verbosity: normal
- vcpkg install sdl2 boost-locale boost-system boost-program-options boost-filesystem boost-uuid boost-crc
- vcpkg upgrade --no-dry-run
- git submodule update --init --recursive
- curl http://s2.jonnyh.net/pub/cd_minimal.iso.xz -o temp\cd.iso.xz
- 7z e temp\cd.iso.xz -odata\
- choco install nsis -pre
- choco install ninja
- call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %VCVARS_ARCH%
build_script:
- cmake -DMSVC_PDB=ON . -GNinja -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE="%CONFIGURATION%"
- cmake --build .
after_build:
- git describe --tags > build-id
- set /p OPENAPOC_VERSION= < build-id
Expand All @@ -29,19 +40,29 @@ after_build:
- mkdir OpenApoc-%OPENAPOC_VERSION%
- echo %APPVEYOR_REPO_COMMIT% > OpenApoc-%OPENAPOC_VERSION%\git-commit
- echo %OPENAPOC_VERSION% > OpenApoc-%OPENAPOC_VERSION%\build-id
- copy bin\%PLATFORM%\%CONFIGURATION%\*.dll OpenApoc-%OPENAPOC_VERSION%\
- copy bin\%PLATFORM%\%CONFIGURATION%\*.exe OpenApoc-%OPENAPOC_VERSION%\
- copy bin\*.dll OpenApoc-%OPENAPOC_VERSION%\
- copy bin\*.exe OpenApoc-%OPENAPOC_VERSION%\
- del data\cd.iso
- del data\cd.iso.xz
- xcopy /E data OpenApoc-%OPENAPOC_VERSION%\data\
- copy portable.txt OpenApoc-%OPENAPOC_VERSION%\
- copy README.md OpenApoc-%OPENAPOC_VERSION%\
- copy README.md OpenApoc-%OPENAPOC_VERSION%\README.txt
- copy README_HOTKEYS.txt OpenApoc-%OPENAPOC_VERSION%\
- 7z a %OPENAPOC_FILENAME% OpenApoc-%OPENAPOC_VERSION%
- copy bin\%PLATFORM%\%CONFIGURATION%\*.pdb OpenApoc-%OPENAPOC_VERSION%\
- copy bin\*.pdb OpenApoc-%OPENAPOC_VERSION%\
- 7z a %OPENAPOC_DEBUG_FILENAME% OpenApoc-%OPENAPOC_VERSION%\*.pdb
- appveyor PushArtifact %OPENAPOC_FILENAME%
- appveyor PushArtifact %OPENAPOC_DEBUG_FILENAME%
- choco install nsis -pre
- '"C:\Program Files (x86)\NSIS\makensis.exe" /DGAME_VERSION=%OPENAPOC_VERSION% install\windows\installer.nsi'
- appveyor PushArtifact install\windows\install-openapoc-%OPENAPOC_VERSION%.exe
before_test:
- 7z e temp\cd.iso.xz -odata\
test_script:
- ctest -T Test -V --no-compress-output -C %CONFIGURATION%
on_finish:
- ps: |
$testFile = ".\Testing\$(Get-Content Testing\TAG -TotalCount 1)\Test.xml"
$XSLInputElement = New-Object System.Xml.Xsl.XslCompiledTransform
$XSLInputElement.Load((Resolve-Path .\tests\ctest-to-junit.xsl))
$XSLInputElement.Transform((Resolve-Path $testFile), (Join-Path (Resolve-Path .) "ctest-to-junit-results.xml"))
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\ctest-to-junit-results.xml))
19 changes: 0 additions & 19 deletions clang_format_win.bat

This file was deleted.

Loading

0 comments on commit 344a16d

Please sign in to comment.