1
0
Fork 0
mirror of https://github.com/halpz/re3.git synced 2024-12-22 17:35:29 +00:00
re3/src/CMakeLists.txt

175 lines
5.2 KiB
CMake
Raw Normal View History

2020-10-31 22:14:28 +00:00
find_package(Threads REQUIRED)
2021-02-12 01:04:31 +00:00
set(THREADS_PREFER_PTHREAD_FLAG ON)
2020-10-31 22:14:28 +00:00
2021-01-13 11:15:22 +00:00
file(GLOB_RECURSE ${PROJECT}_SOURCES "*.cpp" "*.h" "*.rc")
2020-10-31 22:14:28 +00:00
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()
2020-10-31 22:14:28 +00:00
2021-01-13 11:15:22 +00:00
header_directories(${PROJECT}_INCLUDES)
2020-10-31 22:14:28 +00:00
2021-02-12 01:04:31 +00:00
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/extras/GitSHA1.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/extras/GitSHA1.cpp" @ONLY)
list(APPEND ${PROJECT}_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/extras/GitSHA1.cpp")
2021-01-13 11:15:22 +00:00
add_executable(${EXECUTABLE} WIN32
${${PROJECT}_SOURCES}
)
2021-01-13 11:15:22 +00:00
target_link_libraries(${EXECUTABLE} PRIVATE
librw::librw
Threads::Threads
)
2020-10-31 22:14:28 +00:00
2021-01-13 11:15:22 +00:00
target_include_directories(${EXECUTABLE}
PRIVATE
2020-10-31 22:14:28 +00:00
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
2021-01-13 11:15:22 +00:00
$<BUILD_INTERFACE:${${PROJECT}_INCLUDES}>
)
2020-10-31 22:14:28 +00:00
2021-01-13 11:15:22 +00:00
target_compile_definitions(${EXECUTABLE}
2020-10-31 22:14:28 +00:00
PRIVATE
$<IF:$<CONFIG:DEBUG>,DEBUG,NDEBUG>
LIBRW
2021-07-11 01:34:43 +00:00
CMAKE_NO_AUTOLINK
)
2021-01-03 15:30:45 +00:00
if(LIBRW_PLATFORM_D3D9)
2021-01-13 11:15:22 +00:00
target_compile_definitions(${EXECUTABLE}
2021-01-03 15:30:45 +00:00
PUBLIC
USE_D3D9
)
endif()
2021-02-12 01:04:31 +00:00
target_compile_definitions(${EXECUTABLE} PRIVATE CMAKE_BUILD)
2021-06-08 01:10:02 +00:00
target_compile_definitions(${EXECUTABLE} PRIVATE USE_OUR_VERSIONING)
2021-02-12 01:04:31 +00:00
2021-01-13 11:15:22 +00:00
if(${PROJECT}_AUDIO STREQUAL "OAL")
find_package(OpenAL REQUIRED)
2021-01-13 11:15:22 +00:00
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")
2021-01-03 15:30:45 +00:00
find_package(MilesSDK REQUIRED)
2021-01-13 11:15:22 +00:00
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_MSS)
target_link_libraries(${EXECUTABLE} PRIVATE MilesSDK::MilesSDK)
endif()
find_package(mpg123 REQUIRED)
2021-01-13 11:15:22 +00:00
target_link_libraries(${EXECUTABLE} PRIVATE
MPG123::libmpg123
)
2021-01-13 11:15:22 +00:00
if(${PROJECT}_WITH_OPUS)
find_package(opusfile REQUIRED)
2021-01-13 11:15:22 +00:00
target_link_libraries(${EXECUTABLE} PRIVATE
opusfile::opusfile
)
2021-01-13 11:15:22 +00:00
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_OPUS)
endif()
2021-01-13 11:15:22 +00:00
if(${PROJECT}_WITH_LIBSNDFILE)
find_package(SndFile REQUIRED)
2021-01-13 11:15:22 +00:00
target_link_libraries(${EXECUTABLE} PRIVATE
SndFile::SndFile
2020-10-31 22:14:28 +00:00
)
2021-01-13 11:15:22 +00:00
target_compile_definitions(${EXECUTABLE} PRIVATE AUDIO_OAL_USE_SNDFILE)
endif()
2020-10-31 22:14:28 +00:00
2021-01-13 11:15:22 +00:00
target_compile_definitions(${EXECUTABLE} PRIVATE )
2020-10-31 22:14:28 +00:00
2021-01-24 20:34:53 +00:00
option(${PROJECT}_WITH_SANITIZERS "Use UB sanitizers (better crash log)" OFF)
option(${PROJECT}_WITH_ASAN "Use Address sanitizer (better crash log)" OFF)
if(${PROJECT}_WITH_SANITIZERS)
target_compile_options(${EXECUTABLE} PUBLIC
-fsanitize=undefined,float-divide-by-zero,integer,implicit-conversion,implicit-integer-truncation,implicit-integer-arithmetic-value-change,local-bounds,nullability
-g3 -fno-omit-frame-pointer)
target_link_options(${EXECUTABLE} PUBLIC -fsanitize=undefined,float-divide-by-zero,integer,implicit-conversion,implicit-integer-truncation,implicit-integer-arithmetic-value-change,local-bounds,nullability)
endif()
if(${PROJECT}_WITH_ASAN)
target_compile_options(${EXECUTABLE} PUBLIC -fsanitize=address -g3 -fno-omit-frame-pointer)
target_link_options(${EXECUTABLE} PUBLIC -fsanitize=address)
endif()
2020-10-31 22:14:28 +00:00
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
2021-01-13 11:15:22 +00:00
target_compile_options(${EXECUTABLE}
2020-10-31 22:14:28 +00:00
PRIVATE
"-Wall"
)
if (NOT LIBRW_PLATFORM_PS2)
2021-01-13 11:15:22 +00:00
target_compile_options(${EXECUTABLE}
2020-10-31 22:14:28 +00:00
PRIVATE
-Wextra
-Wdouble-promotion
-Wpedantic
)
2020-10-31 22:14:28 +00:00
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
2021-01-13 11:15:22 +00:00
target_compile_options(${EXECUTABLE}
2020-10-31 22:14:28 +00:00
PUBLIC
/Zc:sizedDealloc-
)
2020-10-31 22:14:28 +00:00
endif()
2021-07-04 16:52:48 +00:00
if(NINTENDO_SWITCH)
set(${PROJECT}_C_CXX_EXTENSIONS ON)
else()
set(${PROJECT}_C_CXX_EXTENSIONS OFF)
endif()
2021-01-13 11:15:22 +00:00
set_target_properties(${EXECUTABLE}
2020-10-31 22:14:28 +00:00
PROPERTIES
C_STANDARD 11
2021-07-04 16:52:48 +00:00
C_EXTENSIONS ${${PROJECT}_C_CXX_EXTENSIONS}
2020-10-31 22:14:28 +00:00
C_STANDARD_REQUIRED ON
CXX_STANDARD 11
2021-07-04 16:52:48 +00:00
CXX_EXTENSIONS ${${PROJECT}_C_CXX_EXTENSIONS}
2020-10-31 22:14:28 +00:00
CXX_STANDARD_REQUIRED ON
)
2020-10-31 22:14:28 +00:00
2021-01-13 11:15:22 +00:00
if(${PROJECT}_INSTALL)
2020-10-31 22:14:28 +00:00
install(
2021-01-13 11:15:22 +00:00
TARGETS ${EXECUTABLE}
EXPORT ${EXECUTABLE}-targets
RUNTIME DESTINATION "."
)
if(MSVC)
2021-01-13 11:15:22 +00:00
install(FILES $<TARGET_PDB_FILE:${EXECUTABLE}> DESTINATION "." OPTIONAL)
endif()
2020-10-31 22:14:28 +00:00
endif()
2021-07-04 16:52:48 +00:00
# Build Nintendo Switch binaries
if(NINTENDO_SWITCH)
# Needed for OpenAL-Soft
target_link_libraries(${EXECUTABLE} PRIVATE
openal # HACK - something broke with latest cmake
SDL2
)
nx_generate_nacp (${EXECUTABLE}.nacp
NAME "${EXECUTABLE}"
AUTHOR "${EXECUTABLE} Team"
VERSION "1.0.0-${GIT_SHA1}"
)
nx_create_nro(${EXECUTABLE}
NACP ${EXECUTABLE}.nacp
ICON "${PROJECT_SOURCE_DIR}/logo_switch.jpg"
)
if(${PROJECT}_INSTALL)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE}.nro"
DESTINATION "."
)
endif()
endif()