1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-12-22 13:20:01 +00:00

Make cmake files more generic

This commit is contained in:
Filip Gawin 2021-01-13 12:15:22 +01:00
parent fb1bd1a5bd
commit 4097c20bdd
2 changed files with 54 additions and 51 deletions

View file

@ -1,35 +1,38 @@
cmake_minimum_required(VERSION 3.8)
project(re3 C CXX)
set(EXECUTABLE re3)
set(PROJECT RE3)
project(${EXECUTABLE} C CXX)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
if(WIN32)
set(RE3_AUDIOS "OAL" "MSS")
set(${PROJECT}_AUDIOS "OAL" "MSS")
else()
set(RE3_AUDIOS "OAL")
set(${PROJECT}_AUDIOS "OAL")
endif()
set(RE3_AUDIO "OAL" CACHE STRING "Audio")
set(${PROJECT}_AUDIO "OAL" CACHE STRING "Audio")
option(RE3_WITH_OPUS "Build re3 with opus support" OFF)
option(RE3_WITH_LIBSNDFILE "Build re3 with libsndfile (instead of internal decoder)" OFF)
option(${PROJECT}_WITH_OPUS "Build ${EXECUTABLE} with opus support" OFF)
option(${PROJECT}_WITH_LIBSNDFILE "Build ${EXECUTABLE} with libsndfile (instead of internal decoder)" OFF)
set_property(CACHE RE3_AUDIO PROPERTY STRINGS ${RE3_AUDIOS})
message(STATUS "RE3_AUDIO = ${RE3_AUDIO} (choices=${RE3_AUDIOS})")
set("RE3_AUDIO_${RE3_AUDIO}" ON)
if(NOT RE3_AUDIO IN_LIST RE3_AUDIOS)
message(FATAL_ERROR "Illegal RE3_AUDIO=${RE3_AUDIO}")
set_property(CACHE ${PROJECT}_AUDIO PROPERTY STRINGS ${${PROJECT}_AUDIOS})
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()
option(RE3_VENDORED_LIBRW "Use vendored librw" ON)
if(RE3_VENDORED_LIBRW)
option(${PROJECT}_VENDORED_LIBRW "Use vendored librw" ON)
if(${PROJECT}_VENDORED_LIBRW)
add_subdirectory(vendor/librw)
else()
find_package(librw REQUIRED)
endif()
add_subdirectory(src)
if(RE3_INSTALL)
if(${PROJECT}_INSTALL)
install(DIRECTORY gamefiles/ DESTINATION ".")
if(LIBRW_PLATFORM_NULL)
set(platform "-null")
@ -44,12 +47,12 @@ if(RE3_INSTALL)
elseif(LIBRW_PLATFORM_D3D9)
set(platform "-d3d9")
endif()
if(RE3_AUDIO_OAL)
if(${PROJECT}_AUDIO_OAL)
set(audio "-oal")
elseif(RE3_AUDIO_MSS)
elseif(${PROJECT}_AUDIO_MSS)
set(audio "-mss")
endif()
if(RE3_WITH_OPUS)
if(${PROJECT}_WITH_OPUS)
set(audio "${audio}-opus")
endif()
if(NOT LIBRW_PLATFORM_PS2)

View file

@ -1,7 +1,7 @@
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
file(GLOB_RECURSE RE3_SOURCES "*.cpp" "*.h" "*.rc")
file(GLOB_RECURSE ${PROJECT}_SOURCES "*.cpp" "*.h" "*.rc")
function(header_directories RETURN_LIST)
file(GLOB_RECURSE ALL_SRCS *.h *.cpp *.c)
@ -15,77 +15,77 @@ function(header_directories RETURN_LIST)
set(${RETURN_LIST} ${RELDIRS} PARENT_SCOPE)
endfunction()
header_directories(RE3_INCLUDES)
header_directories(${PROJECT}_INCLUDES)
add_executable(re3 WIN32
${RE3_SOURCES}
add_executable(${EXECUTABLE} WIN32
${${PROJECT}_SOURCES}
)
target_link_libraries(re3 PRIVATE
target_link_libraries(${EXECUTABLE} PRIVATE
librw::librw
Threads::Threads
)
target_include_directories(re3
target_include_directories(${EXECUTABLE}
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${RE3_INCLUDES}>
$<BUILD_INTERFACE:${${PROJECT}_INCLUDES}>
)
target_compile_definitions(re3
target_compile_definitions(${EXECUTABLE}
PRIVATE
$<IF:$<CONFIG:DEBUG>,DEBUG,NDEBUG>
LIBRW
RE3_NO_AUTOLINK
${PROJECT}_NO_AUTOLINK
)
if(LIBRW_PLATFORM_D3D9)
target_compile_definitions(re3
target_compile_definitions(${EXECUTABLE}
PUBLIC
USE_D3D9
)
endif()
if(RE3_AUDIO STREQUAL "OAL")
if(${PROJECT}_AUDIO STREQUAL "OAL")
find_package(OpenAL REQUIRED)
target_include_directories(re3 PRIVATE ${OPENAL_INCLUDE_DIR})
target_link_libraries(re3 PRIVATE ${OPENAL_LIBRARY})
target_compile_definitions(re3 PRIVATE ${OPENAL_DEFINITIONS})
target_compile_definitions(re3 PRIVATE AUDIO_OAL)
elseif(RE3_AUDIO STREQUAL "MSS")
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(re3 PRIVATE AUDIO_MSS)
target_link_libraries(re3 PRIVATE MilesSDK::MilesSDK)
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_MSS)
target_link_libraries(${EXECUTABLE} PRIVATE MilesSDK::MilesSDK)
endif()
find_package(mpg123 REQUIRED)
target_link_libraries(re3 PRIVATE
target_link_libraries(${EXECUTABLE} PRIVATE
MPG123::libmpg123
)
if(RE3_WITH_OPUS)
if(${PROJECT}_WITH_OPUS)
find_package(opusfile REQUIRED)
target_link_libraries(re3 PRIVATE
target_link_libraries(${EXECUTABLE} PRIVATE
opusfile::opusfile
)
target_compile_definitions(re3 PRIVATE AUDIO_OPUS)
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_OPUS)
endif()
if(RE3_WITH_LIBSNDFILE)
if(${PROJECT}_WITH_LIBSNDFILE)
find_package(SndFile REQUIRED)
target_link_libraries(re3 PRIVATE
target_link_libraries(${EXECUTABLE} PRIVATE
SndFile::SndFile
)
target_compile_definitions(re3 PRIVATE AUDIO_OAL_USE_SNDFILE)
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_OAL_USE_SNDFILE)
endif()
target_compile_definitions(re3 PRIVATE )
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")
target_compile_options(re3
target_compile_options(${EXECUTABLE}
PRIVATE
"-Wall"
)
if (NOT LIBRW_PLATFORM_PS2)
target_compile_options(re3
target_compile_options(${EXECUTABLE}
PRIVATE
-Wextra
-Wdouble-promotion
@ -93,13 +93,13 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang
)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(re3
target_compile_options(${EXECUTABLE}
PUBLIC
/Zc:sizedDealloc-
)
endif()
set_target_properties(re3
set_target_properties(${EXECUTABLE}
PROPERTIES
C_STANDARD 11
C_EXTENSIONS OFF
@ -109,13 +109,13 @@ set_target_properties(re3
CXX_STANDARD_REQUIRED ON
)
if(RE3_INSTALL)
if(${PROJECT}_INSTALL)
install(
TARGETS re3
EXPORT re3-targets
TARGETS ${EXECUTABLE}
EXPORT ${EXECUTABLE}-targets
RUNTIME DESTINATION "."
)
if(MSVC)
install(FILES $<TARGET_PDB_FILE:re3> DESTINATION "." OPTIONAL)
install(FILES $<TARGET_PDB_FILE:${EXECUTABLE}> DESTINATION "." OPTIONAL)
endif()
endif()