2020-01-01 21:29:24 +01:00
# CMake File for VVVVVV
# Written by Ethan "flibitijibibo" Lee
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
2020-01-11 01:58:33 +01:00
# CMake Options
OPTION(ENABLE_WARNINGS "Enable compilation warnings" ON)
OPTION(ENABLE_WERROR "Treat compilation warnings as errors" OFF)
2020-02-10 03:21:19 +01:00
SET(CUSTOM_LEVEL_SUPPORT ENABLED CACHE STRING "Optionally disable playing and/or editing of custom levels")
SET_PROPERTY(CACHE CUSTOM_LEVEL_SUPPORT PROPERTY STRINGS ENABLED NO_EDITOR DISABLED)
2020-06-01 18:23:07 +02:00
SET(STEAM OFF CACHE BOOL "Use the Steam API")
SET(GOG OFF CACHE BOOL "Use the GOG API")
2020-11-21 03:15:25 +01:00
SET(OFFICIAL_BUILD OFF CACHE BOOL "Compile an official build of the game")
Add official, M&P, no custom levels, and no editor builds to CI
CI builds were added to this repository on the first day it was
released, and haven't really been touched since then. And since then,
2.3 has added NO_CUSTOM_LEVELS, NO_EDITOR, and OFFICIAL_BUILD builds to
the CMake file.
On top of the MAKEANDPLAY define already existing, this means CI
coverage is a bit sparse - covering compile failures for changes made to
most of the codebase, except for Steam and GOG, and not covering compile
failures if certain parts of the code get stripped out. And people do
forget to check for those configurations as well.
These mess of configurations is kind of a wake-up call to refactor and
generalize the code a bit, because we would probably be able to get rid
of at least two of these (Make & Play, and no-custom-levels) by making
it so custom levels behave indistinguishably from the main game. But,
that's something to do in 2.4. At the very least, we should cover these
in CI right now.
On a small note, I had to add a MAKEANDPLAY configure option to the
CMake file to be able to easily configure a Make & Play build from the
CI runner. This option shouldn't really be used otherwise, so I added a
note to it telling people to consider modifying MakeAndPlay.h instead.
2020-12-27 08:40:28 +01:00
SET(MAKEANDPLAY OFF CACHE BOOL "Compile a version of the game without the main campaign (provided for convenience; consider modifying MakeAndPlay.h instead")
IF(OFFICIAL_BUILD AND NOT MAKEANDPLAY)
2020-06-01 18:23:07 +02:00
SET(STEAM ON)
SET(GOG ON)
ENDIF()
Add official, M&P, no custom levels, and no editor builds to CI
CI builds were added to this repository on the first day it was
released, and haven't really been touched since then. And since then,
2.3 has added NO_CUSTOM_LEVELS, NO_EDITOR, and OFFICIAL_BUILD builds to
the CMake file.
On top of the MAKEANDPLAY define already existing, this means CI
coverage is a bit sparse - covering compile failures for changes made to
most of the codebase, except for Steam and GOG, and not covering compile
failures if certain parts of the code get stripped out. And people do
forget to check for those configurations as well.
These mess of configurations is kind of a wake-up call to refactor and
generalize the code a bit, because we would probably be able to get rid
of at least two of these (Make & Play, and no-custom-levels) by making
it so custom levels behave indistinguishably from the main game. But,
that's something to do in 2.4. At the very least, we should cover these
in CI right now.
On a small note, I had to add a MAKEANDPLAY configure option to the
CMake file to be able to easily configure a Make & Play build from the
CI runner. This option shouldn't really be used otherwise, so I added a
note to it telling people to consider modifying MakeAndPlay.h instead.
2020-12-27 08:40:28 +01:00
IF(MAKEANDPLAY)
ADD_DEFINITIONS(-DMAKEANDPLAY)
ENDIF()
2020-06-07 21:57:18 +02:00
# Set standard to C++98/C++03
SET(CMAKE_CXX_STANDARD 98)
SET(CMAKE_CXX_EXTENSIONS OFF) # prevent mixing stdlib implementations (dangerous!)
2020-01-01 21:29:24 +01:00
# Architecture Flags
IF(APPLE)
# Wow, Apple is a huge jerk these days huh?
2020-01-11 01:49:42 +01:00
SET(OSX_10_9_SDK_PATH /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk)
2020-01-11 13:40:07 +01:00
IF(NOT CMAKE_OSX_SYSROOT)
IF(IS_DIRECTORY ${OSX_10_9_SDK_PATH})
SET(CMAKE_OSX_SYSROOT ${OSX_10_9_SDK_PATH})
ELSE()
MESSAGE(WARNING "CMAKE_OSX_SYSROOT not set and macOS 10.9 SDK not found! Using default one.")
ENDIF()
2020-01-11 01:49:42 +01:00
ENDIF()
2020-01-01 21:29:24 +01:00
SET(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
LINK_DIRECTORIES(/usr/local/lib)
2020-01-10 23:12:51 +01:00
ADD_COMPILE_OPTIONS(-Werror=partial-availability)
2020-01-01 21:29:24 +01:00
ENDIF()
2020-01-11 05:24:41 +01:00
PROJECT(VVVVVV)
2020-01-11 13:40:07 +01:00
IF(APPLE)
MESSAGE(STATUS "Using macOS SDK at ${CMAKE_OSX_SYSROOT}")
ENDIF()
2020-01-01 21:29:24 +01:00
# Compiler Flags
ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_DEFAULT=0 -DPHYSFS_SUPPORTS_ZIP=1)
2020-01-11 17:23:49 +01:00
# RPATH
IF(NOT WIN32)
IF(APPLE)
SET(BIN_LIBROOT "osx")
SET(BIN_RPATH "@executable_path/osx")
ELSEIF(CMAKE_SIZEOF_VOID_P MATCHES "8")
SET(BIN_LIBROOT "lib64")
SET(BIN_RPATH "\$ORIGIN/lib64")
ELSE()
SET(BIN_LIBROOT "lib")
SET(BIN_RPATH "\$ORIGIN/lib")
ENDIF()
SET(CMAKE_SKIP_BUILD_RPATH TRUE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH ${BIN_RPATH})
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
2020-01-01 21:29:24 +01:00
ENDIF()
# Include Directories
2020-01-12 18:54:34 +01:00
INCLUDE_DIRECTORIES(
src
2020-06-03 18:42:42 +02:00
../third_party/tinyxml2
2020-01-12 18:54:34 +01:00
../third_party/physfs
../third_party/lodepng
2020-01-31 19:25:37 +01:00
../third_party/utfcpp/source
2020-01-12 18:54:34 +01:00
)
2020-01-01 21:29:24 +01:00
# Source Lists
SET(VVV_SRC
src/BinaryBlob.cpp
src/BlockV.cpp
src/Ent.cpp
src/Entity.cpp
src/FileSystemUtils.cpp
src/Finalclass.cpp
src/Game.cpp
src/Graphics.cpp
src/GraphicsResources.cpp
src/GraphicsUtil.cpp
src/Input.cpp
src/KeyPoll.cpp
src/Labclass.cpp
src/Logic.cpp
src/Map.cpp
src/Music.cpp
src/Otherlevel.cpp
src/preloader.cpp
2020-04-04 07:53:31 +02:00
src/Render.cpp
2020-11-08 00:47:49 +01:00
src/RenderFixed.cpp
2020-01-01 21:29:24 +01:00
src/Screen.cpp
src/Script.cpp
src/Scripts.cpp
src/SoundSystem.cpp
src/Spacestation2.cpp
src/TerminalScripts.cpp
src/Textbox.cpp
src/Tower.cpp
src/UtilityClass.cpp
src/WarpClass.cpp
2020-09-25 18:08:20 +02:00
src/XMLUtils.cpp
2020-01-01 21:29:24 +01:00
src/main.cpp
2020-01-13 17:15:17 +01:00
src/Network.c
2020-01-01 21:29:24 +01:00
)
2020-02-10 03:21:19 +01:00
IF(NOT CUSTOM_LEVEL_SUPPORT STREQUAL "DISABLED")
2020-02-10 01:53:01 +01:00
LIST(APPEND VVV_SRC src/editor.cpp)
ENDIF()
2020-06-01 18:23:07 +02:00
IF(STEAM)
LIST(APPEND VVV_SRC src/SteamNetwork.c)
ADD_DEFINITIONS(-DSTEAM_NETWORK)
ENDIF()
IF(GOG)
LIST(APPEND VVV_SRC src/GOGNetwork.c)
ADD_DEFINITIONS(-DGOG_NETWORK)
ENDIF()
2020-02-10 01:53:01 +01:00
2020-06-03 18:42:42 +02:00
SET(XML2_SRC
../third_party/tinyxml2/tinyxml2.cpp
)
2020-01-01 21:29:24 +01:00
SET(PFS_SRC
2020-01-12 18:54:34 +01:00
../third_party/physfs/physfs.c
../third_party/physfs/physfs_archiver_dir.c
../third_party/physfs/physfs_archiver_unpacked.c
../third_party/physfs/physfs_archiver_zip.c
../third_party/physfs/physfs_byteorder.c
../third_party/physfs/physfs_unicode.c
../third_party/physfs/physfs_platform_posix.c
../third_party/physfs/physfs_platform_unix.c
../third_party/physfs/physfs_platform_windows.c
2020-01-14 05:31:14 +01:00
../third_party/physfs/physfs_platform_haiku.cpp
2020-01-01 21:29:24 +01:00
)
IF(APPLE)
# Are you noticing a pattern with this Apple crap yet?
2020-01-12 18:54:34 +01:00
SET(PFS_SRC ${PFS_SRC} ../third_party/physfs/physfs_platform_apple.m)
2020-01-01 21:29:24 +01:00
ENDIF()
2020-01-12 18:54:34 +01:00
SET(PNG_SRC ../third_party/lodepng/lodepng.c)
2020-01-01 21:29:24 +01:00
# Executable information
IF(WIN32)
2020-01-11 17:23:49 +01:00
ADD_EXECUTABLE(VVVVVV WIN32 ${VVV_SRC})
2020-01-01 21:29:24 +01:00
ELSE()
2020-01-11 17:23:49 +01:00
ADD_EXECUTABLE(VVVVVV ${VVV_SRC})
2020-01-01 21:29:24 +01:00
ENDIF()
Update commit hash every time it changes, not just when CMake is re-ran
The commit hash is now properly updated every time it gets changed, and
not just when CMake gets re-ran.
For this to work, we need to use a few CMake tricks. We add a custom
target with ADD_CUSTOM_TARGET(), which is apparently always considered
out-of-date (but I had to add a BYPRODUCTS line to get it to actually
work), and we use the target to run a .cmake file every time we build.
Also, VVVVVV needs to depend on this custom target, to ensure that the
game gets built AFTER the version gets generated - otherwise there'll be
an error. So we do an ADD_DEPENDENCIES() after the ADD_EXECUTABLE() for
VVVVVV.
This file, version.cmake, is just the Version.h.out generation that I
added previously, but the important thing about all of this is that if
the contents of Version.h.out doesn't change, and thus if the commit
hash hasn't changed, then CMake will never recompile and relink anything
at all. (At least with the Ninja generator.)
On a small note, since the Version.h.out generation is now a separate
script that is guaranteed to get ran on every single build, while the
Git FIND_PACKAGE() gets ran only at configure time, it is possible for
the cached path of the Git executable to get out of date. Fixing this
requires a simple re-configure (ideally), but in case it wasn't fixed,
the INTERIM_COMMIT and COMMIT_DATE variables would get set to empty
strings instead of containing a value. To prevent this from happening,
I've removed ERROR_QUIET from the EXECUTE_PROCESS() calls in
version.cmake, because it's better to explicitly error if the Git
executable wasn't found than implicitly carry on like nothing happened.
2020-12-26 05:24:14 +01:00
IF(NOT OFFICIAL_BUILD)
# Add interim commit hash and its date to the build
# FIND_PACKAGE sets GIT_FOUND and GIT_EXECUTABLE
FIND_PACKAGE(Git)
IF(GIT_FOUND)
# These filenames have to be qualified, because when we run
# the CMake script, its work dir gets set to the build folder
SET(VERSION_INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/Version.h.in)
SET(VERSION_OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/Version.h.out)
ADD_CUSTOM_TARGET(
GenerateVersion ALL
# This BYPRODUCTS line is required for this to be ran every time
BYPRODUCTS ${VERSION_OUTPUT_FILE}
COMMAND ${CMAKE_COMMAND}
# These args have to be passed through, otherwise the script can't see them
# Also, these args have to come BEFORE `-P`! (Otherwise it fails with an unclear error)
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-DINPUT_FILE=${VERSION_INPUT_FILE}
-DOUTPUT_FILE=${VERSION_OUTPUT_FILE}
-P ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake
)
ADD_DEPENDENCIES(VVVVVV GenerateVersion)
# This lets Version.h know that Version.h.out exists
ADD_DEFINITIONS(-DVERSION_H_OUT_EXISTS)
ENDIF()
ENDIF()
2020-01-11 01:58:33 +01:00
# Build options
IF(ENABLE_WARNINGS)
# The weird syntax is due to CMake generator expressions.
# Saves quite a few lines and boilerplate at the price of readability.
2020-01-11 17:23:49 +01:00
TARGET_COMPILE_OPTIONS(VVVVVV PRIVATE
2020-01-11 01:58:33 +01:00
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
2020-01-12 01:28:39 +01:00
-Wall $<$<BOOL:${ENABLE_WERROR}>:-Werror>>
2020-01-11 01:58:33 +01:00
$<$<CXX_COMPILER_ID:MSVC>:
2020-01-12 01:28:39 +01:00
/W4 $<$<BOOL:${ENABLE_WERROR}>:/WX>>)
2020-01-11 01:58:33 +01:00
ENDIF()
2020-02-10 03:21:19 +01:00
IF(CUSTOM_LEVEL_SUPPORT STREQUAL "NO_EDITOR")
ADD_DEFINITIONS(-DNO_EDITOR)
ELSEIF(CUSTOM_LEVEL_SUPPORT STREQUAL "DISABLED")
ADD_DEFINITIONS(-DNO_CUSTOM_LEVELS -DNO_EDITOR)
ENDIF()
2020-04-23 21:32:34 +02:00
IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
SET(SUPPORTS_IMPLICIT_FALLTHROUGH 1)
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
IF(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
SET(SUPPORTS_IMPLICIT_FALLTHROUGH 1)
ELSE()
SET(SUPPORTS_IMPLICIT_FALLTHROUGH 0)
ENDIF()
ELSE()
SET(SUPPORTS_IMPLICIT_FALLTHROUGH 0)
ENDIF()
IF(SUPPORTS_IMPLICIT_FALLTHROUGH)
2020-04-17 21:34:09 +02:00
TARGET_COMPILE_OPTIONS(VVVVVV PRIVATE -Werror=implicit-fallthrough)
ENDIF()
2020-04-17 21:22:43 +02:00
2020-06-07 21:48:07 +02:00
SET_PROPERTY(TARGET VVVVVV PROPERTY CXX_STANDARD 98)
SET_PROPERTY(TARGET VVVVVV PROPERTY CXX_EXTENSIONS FALSE)
2020-01-01 21:29:24 +01:00
# Library information
2020-06-03 18:42:42 +02:00
ADD_LIBRARY(tinyxml2-static STATIC ${XML2_SRC})
2020-01-01 21:29:24 +01:00
ADD_LIBRARY(physfs-static STATIC ${PFS_SRC} ${PFSP_SRC})
ADD_LIBRARY(lodepng-static STATIC ${PNG_SRC})
# Static Dependencies
2020-06-04 04:37:01 +02:00
TARGET_LINK_LIBRARIES(VVVVVV physfs-static tinyxml2-static lodepng-static)
2020-01-01 21:29:24 +01:00
# SDL2 Dependency (Detection pulled from FAudio)
if (DEFINED SDL2_INCLUDE_DIRS AND DEFINED SDL2_LIBRARIES)
message(STATUS "Using pre-defined SDL2 variables SDL2_INCLUDE_DIRS and SDL2_LIBRARIES")
2020-11-17 17:31:40 +01:00
target_include_directories(VVVVVV SYSTEM PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
2020-01-11 17:23:49 +01:00
target_link_libraries(VVVVVV ${SDL2_LIBRARIES})
2020-01-01 21:29:24 +01:00
else()
# Only try to autodetect if both SDL2 variables aren't explicitly set
find_package(SDL2 CONFIG)
if (TARGET SDL2::SDL2)
message(STATUS "Using TARGET SDL2::SDL2")
2020-01-11 17:23:49 +01:00
target_link_libraries(VVVVVV SDL2::SDL2 SDL2_mixer)
2020-01-01 21:29:24 +01:00
elseif (TARGET SDL2)
message(STATUS "Using TARGET SDL2")
2020-01-11 17:23:49 +01:00
target_link_libraries(VVVVVV SDL2 SDL2_mixer)
2020-01-01 21:29:24 +01:00
else()
message(STATUS "No TARGET SDL2::SDL2, or SDL2, using variables")
2020-06-07 22:11:12 +02:00
find_path(SDL2_MIXER_INCLUDE_DIRS NAMES SDL_mixer.h PATH_SUFFIXES SDL2)
2020-11-17 17:31:40 +01:00
target_include_directories(VVVVVV SYSTEM PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>" ${SDL2_MIXER_INCLUDE_DIRS})
2020-01-11 17:23:49 +01:00
target_link_libraries(VVVVVV ${SDL2_LIBRARIES} SDL2_mixer)
2020-01-01 21:29:24 +01:00
endif()
endif()
# Yes, more Apple Crap
IF(APPLE)
FIND_LIBRARY(FOUNDATION NAMES Foundation)
FIND_LIBRARY(IOKIT NAMES IOKit)
2020-01-11 17:23:49 +01:00
TARGET_LINK_LIBRARIES(VVVVVV objc ${IOKIT} ${FOUNDATION})
2020-01-01 21:29:24 +01:00
ENDIF()
2020-01-14 05:31:14 +01:00
# But hey, also some Haiku crap
IF(HAIKU)
FIND_LIBRARY(BE_LIBRARY be)
FIND_LIBRARY(ROOT_LIBRARY root)
TARGET_LINK_LIBRARIES(VVVVVV ${BE_LIBRARY} ${ROOT_LIBRARY})
ENDIF()