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

View file

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