From 4097c20bdd66d03e0be454f1834e2d1bd4c54443 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Wed, 13 Jan 2021 12:15:22 +0100 Subject: Make cmake files more generic --- CMakeLists.txt | 37 +++++++++++++++-------------- src/CMakeLists.txt | 68 +++++++++++++++++++++++++++--------------------------- 2 files changed, 54 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df31a704..ae6395c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f663061..dc204d17 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 $ - $ + $ ) -target_compile_definitions(re3 +target_compile_definitions(${EXECUTABLE} PRIVATE $,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 $ DESTINATION "." OPTIONAL) + install(FILES $ DESTINATION "." OPTIONAL) endif() endif() -- cgit v1.2.3