1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-16 16:09:42 +01:00
VVVVVV/desktop_version/CMakeLists.txt
Misa 7a02f174ac Add option to not use bundled TinyXML-2, PhysFS, and UTF8-CPP
If you configure the build with -DBUNDLE_DEPENDENCIES=OFF, then VVVVVV
will dynamically link with TinyXML-2 and PhysicsFS instead of using the
bundled source code in third_party/ and statically linking with them.

Unfortunately, it doesn't seem like distros package LodePNG, and LodePNG
isn't intended to be packaged, so we can't dynamically link with it, nor
can we use some system LodePNG header files somewhere else because those
don't exist.

UTF8-CPP is a special case, because no matter what, it's going to be
statically linked with the binary (it doesn't come as a shared object
file in any way). So with -DBUNDLE_DEPENDENCIES=OFF, we will use the
system UTF8-CPP header files instead of the bundled ones, but it will
still be statically linked in with the binary.

The main motivation for doing this is so if VVVVVV ever gets packaged in
distros, distro maintainers would be more likely to accept it if there
was an option to compile the game without bundled dependencies. Also, it
discourages modifying the third-party dependencies we have, because it's
always possible for someone to compile those dependencies without our
changes, with this CMake option.
2021-02-17 09:05:11 -05:00

298 lines
8.6 KiB
CMake

# CMake File for VVVVVV
# Written by Ethan "flibitijibibo" Lee
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
# CMake Options
OPTION(ENABLE_WARNINGS "Enable compilation warnings" ON)
OPTION(ENABLE_WERROR "Treat compilation warnings as errors" OFF)
SET(BUNDLE_DEPENDENCIES ON CACHE BOOL "Use bundled TinyXML-2, PhysicsFS, and UTF8-CPP (if disabled, TinyXML-2 and PhysicsFS will be dynamically linked, LodePNG and UTF8-CPP will still be statically linked)")
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)
SET(STEAM OFF CACHE BOOL "Use the Steam API")
SET(GOG OFF CACHE BOOL "Use the GOG API")
SET(OFFICIAL_BUILD OFF CACHE BOOL "Compile an official build of the game")
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)
SET(STEAM ON)
SET(GOG ON)
ENDIF()
IF(MAKEANDPLAY)
ADD_DEFINITIONS(-DMAKEANDPLAY)
ENDIF()
# Set standard to C++98/C++03
SET(CMAKE_CXX_STANDARD 98)
SET(CMAKE_CXX_EXTENSIONS OFF) # prevent mixing stdlib implementations (dangerous!)
# Architecture Flags
IF(APPLE)
# Wow, Apple is a huge jerk these days huh?
SET(OSX_10_9_SDK_PATH /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk)
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()
ENDIF()
SET(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
LINK_DIRECTORIES(/usr/local/lib)
ADD_COMPILE_OPTIONS(-Werror=partial-availability)
ENDIF()
PROJECT(VVVVVV)
IF(APPLE)
MESSAGE(STATUS "Using macOS SDK at ${CMAKE_OSX_SYSROOT}")
ENDIF()
# Compiler Flags
ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_DEFAULT=0 -DPHYSFS_SUPPORTS_ZIP=1)
# 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)
ENDIF()
# Include Directories
IF(BUNDLE_DEPENDENCIES)
INCLUDE_DIRECTORIES(
src
../third_party/tinyxml2
../third_party/physfs
../third_party/lodepng
../third_party/utfcpp/source
)
ELSE()
INCLUDE_DIRECTORIES(
src
../third_party/lodepng
)
ENDIF()
# 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
src/Render.cpp
src/RenderFixed.cpp
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
src/XMLUtils.cpp
src/main.cpp
src/Network.c
src/ThirdPartyDeps.c
)
IF(NOT CUSTOM_LEVEL_SUPPORT STREQUAL "DISABLED")
LIST(APPEND VVV_SRC src/editor.cpp)
ENDIF()
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()
SET(XML2_SRC
../third_party/tinyxml2/tinyxml2.cpp
)
SET(PFS_SRC
../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
../third_party/physfs/physfs_platform_haiku.cpp
)
IF(APPLE)
# Are you noticing a pattern with this Apple crap yet?
SET(PFS_SRC ${PFS_SRC} ../third_party/physfs/physfs_platform_apple.m)
ENDIF()
SET(PNG_SRC ../third_party/lodepng/lodepng.c)
# Executable information
IF(WIN32)
ADD_EXECUTABLE(VVVVVV WIN32 ${VVV_SRC})
ELSE()
ADD_EXECUTABLE(VVVVVV ${VVV_SRC})
ENDIF()
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()
# 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.
TARGET_COMPILE_OPTIONS(VVVVVV PRIVATE
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Wall $<$<BOOL:${ENABLE_WERROR}>:-Werror>>
$<$<CXX_COMPILER_ID:MSVC>:
/W4 $<$<BOOL:${ENABLE_WERROR}>:/WX>>)
ENDIF()
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()
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)
TARGET_COMPILE_OPTIONS(VVVVVV PRIVATE -Werror=implicit-fallthrough)
ENDIF()
IF(MSVC)
# Disable MSVC warnings about implicit conversion
TARGET_COMPILE_OPTIONS(VVVVVV PRIVATE /wd4244)
ENDIF()
SET_PROPERTY(TARGET VVVVVV PROPERTY CXX_STANDARD 98)
SET_PROPERTY(TARGET VVVVVV PROPERTY CXX_EXTENSIONS FALSE)
# Unfortunately, it doesn't seem like distros package LodePNG
ADD_LIBRARY(lodepng-static STATIC ${PNG_SRC})
TARGET_COMPILE_DEFINITIONS(lodepng-static PRIVATE
-DLODEPNG_NO_COMPILE_ALLOCATORS
-DLODEPNG_NO_COMPILE_DISK
-DLODEPNG_NO_COMPILE_ENCODER
)
IF(BUNDLE_DEPENDENCIES)
ADD_LIBRARY(tinyxml2-static STATIC ${XML2_SRC})
ADD_LIBRARY(physfs-static STATIC ${PFS_SRC} ${PFSP_SRC})
TARGET_LINK_LIBRARIES(VVVVVV physfs-static tinyxml2-static lodepng-static)
ELSE()
FIND_PACKAGE(utf8cpp CONFIG)
TARGET_LINK_LIBRARIES(VVVVVV physfs tinyxml2 utf8cpp lodepng-static)
ENDIF()
# 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")
target_include_directories(VVVVVV SYSTEM PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_link_libraries(VVVVVV ${SDL2_LIBRARIES})
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")
target_link_libraries(VVVVVV SDL2::SDL2 SDL2_mixer)
elseif (TARGET SDL2)
message(STATUS "Using TARGET SDL2")
target_link_libraries(VVVVVV SDL2 SDL2_mixer)
else()
message(STATUS "No TARGET SDL2::SDL2, or SDL2, using variables")
find_path(SDL2_MIXER_INCLUDE_DIRS NAMES SDL_mixer.h PATH_SUFFIXES SDL2)
target_include_directories(VVVVVV SYSTEM PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>" ${SDL2_MIXER_INCLUDE_DIRS})
target_link_libraries(VVVVVV ${SDL2_LIBRARIES} SDL2_mixer)
endif()
endif()
# Yes, more Apple Crap
IF(APPLE)
FIND_LIBRARY(FOUNDATION NAMES Foundation)
FIND_LIBRARY(IOKIT NAMES IOKit)
TARGET_LINK_LIBRARIES(VVVVVV objc ${IOKIT} ${FOUNDATION})
ENDIF()
# 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()