2021-05-08 01:57:46 +00:00
|
|
|
add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32)
|
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" AND NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}")
|
|
|
|
# On MinGW with internal libraries, link the standard library statically
|
|
|
|
target_link_options(SRB2SDL2 PRIVATE "-static")
|
|
|
|
endif()
|
|
|
|
|
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_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.")
|
2022-11-05 03:11:36 +00:00
|
|
|
set(SRB2_CONFIG_DEV_BUILD OFF CACHE BOOL
|
|
|
|
"Compile a development build of SRB2.")
|
2015-01-28 05:46:39 +00:00
|
|
|
|
2021-05-05 10:56:57 +00:00
|
|
|
add_subdirectory(blua)
|
2015-01-28 05:46:39 +00:00
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
# OS macros
|
|
|
|
if (UNIX)
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DUNIXCOMMON)
|
2015-01-28 05:46:39 +00:00
|
|
|
endif()
|
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
|
|
|
find_program(OBJCOPY objcopy)
|
2019-01-02 08:27:24 +00:00
|
|
|
endif()
|
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DLINUX)
|
|
|
|
if(${SRB2_SYSTEM_BITS} EQUAL 64)
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DLINUX64)
|
2020-06-07 02:05:25 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DMACOSX)
|
2015-01-28 05:46:39 +00:00
|
|
|
endif()
|
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
target_link_libraries(SRB2SDL2 PRIVATE gme)
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_GME)
|
|
|
|
if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}")
|
|
|
|
# this sucks but gme doesn't use modern cmake to delineate public headers
|
|
|
|
target_include_directories(SRB2SDL2 PRIVATE "${libgme_SOURCE_DIR}")
|
2015-01-28 05:46:39 +00:00
|
|
|
endif()
|
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
target_link_libraries(SRB2SDL2 PRIVATE openmpt)
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_OPENMPT)
|
2020-04-07 05:48:43 +00:00
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
target_link_libraries(SRB2SDL2 PRIVATE ZLIB::ZLIB PNG::PNG CURL::libcurl)
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_ZLIB -DHAVE_PNG -DHAVE_CURL -D_LARGEFILE64_SOURCE)
|
|
|
|
target_sources(SRB2SDL2 PRIVATE apng.c)
|
|
|
|
|
|
|
|
set(SRB2_HAVE_THREADS ON)
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS)
|
2020-10-20 20:58:34 +00:00
|
|
|
|
2022-11-05 05:14:32 +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
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
if("${SRB2_CONFIG_STATIC_OPENGL}")
|
|
|
|
find_package(OpenGL)
|
|
|
|
if(${OPENGL_FOUND})
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DSTATIC_OPENGL)
|
|
|
|
else()
|
|
|
|
message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.")
|
|
|
|
endif()
|
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.
|
2022-11-05 05:14:32 +00:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
2017-01-11 01:16:48 +00:00
|
|
|
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)
|
2022-11-05 05:14:32 +00:00
|
|
|
target_compile_options(SRB2SDL2 PRIVATE -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
|
2022-11-05 05:14:32 +00:00
|
|
|
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
|
2020-06-08 00:41:43 +00:00
|
|
|
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")
|
2022-11-05 05:14:32 +00:00
|
|
|
target_compile_options(SRB2SDL2 PRIVATE -mno-ms-bitfields)
|
|
|
|
target_compile_options(SRB2SDL2 PRIVATE -Wno-trigraphs)
|
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")
|
2022-11-05 05:14:32 +00:00
|
|
|
target_compile_options(SRB2SDL2 PRIVATE -Wno-absolute-value)
|
2016-02-06 03:38:40 +00:00
|
|
|
endif()
|
|
|
|
|
2022-11-05 03:11:36 +00:00
|
|
|
if(${SRB2_CONFIG_DEV_BUILD})
|
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DDEVELOP)
|
|
|
|
endif()
|
2021-05-05 10:56:57 +00:00
|
|
|
target_compile_definitions(SRB2SDL2 PRIVATE -DCMAKECONFIG)
|
2015-01-29 00:03:41 +00:00
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
add_subdirectory(sdl)
|
2015-03-08 08:26:54 +00:00
|
|
|
|
2022-11-05 05:14:32 +00:00
|
|
|
# strip debug symbols into separate file when using gcc.
|
|
|
|
# to be consistent with Makefile, don't generate for OS X.
|
|
|
|
if((CMAKE_COMPILER_IS_GNUCC) AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin))
|
|
|
|
if((${CMAKE_BUILD_TYPE} MATCHES Debug) OR (${CMAKE_BUILD_TYPE} MATCHES RelWithDebInfo))
|
|
|
|
if(${CMAKE_BUILD_TYPE} MATCHES Debug)
|
|
|
|
set(OBJCOPY_ONLY_KEEP_DEBUG "--only-keep-debug")
|
|
|
|
endif()
|
|
|
|
message(STATUS "Will make separate debug symbols in *.debug")
|
|
|
|
add_custom_command(TARGET SRB2SDL2 POST_BUILD
|
|
|
|
COMMAND ${OBJCOPY} ${OBJCOPY_ONLY_KEEP_DEBUG} $<TARGET_FILE:SRB2SDL2> $<TARGET_FILE:SRB2SDL2>.debug
|
|
|
|
COMMAND ${OBJCOPY} --strip-debug $<TARGET_FILE:SRB2SDL2>
|
|
|
|
COMMAND ${OBJCOPY} --add-gnu-debuglink=$<TARGET_FILE:SRB2SDL2>.debug $<TARGET_FILE:SRB2SDL2>
|
|
|
|
)
|
|
|
|
endif()
|
2016-02-06 02:49:24 +00:00
|
|
|
endif()
|