1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-12-23 03:30:00 +00:00

Port cmake improvements to miami

This commit is contained in:
Filip Gawin 2021-01-13 12:45:10 +01:00
parent 1b55a9956f
commit 4741afd2cf
5 changed files with 237 additions and 181 deletions

View file

@ -1,44 +1,82 @@
cmake_minimum_required(VERSION 3.8) cmake_minimum_required(VERSION 3.8)
project(reVC C CXX) set(EXECUTABLE reVC)
set(PROJECT REVC)
project(${EXECUTABLE} C CXX)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
if(WIN32) if(WIN32)
set(REVC_AUDIOS "NULL" "OAL" "MSS") set(${PROJECT}_AUDIOS "OAL" "MSS")
else() else()
set(REVC_AUDIOS "NULL" "OAL") set(${PROJECT}_AUDIOS "OAL")
endif() endif()
set(REVC_AUDIO "OAL" CACHE STRING "Audio") set(${PROJECT}_AUDIO "OAL" CACHE STRING "Audio")
set_property(CACHE REVC_AUDIO PROPERTY STRINGS ${REVC_AUDIOS}) option(${PROJECT}_WITH_OPUS "Build ${EXECUTABLE} with opus support" OFF)
message(STATUS "REVC_AUDIO = ${REVC_AUDIO} (choices=${REVC_AUDIOS})") option(${PROJECT}_WITH_LIBSNDFILE "Build ${EXECUTABLE} with libsndfile (instead of internal decoder)" OFF)
set("REVC_AUDIO_${REVC_AUDIO}" ON)
if(NOT REVC_AUDIO IN_LIST REVC_AUDIOS) set_property(CACHE ${PROJECT}_AUDIO PROPERTY STRINGS ${${PROJECT}_AUDIOS})
message(FATAL_ERROR "Illegal REVC_AUDIO=${REVC_AUDIO}") message(STATUS "${PROJECT}_AUDIO = ${${PROJECT}_AUDIO} (choices=${${PROJECT}_AUDIOS})")
set("${PROJECT}_AUDIO_${${PROJECT}_AUDIO}" ON)
if(NOT ${PROJECT}_AUDIO IN_LIST ${PROJECT}_AUDIOS)
message(FATAL_ERROR "Illegal ${PROJECT}_AUDIO=${${PROJECT}_AUDIO}")
endif() endif()
if(REVC_INSTALL) option(${PROJECT}_VENDORED_LIBRW "Use vendored librw" ON)
include(GNUInstallDirs) if(${PROJECT}_VENDORED_LIBRW)
set(REVC_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/reVC") add_subdirectory(vendor/librw)
else()
find_package(librw REQUIRED)
endif() endif()
add_subdirectory("vendor/librw")
add_subdirectory(src) add_subdirectory(src)
if(REVC_INSTALL) if(${PROJECT}_INSTALL)
include(CMakePackageConfigHelpers) install(DIRECTORY gamefiles/ DESTINATION ".")
configure_package_config_file(reVC-config.cmake.in reVC-config.cmake if(LIBRW_PLATFORM_NULL)
INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}" set(platform "-null")
) elseif(LIBRW_PLATFORM_PS2)
install( set(platform "-ps2")
FILES "${CMAKE_CURRENT_BINARY_DIR}/reVC-config.cmake" elseif(LIBRW_PLATFORM_GL3)
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
) set(platform "-gl3-glfw")
install( else()
EXPORT reVC-targets set(platform "-gl3-sdl2")
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" endif()
) elseif(LIBRW_PLATFORM_D3D9)
set(platform "-d3d9")
endif()
if(${PROJECT}_AUDIO_OAL)
set(audio "-oal")
elseif(${PROJECT}_AUDIO_MSS)
set(audio "-mss")
endif()
if(${PROJECT}_WITH_OPUS)
set(audio "${audio}-opus")
endif()
if(NOT LIBRW_PLATFORM_PS2)
if(WIN32)
set(os "-win")
elseif(APPLE)
set(os "-apple")
elseif(UNIX)
set(os "-linux")
else()
set(compiler "-UNK")
message(WARNING "Unknown os. Created cpack package will be wrong. (override using cpack -P)")
endif()
endif()
include(CMakeCPack.cmake) set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${platform}${audio}${os}${compiler}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "GTA III reversed")
set(CPACK_PACKAGE_VENDOR "GTAModding")
# FIXME: missing license (https://github.com/GTAmodding/re3/issues/794)
# set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/LICENSE")
# set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_GENERATOR "TXZ")
include(CPack)
endif() endif()

View file

@ -1,28 +0,0 @@
# - Find mpg123
# Find the native mpg123 includes and library
#
# MPG123_INCLUDE_DIR - where to find mpg123.h
# MPG123_LIBRARIES - List of libraries when using mpg123.
# MPG123_FOUND - True if mpg123 found.
IF(MPG123_INCLUDE_DIR AND MPG123_LIBRARIES)
# Already in cache, be silent
SET(MPG123_FIND_QUIETLY TRUE)
ENDIF(MPG123_INCLUDE_DIR AND MPG123_LIBRARIES)
FIND_PATH(MPG123_INCLUDE_DIR mpg123.h
PATHS "${MPG123_DIR}"
PATH_SUFFIXES include
)
FIND_LIBRARY(MPG123_LIBRARIES NAMES mpg123 mpg123-0
PATHS "${MPG123_DIR}"
PATH_SUFFIXES lib
)
# MARK_AS_ADVANCED(MPG123_LIBRARIES MPG123_INCLUDE_DIR)
# handle the QUIETLY and REQUIRED arguments and set MPG123_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MPG123 DEFAULT_MSG MPG123_LIBRARIES MPG123_INCLUDE_DIR)

View file

@ -7,6 +7,8 @@
# SNDFILE_FOUND - system has libsndfile # SNDFILE_FOUND - system has libsndfile
# SNDFILE_INCLUDE_DIRS - the libsndfile include directory # SNDFILE_INCLUDE_DIRS - the libsndfile include directory
# SNDFILE_LIBRARIES - Link these to use libsndfile # SNDFILE_LIBRARIES - Link these to use libsndfile
# SNDFILE_CFLAGS - Compile options to use libsndfile
# SndFile::SndFile - Imported library of libsndfile
# #
# Copyright (C) 2006 Wengo # Copyright (C) 2006 Wengo
# #
@ -15,14 +17,16 @@
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
# #
if (SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS) find_package(PkgConfig QUIET)
# in cache already if(PKG_CONFIG_FOUND)
set(SNDFILE_FOUND TRUE) pkg_search_module(PKG_SNDFILE "sndfile")
else (SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS) endif()
find_path(SNDFILE_INCLUDE_DIR find_path(SNDFILE_INCLUDE_DIR
NAMES NAMES
sndfile.h sndfile.h
HINTS
${PKG_SNDFILE_INCLUDE_DIRS}
PATHS PATHS
/usr/include /usr/include
/usr/local/include /usr/local/include
@ -30,38 +34,34 @@ else (SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS)
/sw/include /sw/include
) )
find_library(SNDFILE_LIBRARY find_library(SNDFILE_LIBRARY
NAMES NAMES
sndfile sndfile
HINTS
${PKG_SNDFILE_LIBRARIES}
PATHS PATHS
/usr/lib /usr/lib
/usr/local/lib /usr/local/lib
/opt/local/lib /opt/local/lib
/sw/lib /sw/lib
) )
set(SNDFILE_INCLUDE_DIRS set(SNDFILE_CFLAGS "${PKG_SNDFILE_CFLAGS_OTHER}" CACHE STRING "CFLAGS of libsndfile")
${SNDFILE_INCLUDE_DIR}
)
set(SNDFILE_LIBRARIES
${SNDFILE_LIBRARY}
)
if (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES) set(SNDFILE_INCLUDE_DIRS "${SNDFILE_INCLUDE_DIR}")
set(SNDFILE_LIBRARIES "${SNDFILE_LIBRARY}")
if(SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES)
set(SNDFILE_FOUND TRUE) set(SNDFILE_FOUND TRUE)
endif (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES) endif()
if (SNDFILE_FOUND) include(FindPackageHandleStandardArgs)
if (NOT SndFile_FIND_QUIETLY) find_package_handle_standard_args(SndFile DEFAULT_MSG SNDFILE_INCLUDE_DIRS SNDFILE_LIBRARIES)
message(STATUS "Found libsndfile: ${SNDFILE_LIBRARIES}")
endif (NOT SndFile_FIND_QUIETLY)
else (SNDFILE_FOUND)
if (SndFile_FIND_REQUIRED)
message(FATAL_ERROR "Could not find libsndfile")
endif (SndFile_FIND_REQUIRED)
endif (SNDFILE_FOUND)
# show the SNDFILE_INCLUDE_DIRS and SNDFILE_LIBRARIES variables only in the advanced view if(NOT TARGET SndFile::SndFile)
mark_as_advanced(SNDFILE_INCLUDE_DIRS SNDFILE_LIBRARIES) add_library(__SndFile INTERFACE)
target_compile_options(__SndFile INTERFACE ${SNDFILE_CFLAGS})
endif (SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS) target_include_directories(__SndFile INTERFACE ${SNDFILE_INCLUDE_DIRS})
target_link_libraries(__SndFile INTERFACE ${SNDFILE_LIBRARIES})
add_library(SndFile::SndFile ALIAS __SndFile)
endif()

38
cmake/Findmpg123.cmake Normal file
View file

@ -0,0 +1,38 @@
# - Find mpg123
# Find the native mpg123 includes and library
#
# mpg123_INCLUDE_DIR - Where to find mpg123.h
# mpg123_LIBRARIES - List of libraries when using mpg123.
# mpg123_CFLAGS - Compile options to use mpg123
# mpg123_FOUND - True if mpg123 found.
# MPG123::libmpg123 - Imported library of libmpg123
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_search_module(PKG_MPG123 mpg123)
endif()
find_path(mpg123_INCLUDE_DIR mpg123.h
HINTS ${PKG_MPG123_INCLUDE_DIRS}
PATHS "${mpg123_DIR}"
PATH_SUFFIXES include
)
find_library(mpg123_LIBRARIES NAMES mpg123 mpg123-0
HINTS ${PKG_MPG123_LIBRARIES}
PATHS "${mpg123_DIR}"
PATH_SUFFIXES lib
)
set(mpg123_CFLAGS "${PKG_MPG123_CFLAGS_OTHER}" CACHE STRING "CFLAGS of mpg123")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(mpg123 DEFAULT_MSG mpg123_LIBRARIES mpg123_INCLUDE_DIR)
if(NOT TARGET MPG123::libmpg123)
add_library(__libmpg123 INTERFACE)
target_compile_options(__libmpg123 INTERFACE ${mpg123_CFLAGS})
target_include_directories(__libmpg123 INTERFACE ${mpg123_INCLUDE_DIR})
target_link_libraries(__libmpg123 INTERFACE ${mpg123_LIBRARIES})
add_library(MPG123::libmpg123 ALIAS __libmpg123)
endif()

View file

@ -1,92 +1,105 @@
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
if(${REVC_AUDIO} STREQUAL "OAL") file(GLOB_RECURSE ${PROJECT}_SOURCES "*.cpp" "*.h" "*.rc")
find_package(OpenAL REQUIRED)
find_package(MPG123 REQUIRED)
find_package(SndFile REQUIRED)
endif()
file(GLOB_RECURSE Sources "*.cpp" "*.h") function(header_directories RETURN_LIST)
file(GLOB_RECURSE ALL_SRCS *.h *.cpp *.c)
set(RELDIRS)
foreach(SRC ${ALL_SRCS})
file(RELATIVE_PATH RELSRC "${CMAKE_CURRENT_SOURCE_DIR}" "${SRC}")
get_filename_component(RELDIR "${RELSRC}" DIRECTORY)
list(APPEND RELDIRS ${RELDIR})
endforeach()
list(REMOVE_DUPLICATES RELDIRS)
set(${RETURN_LIST} ${RELDIRS} PARENT_SCOPE)
endfunction()
MACRO(HEADER_DIRECTORIES return_list) header_directories(${PROJECT}_INCLUDES)
FILE(GLOB_RECURSE new_list *.cpp)
SET(dir_list "animation"
"audio"
"collision"
"control"
"core"
"entities"
"extras"
"fakerw"
"math"
"modelinfo"
"objects"
"peds"
"render"
"rw"
"save"
"skel"
"text"
"vehicles"
"weapons")
FOREACH(file_path ${new_list})
GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
SET(dir_list ${dir_list} ${dir_path})
ENDFOREACH()
LIST(REMOVE_DUPLICATES dir_list)
SET(${return_list} ${dir_list})
ENDMACRO()
HEADER_DIRECTORIES(header_list) add_executable(${EXECUTABLE} WIN32
include_directories(${header_list}) ${${PROJECT}_SOURCES}
)
target_link_libraries(${EXECUTABLE} PRIVATE
librw::librw
Threads::Threads
)
add_executable(reVC ${Sources}) target_include_directories(${EXECUTABLE}
target_link_libraries(reVC librw)
target_link_libraries(reVC Threads::Threads)
if(${REVC_AUDIO} STREQUAL "OAL")
target_link_libraries(reVC ${OPENAL_LIBRARY})
target_link_libraries(reVC ${MPG123_LIBRARIES})
target_link_libraries(reVC ${SNDFILE_LIBRARIES})
endif()
target_include_directories(reVC
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
)
target_compile_definitions(reVC
PRIVATE PRIVATE
"$<IF:$<CONFIG:DEBUG>,DEBUG,NDEBUG>" $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
PUBLIC $<BUILD_INTERFACE:${${PROJECT}_INCLUDES}>
"RW_${REVC_PLATFORM}" )
)
target_compile_definitions(reVC PRIVATE LIBRW=1 AUDIO_OAL=1) target_compile_definitions(${EXECUTABLE}
PRIVATE
$<IF:$<CONFIG:DEBUG>,DEBUG,NDEBUG>
LIBRW
${PROJECT}_NO_AUTOLINK
)
if(LIBRW_PLATFORM_D3D9)
target_compile_definitions(${EXECUTABLE}
PUBLIC
USE_D3D9
)
endif()
if(${PROJECT}_AUDIO STREQUAL "OAL")
find_package(OpenAL REQUIRED)
target_include_directories(${EXECUTABLE} PRIVATE ${OPENAL_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE} PRIVATE ${OPENAL_LIBRARY})
target_compile_definitions(${EXECUTABLE} PRIVATE ${OPENAL_DEFINITIONS})
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_OAL)
elseif(${PROJECT}_AUDIO STREQUAL "MSS")
find_package(MilesSDK REQUIRED)
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_MSS)
target_link_libraries(${EXECUTABLE} PRIVATE MilesSDK::MilesSDK)
endif()
find_package(mpg123 REQUIRED)
target_link_libraries(${EXECUTABLE} PRIVATE
MPG123::libmpg123
)
if(${PROJECT}_WITH_OPUS)
find_package(opusfile REQUIRED)
target_link_libraries(${EXECUTABLE} PRIVATE
opusfile::opusfile
)
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_OPUS)
endif()
if(${PROJECT}_WITH_LIBSNDFILE)
find_package(SndFile REQUIRED)
target_link_libraries(${EXECUTABLE} PRIVATE
SndFile::SndFile
)
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_OAL_USE_SNDFILE)
endif()
target_compile_definitions(${EXECUTABLE} PRIVATE )
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_compile_options(reVC target_compile_options(${EXECUTABLE}
PRIVATE PRIVATE
"-Wall" "-Wall"
) )
if (NOT REVC_PLATFORM_PS2) if (NOT LIBRW_PLATFORM_PS2)
target_compile_options(reVC target_compile_options(${EXECUTABLE}
PRIVATE PRIVATE
"-Wextra" -Wextra
"-Wdouble-promotion" -Wdouble-promotion
"-Wpedantic" -Wpedantic
) )
endif() endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(reVC target_compile_options(${EXECUTABLE}
PUBLIC PUBLIC
/wd4996 /wd4244 /Zc:sizedDealloc-
) )
endif() endif()
set_target_properties(reVC set_target_properties(${EXECUTABLE}
PROPERTIES PROPERTIES
C_STANDARD 11 C_STANDARD 11
C_EXTENSIONS OFF C_EXTENSIONS OFF
@ -94,20 +107,15 @@ set_target_properties(reVC
CXX_STANDARD 11 CXX_STANDARD 11
CXX_EXTENSIONS OFF CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
PREFIX "" )
)
if(REVC_INSTALL)
target_include_directories(reVC
INTERFACE
$<INSTALL_INTERFACE:${REVC_INSTALL_INCLUDEDIR}>
)
if(${PROJECT}_INSTALL)
install( install(
TARGETS reVC TARGETS ${EXECUTABLE}
EXPORT reVC-targets EXPORT ${EXECUTABLE}-targets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" RUNTIME DESTINATION "."
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
) )
if(MSVC)
install(FILES $<TARGET_PDB_FILE:${EXECUTABLE}> DESTINATION "." OPTIONAL)
endif()
endif() endif()