2015-01-28 05:46:39 +00:00
|
|
|
# SRB2 Core
|
|
|
|
|
2021-05-08 01:57:46 +00:00
|
|
|
add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32)
|
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
# Core sources
|
2021-05-05 10:56:57 +00:00
|
|
|
target_sourcefile(c)
|
2021-07-12 10:50:44 +00:00
|
|
|
target_sources(SRB2SDL2 PRIVATE comptime.c md5.c config.h.in)
|
2015-01-28 05:46:39 +00:00
|
|
|
|
2021-05-05 10:56:57 +00:00
|
|
|
set(SRB2_ASM_SOURCES vid_copy.s)
|
2015-02-02 01:18:25 +00:00
|
|
|
|
2021-05-05 10:56:57 +00:00
|
|
|
set(SRB2_NASM_SOURCES tmap_mmx.nas tmap.nas)
|
2015-02-02 03:25:02 +00:00
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
### Configuration
|
|
|
|
set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL
|
|
|
|
"Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.")
|
|
|
|
set(SRB2_CONFIG_HAVE_ZLIB ON CACHE BOOL
|
2015-03-08 08:26:54 +00:00
|
|
|
"Enable zlib support.")
|
2015-01-28 07:20:43 +00:00
|
|
|
set(SRB2_CONFIG_HAVE_GME ON CACHE BOOL
|
2015-03-08 08:26:54 +00:00
|
|
|
"Enable GME support.")
|
2019-01-04 02:17:18 +00:00
|
|
|
set(SRB2_CONFIG_HAVE_OPENMPT ON CACHE BOOL
|
2019-01-02 08:27:24 +00:00
|
|
|
"Enable OpenMPT support.")
|
2020-04-07 05:48:43 +00:00
|
|
|
set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL
|
2020-10-31 03:37:34 +00:00
|
|
|
"Enable curl support.")
|
2020-10-20 20:44:01 +00:00
|
|
|
set(SRB2_CONFIG_HAVE_THREADS ON CACHE BOOL
|
|
|
|
"Enable multithreading support.")
|
2020-06-07 02:05:25 +00:00
|
|
|
if(${CMAKE_SYSTEM} MATCHES Windows)
|
|
|
|
set(SRB2_CONFIG_HAVE_MIXERX ON CACHE BOOL
|
|
|
|
"Enable SDL Mixer X support.")
|
|
|
|
else()
|
|
|
|
set(SRB2_CONFIG_HAVE_MIXERX OFF)
|
|
|
|
endif()
|
2015-01-28 05:46:39 +00:00
|
|
|
set(SRB2_CONFIG_HWRENDER ON CACHE BOOL
|
2015-03-08 08:26:54 +00:00
|
|
|
"Enable hardware rendering through OpenGL.")
|
2015-01-28 05:46:39 +00:00
|
|
|
set(SRB2_CONFIG_USEASM OFF CACHE BOOL
|
2015-02-02 01:18:25 +00:00
|
|
|
"Enable NASM tmap implementation for software mode speedup.")
|
2015-02-02 03:25:02 +00:00
|
|
|
set(SRB2_CONFIG_YASM OFF CACHE BOOL
|
|
|
|
"Use YASM in place of NASM.")
|
2015-01-28 07:20:43 +00:00
|
|
|
set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL
|
|
|
|
"Use statically linked OpenGL. NOT RECOMMENDED.")
|
2015-01-28 05:46:39 +00:00
|
|
|
|
2016-09-25 19:33:07 +00:00
|
|
|
### use internal libraries?
|
2018-11-14 20:58:45 +00:00
|
|
|
if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only
|
2018-11-14 01:37:14 +00:00
|
|
|
set(SRB2_CONFIG_USE_INTERNAL_LIBRARIES OFF CACHE BOOL
|
2019-01-02 08:27:24 +00:00
|
|
|
"Use SRB2's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).")
|
2018-11-14 01:37:14 +00:00
|
|
|
endif()
|
2016-09-25 19:33:07 +00:00
|
|
|
|
2021-05-05 10:56:57 +00:00
|
|
|
add_subdirectory(blua)
|
2015-01-28 05:46:39 +00:00
|
|
|
|
2015-01-28 07:20:43 +00:00
|
|
|
if(${SRB2_CONFIG_HAVE_GME})
|
2016-09-25 19:33:07 +00:00
|
|
|
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
|
|
|
|
set(GME_FOUND ON)
|
|
|
|
set(GME_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/gme/include)
|
2018-10-31 00:50:36 +00:00
|
|
|
if(${SRB2_SYSTEM_BITS} EQUAL 64)
|
|
|
|
set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win64 -lgme")
|
|
|
|
else() # 32-bit
|
|
|
|
set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win32 -lgme")
|
|
|
|
endif()
|
2016-09-25 19:33:07 +00:00
|
|
|
else()
|
|
|
|
find_package(GME)
|
|
|
|
endif()
|
2015-01-28 07:20:43 +00:00
|
|
|
if(${GME_FOUND})
|
|
|
|
set(SRB2_HAVE_GME ON)
|
2021-07-16 19:26:09 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_GME)
|
2015-01-28 07:20:43 +00:00
|
|
|
else()
|
|
|
|
message(WARNING "You have specified that GME is available but it was not found.")
|
|
|
|
endif()
|
2015-01-28 05:46:39 +00:00
|
|
|
endif()
|
|
|
|
|
2019-01-02 08:27:24 +00:00
|
|
|
if(${SRB2_CONFIG_HAVE_OPENMPT})
|
|
|
|
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
|
|
|
|
set(OPENMPT_FOUND ON)
|
2019-01-04 02:17:18 +00:00
|
|
|
set(OPENMPT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/inc)
|
2019-01-02 08:27:24 +00:00
|
|
|
if(${SRB2_SYSTEM_BITS} EQUAL 64)
|
2019-01-04 02:17:18 +00:00
|
|
|
set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86_64/mingw -lopenmpt")
|
2019-01-02 08:27:24 +00:00
|
|
|
else() # 32-bit
|
2019-01-04 02:17:18 +00:00
|
|
|
set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86/mingw -lopenmpt")
|
2019-01-02 08:27:24 +00:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
find_package(OPENMPT)
|
|
|
|
endif()
|
|
|
|
if(${OPENMPT_FOUND})
|
|
|
|
set(SRB2_HAVE_OPENMPT ON)
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_OPENMPT)
|
2019-01-02 08:27:24 +00:00
|
|
|
else()
|
|
|
|
message(WARNING "You have specified that OpenMPT is available but it was not found.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-06-07 02:05:25 +00:00
|
|
|
if(${SRB2_CONFIG_HAVE_MIXERX})
|
|
|
|
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
|
|
|
|
set(MIXERX_FOUND ON)
|
|
|
|
set(MIXERX_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/SDLMixerX/i686-w64-mingw32/include/SDL2)
|
|
|
|
if(${SRB2_SYSTEM_BITS} EQUAL 64)
|
|
|
|
set(MIXERX_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDLMixerX/x86_64-w64-mingw32/lib -lSDL2_mixer_ext")
|
|
|
|
else() # 32-bit
|
|
|
|
set(MIXERX_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDLMixerX/i686-w64-mingw32/lib -lSDL2_mixer_ext")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
# No support for non-Windows (yet?)
|
|
|
|
#find_package(MIXERX)
|
|
|
|
message(WARNING "SDL Mixer X is not supported as an external library.")
|
|
|
|
set(MIXERX_FOUND OFF)
|
|
|
|
endif()
|
|
|
|
if(${MIXERX_FOUND})
|
|
|
|
set(SRB2_HAVE_MIXERX ON)
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXERX)
|
2020-06-07 02:05:25 +00:00
|
|
|
else()
|
|
|
|
message(WARNING "You have specified that SDL Mixer X is available but it was not found.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
if(${SRB2_CONFIG_HAVE_ZLIB})
|
2016-09-25 19:33:07 +00:00
|
|
|
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
|
|
|
|
set(ZLIB_FOUND ON)
|
|
|
|
set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/zlib)
|
2016-09-26 20:58:25 +00:00
|
|
|
if(${SRB2_SYSTEM_BITS} EQUAL 64)
|
|
|
|
set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz64")
|
|
|
|
else() # 32-bit
|
|
|
|
set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz32")
|
|
|
|
endif()
|
2016-09-25 19:33:07 +00:00
|
|
|
else()
|
|
|
|
find_package(ZLIB)
|
|
|
|
endif()
|
2015-01-28 05:46:39 +00:00
|
|
|
if(${ZLIB_FOUND})
|
|
|
|
set(SRB2_HAVE_ZLIB ON)
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_ZLIB)
|
2015-01-28 05:46:39 +00:00
|
|
|
else()
|
|
|
|
message(WARNING "You have specified that ZLIB is available but it was not found. SRB2 may not compile correctly.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB})
|
|
|
|
if (${ZLIB_FOUND})
|
2016-09-25 19:33:07 +00:00
|
|
|
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
|
|
|
|
set(PNG_FOUND ON)
|
|
|
|
set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libpng-src)
|
2016-09-26 20:58:25 +00:00
|
|
|
if(${SRB2_SYSTEM_BITS} EQUAL 64)
|
|
|
|
set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng64")
|
|
|
|
else() # 32-bit
|
|
|
|
set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng32")
|
|
|
|
endif()
|
2016-09-25 19:33:07 +00:00
|
|
|
else()
|
|
|
|
find_package(PNG)
|
|
|
|
endif()
|
2015-01-28 05:46:39 +00:00
|
|
|
if(${PNG_FOUND})
|
|
|
|
set(SRB2_HAVE_PNG ON)
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_PNG)
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -D_LARGEFILE64_SOURCE)
|
|
|
|
target_sources(SRB2SDL2 PRIVATE apng.c)
|
2015-01-28 05:46:39 +00:00
|
|
|
else()
|
|
|
|
message(WARNING "You have specified that PNG is available but it was not found. SRB2 may not compile correctly.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-04-07 05:48:43 +00:00
|
|
|
if(${SRB2_CONFIG_HAVE_CURL})
|
|
|
|
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
|
|
|
|
set(CURL_FOUND ON)
|
2020-10-31 03:37:34 +00:00
|
|
|
set(CURL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/curl/include)
|
2020-04-07 05:48:43 +00:00
|
|
|
if(${SRB2_SYSTEM_BITS} EQUAL 64)
|
|
|
|
set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib64 -lcurl")
|
2020-04-12 21:56:12 +00:00
|
|
|
else() # 32-bit
|
|
|
|
set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib32 -lcurl")
|
2020-04-07 05:48:43 +00:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
find_package(CURL)
|
|
|
|
endif()
|
|
|
|
if(${CURL_FOUND})
|
|
|
|
set(SRB2_HAVE_CURL ON)
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_CURL)
|
2020-04-07 05:48:43 +00:00
|
|
|
else()
|
2020-05-15 19:57:31 +00:00
|
|
|
message(WARNING "You have specified that CURL is available but it was not found. SRB2 may not compile correctly.")
|
2020-04-07 05:48:43 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-10-20 20:58:34 +00:00
|
|
|
if(${SRB2_CONFIG_HAVE_THREADS})
|
|
|
|
set(SRB2_HAVE_THREADS ON)
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS)
|
2020-10-20 20:58:34 +00:00
|
|
|
endif()
|
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
if(${SRB2_CONFIG_HWRENDER})
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER)
|
|
|
|
add_subdirectory(hardware)
|
2015-01-28 07:20:43 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL})
|
2015-01-28 05:46:39 +00:00
|
|
|
find_package(OpenGL)
|
|
|
|
if(${OPENGL_FOUND})
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER)
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DSTATIC_OPENGL)
|
2015-01-28 05:46:39 +00:00
|
|
|
else()
|
2015-01-28 07:20:43 +00:00
|
|
|
message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.")
|
2015-01-28 05:46:39 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${SRB2_CONFIG_USEASM})
|
2017-01-11 01:16:48 +00:00
|
|
|
#SRB2_ASM_FLAGS can be used to pass flags to either nasm or yasm.
|
|
|
|
if(${CMAKE_SYSTEM} MATCHES "Linux")
|
|
|
|
set(SRB2_ASM_FLAGS "-DLINUX ${SRB2_ASM_FLAGS}")
|
|
|
|
endif()
|
|
|
|
|
2015-02-02 03:25:02 +00:00
|
|
|
if(${SRB2_CONFIG_YASM})
|
|
|
|
set(CMAKE_ASM_YASM_SOURCE_FILE_EXTENSIONS ${CMAKE_ASM_YASM_SOURCE_FILE_EXTENSIONS} nas)
|
2017-01-11 19:52:14 +00:00
|
|
|
set(CMAKE_ASM_YASM_FLAGS "${SRB2_ASM_FLAGS}" CACHE STRING "Flags used by the assembler during all build types.")
|
2015-02-02 03:25:02 +00:00
|
|
|
enable_language(ASM_YASM)
|
|
|
|
else()
|
|
|
|
set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS ${CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS} nas)
|
2017-01-11 19:52:14 +00:00
|
|
|
set(CMAKE_ASM_NASM_FLAGS "${SRB2_ASM_FLAGS}" CACHE STRING "Flags used by the assembler during all build types.")
|
2015-02-02 03:25:02 +00:00
|
|
|
enable_language(ASM_NASM)
|
|
|
|
endif()
|
2021-05-08 01:57:46 +00:00
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
set(SRB2_USEASM ON)
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DUSEASM)
|
2020-10-31 16:04:44 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3 -mfpmath=sse")
|
2021-05-08 01:57:46 +00:00
|
|
|
|
|
|
|
target_sources(SRB2SDL2 PRIVATE ${SRB2_ASM_SOURCES}
|
|
|
|
${SRB2_NASM_SOURCES})
|
2015-01-28 05:46:39 +00:00
|
|
|
else()
|
|
|
|
set(SRB2_USEASM OFF)
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DNONX86 -DNORUSEASM)
|
2015-01-28 05:46:39 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Targets
|
|
|
|
|
2020-06-08 00:41:43 +00:00
|
|
|
# If using CCACHE, then force it.
|
|
|
|
# https://github.com/Cockatrice/Cockatrice/pull/3052/files
|
|
|
|
if (${CMAKE_SYSTEM} MATCHES "Darwin")
|
|
|
|
get_property(RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
|
|
|
|
if(RULE_LAUNCH_COMPILE)
|
|
|
|
MESSAGE(STATUS "Force enabling CCache usage under macOS")
|
|
|
|
# Set up wrapper scripts
|
2020-06-10 19:07:41 +00:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/launch-c.in ${CMAKE_BINARY_DIR}/launch-c)
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/launch-cxx.in ${CMAKE_BINARY_DIR}/launch-cxx)
|
2020-06-08 00:41:43 +00:00
|
|
|
execute_process(COMMAND chmod a+rx
|
|
|
|
"${CMAKE_BINARY_DIR}/launch-c"
|
|
|
|
"${CMAKE_BINARY_DIR}/launch-cxx")
|
|
|
|
|
|
|
|
# Set Xcode project attributes to route compilation through our scripts
|
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c")
|
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx")
|
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c")
|
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
# Compatibility flag with later versions of GCC
|
|
|
|
# We should really fix our code to not need this
|
2016-02-06 02:49:24 +00:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
2015-02-02 03:25:02 +00:00
|
|
|
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields)
|
2015-01-28 06:58:30 +00:00
|
|
|
endif()
|
2015-01-28 05:46:39 +00:00
|
|
|
|
2016-02-06 03:38:40 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value)
|
|
|
|
endif()
|
|
|
|
|
2021-05-08 23:48:40 +00:00
|
|
|
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-trigraphs)
|
|
|
|
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DCMAKECONFIG)
|
2015-01-29 00:03:41 +00:00
|
|
|
|
2015-03-25 00:32:58 +00:00
|
|
|
#add_library(SRB2Core STATIC
|
|
|
|
# ${SRB2_CORE_SOURCES}
|
|
|
|
# ${SRB2_CORE_HEADERS}
|
|
|
|
# ${SRB2_CORE_RENDER_SOURCES}
|
|
|
|
# ${SRB2_CORE_GAME_SOURCES}
|
|
|
|
# ${SRB2_LUA_SOURCES}
|
|
|
|
# ${SRB2_LUA_HEADERS}
|
|
|
|
# ${SRB2_BLUA_SOURCES}
|
|
|
|
# ${SRB2_BLUA_HEADERS}
|
|
|
|
#)
|
2015-03-08 08:26:54 +00:00
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
add_subdirectory(sdl)
|
2015-03-08 08:26:54 +00:00
|
|
|
|
2019-12-15 06:47:58 +00:00
|
|
|
if(NOT ${SRB2_SDL2_AVAILABLE})
|
2015-03-08 08:26:54 +00:00
|
|
|
message(FATAL_ERROR "There are no targets available to build an SRB2 executable. :(")
|
2016-02-06 02:49:24 +00:00
|
|
|
endif()
|