cmake: make librw non-vendorable + rename Findmpg123 + create targets for dependencies

This commit is contained in:
Anonymous Maarten 2020-12-06 13:54:06 +01:00 committed by shfil
parent 8a157eee0a
commit 2ff9270279
6 changed files with 136 additions and 124 deletions

View File

@ -23,12 +23,17 @@ if(RE3_INSTALL)
set(RE3_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/re3")
endif()
add_subdirectory("vendor/librw")
option(RE3_VENDORED_LIBRW "Use vendored librw" ON)
if(RE3_VENDORED_LIBRW)
add_subdirectory(vendor/librw)
else()
find_package(librw REQUIRED)
endif()
add_subdirectory(src)
if(RE3_INSTALL)
include(CMakePackageConfigHelpers)
configure_package_config_file(re3-config.cmake.in re3-config.cmake
configure_package_config_file(cmake/re3-config.cmake.in re3-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}"
)
install(
@ -40,5 +45,15 @@ if(RE3_INSTALL)
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
include(CMakeCPack.cmake)
set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
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}")
include(CPack)
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_INCLUDE_DIRS - the libsndfile include directory
# SNDFILE_LIBRARIES - Link these to use libsndfile
# SNDFILE_CFLAGS - Compile options to use libsndfile
# SndFile::SNdFile - Imported library of libsndfile
#
# Copyright (C) 2006 Wengo
#
@ -15,14 +17,16 @@
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
if (SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS)
# in cache already
set(SNDFILE_FOUND TRUE)
else (SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_search_module(PKG_SNDFILE "sndfile")
endif()
find_path(SNDFILE_INCLUDE_DIR
find_path(SNDFILE_INCLUDE_DIR
NAMES
sndfile.h
HINTS
${PKG_SNDFILE_INCLUDE_DIRS}
PATHS
/usr/include
/usr/local/include
@ -30,38 +34,37 @@ else (SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS)
/sw/include
)
find_library(SNDFILE_LIBRARY
find_library(SNDFILE_LIBRARY
NAMES
sndfile
HINTS
${PKG_SNDFILE_LIBRARIES}
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
)
set(SNDFILE_INCLUDE_DIRS
${SNDFILE_INCLUDE_DIR}
)
set(SNDFILE_LIBRARIES
${SNDFILE_LIBRARY}
)
set(SNDFILE_CFLAGS "${PKG_SNDFILE_CFLAGS_OTHER}" CACHE STRING "CFLAGS of libsndfile")
if (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES)
set(SNDFILE_FOUND TRUE)
endif (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES)
set(SNDFILE_INCLUDE_DIRS ${SNDFILE_INCLUDE_DIR})
set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY})
if (SNDFILE_FOUND)
if (NOT SndFile_FIND_QUIETLY)
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)
if (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES)
set(SNDFILE_FOUND TRUE)
endif (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES)
# show the SNDFILE_INCLUDE_DIRS and SNDFILE_LIBRARIES variables only in the advanced view
mark_as_advanced(SNDFILE_INCLUDE_DIRS SNDFILE_LIBRARIES)
endif (SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS)
# handle the QUIETLY and REQUIRED arguments and set SNdFile_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SndFile DEFAULT_MSG SNDFILE_INCLUDE_DIRS SNDFILE_LIBRARIES)
if(NOT TARGET SndFile::SndFile)
add_library(__SndFile INTERFACE)
target_compile_options(__SndFile INTERFACE ${SNDFILE_CFLAGS})
target_include_directories(__SndFile INTERFACE ${SNDFILE_INCLUDE_DIRS})
target_link_libraries(__SndFile INTERFACE ${SNDFILE_LIBRARIES})
add_library(SndFile::SndFile ALIAS __SndFile)
endif()

40
cmake/Findmpg123.cmake Normal file
View File

@ -0,0 +1,40 @@
# - 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")
# 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)
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

@ -0,0 +1,5 @@
include("${CMAKE_CURRENT_LIST_DIR}/re3-targets.cmake")
set(RE3_AUDIO "@RE3_AUDIO@")
set(RE3_AUDIOS "@RE3_AUDIOS@")
set(RE3_PLATFORM @LIBRW_PLATFORM@)

View File

@ -3,65 +3,48 @@ find_package(Threads REQUIRED)
if(${RE3_AUDIO} STREQUAL "OAL")
find_package(OpenAL REQUIRED)
find_package(MPG123 REQUIRED)
find_package(mpg123 REQUIRED)
find_package(SndFile REQUIRED)
endif()
file(GLOB_RECURSE Sources "*.cpp" "*.h")
file(GLOB_RECURSE RE3_SOURCES "*.cpp" "*.h")
MACRO(HEADER_DIRECTORIES return_list)
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()
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()
HEADER_DIRECTORIES(header_list)
include_directories(${header_list})
header_directories(RE3_INCLUDES)
include_directories(${RE3_INCLUDES})
add_executable(re3 ${RE3_SOURCES})
target_link_libraries(re3 PRIVATE
librw::librw
Threads::Threads
)
add_executable(re3 ${Sources})
target_link_libraries(re3 librw)
target_link_libraries(re3 Threads::Threads)
if(${RE3_AUDIO} STREQUAL "OAL")
target_link_libraries(re3 ${OPENAL_LIBRARY})
target_link_libraries(re3 ${MPG123_LIBRARIES})
target_link_libraries(re3 ${SNDFILE_LIBRARIES})
if(RE3_AUDIO STREQUAL "OAL")
target_link_libraries(re3 PRIVATE ${OPENAL_LIBRARY})
target_link_libraries(re3 PRIVATE MPG123::libmpg123)
target_link_libraries(re3 PRIVATE SndFile::SndFile)
endif()
target_include_directories(re3
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${RE3_INSTALL_INCLUDEDIR}>
)
target_compile_definitions(re3
PRIVATE
"$<IF:$<CONFIG:DEBUG>,DEBUG,NDEBUG>"
PUBLIC
"RW_${RE3_PLATFORM}"
)
target_compile_definitions(re3 PRIVATE LIBRW=1 AUDIO_OAL=1)
@ -71,7 +54,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang
PRIVATE
"-Wall"
)
if (NOT RE3_PLATFORM_PS2)
if (NOT LIBRW_PLATFORM_PS2)
target_compile_options(re3
PRIVATE
"-Wextra"
@ -94,15 +77,9 @@ set_target_properties(re3
CXX_STANDARD 11
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
PREFIX ""
)
if(RE3_INSTALL)
target_include_directories(re3
INTERFACE
$<INSTALL_INTERFACE:${RE3_INSTALL_INCLUDEDIR}>
)
install(
TARGETS re3
EXPORT re3-targets