Skip to content

Commit

Permalink
CMake: Cleanup no-mpq config
Browse files Browse the repository at this point in the history
Introduce a `SUPPORTS_MPQ` variable and use it throughout.
Also disables fetching bzip2 when MPQ support is disabled.
  • Loading branch information
glebm committed Mar 18, 2023
1 parent 243c3ff commit 6bbe9e5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
19 changes: 11 additions & 8 deletions CMake/Dependencies.cmake
Expand Up @@ -12,12 +12,15 @@ else()
endif()
endif()

if(EMSCRIPTEN)
emscripten_system_library("bzip2" BZip2::BZip2 USE_BZIP2=1)
else()
dependency_options("bzip2" DEVILUTIONX_SYSTEM_BZIP2 ON DEVILUTIONX_STATIC_BZIP2)
if(NOT DEVILUTIONX_SYSTEM_BZIP2)
add_subdirectory(3rdParty/bzip2)
if(SUPPORTS_MPQ)
# bzip2 is a libmpq dependency.
if(EMSCRIPTEN)
emscripten_system_library("bzip2" BZip2::BZip2 USE_BZIP2=1)
else()
dependency_options("bzip2" DEVILUTIONX_SYSTEM_BZIP2 ON DEVILUTIONX_STATIC_BZIP2)
if(NOT DEVILUTIONX_SYSTEM_BZIP2)
add_subdirectory(3rdParty/bzip2)
endif()
endif()
endif()

Expand Down Expand Up @@ -182,15 +185,15 @@ else()
add_subdirectory(3rdParty/simpleini)
endif()

if(NOT (UNPACKED_MPQS AND UNPACKED_SAVES))
if(SUPPORTS_MPQ)
add_subdirectory(3rdParty/libmpq)
endif()

add_subdirectory(3rdParty/tl)

add_subdirectory(3rdParty/hoehrmann_utf8)

if(NOT (UNPACKED_MPQS AND UNPACKED_SAVES AND NONET))
if(SUPPORTS_MPQ OR NOT NONET)
add_subdirectory(3rdParty/PKWare)
endif()

Expand Down
31 changes: 21 additions & 10 deletions CMakeLists.txt
Expand Up @@ -139,18 +139,29 @@ mark_as_advanced(DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT)
option(DISABLE_DEMOMODE "Disable demo mode support" OFF)
option(DISCORD_INTEGRATION "Build with Discord SDK for rich presence support" OFF)

# By default, devilutionx.mpq is built only if smpq is installed.
if(NOT DEFINED BUILD_ASSETS_MPQ AND NOT SRC_DIST)
find_program(SMPQ smpq)
elseif(BUILD_ASSETS_MPQ)
find_program(SMPQ smpq REQUIRED)
endif()
if(SMPQ)
set(_has_smpq ON)
# If both UNPACKED_MPQS and UNPACKED_SAVES are enabled, we completely remove MPQ support.
if(UNPACKED_MPQS AND UNPACKED_SAVES)
set(SUPPORTS_MPQ OFF)
else()
set(_has_smpq OFF)
set(SUPPORTS_MPQ ON)
endif()

# By default, devilutionx.mpq is built only if smpq is installed and MPQ support is enabled.
if(SUPPORTS_MPQ)
if(NOT DEFINED BUILD_ASSETS_MPQ AND NOT SRC_DIST)
find_program(SMPQ smpq)
elseif(BUILD_ASSETS_MPQ)
find_program(SMPQ smpq REQUIRED)
endif()
if(SMPQ)
set(_has_smpq ON)
else()
set(_has_smpq OFF)
endif()
option(BUILD_ASSETS_MPQ "If true, assets are packaged into devilutionx.mpq." ${_has_smpq})
else()
set(BUILD_ASSETS_MPQS OFF)
endif()
option(BUILD_ASSETS_MPQ "If true, assets are packaged into devilutionx.mpq." ${_has_smpq})

# === Option overrides ===
# TSAN is not compatible with ASAN.
Expand Down
4 changes: 2 additions & 2 deletions Source/CMakeLists.txt
Expand Up @@ -164,15 +164,15 @@ set(libdevilutionx_SRCS
utils/surface_to_clx.cpp
utils/utf8.cpp)

if(NOT (UNPACKED_MPQS AND UNPACKED_SAVES))
if(SUPPORTS_MPQ)
list(APPEND libdevilutionx_DEPS libmpq)
list(APPEND libdevilutionx_SRCS
mpq/mpq_reader.cpp
mpq/mpq_sdl_rwops.cpp
mpq/mpq_writer.cpp)
endif()

if(NOT (UNPACKED_MPQS AND UNPACKED_SAVES AND NONET))
if(SUPPORTS_MPQ OR NOT NONET)
list(APPEND libdevilutionx_DEPS PKWare)
list(APPEND libdevilutionx_SRCS encrypt.cpp)
endif()
Expand Down

0 comments on commit 6bbe9e5

Please sign in to comment.