diff --git a/CMakeLists.txt b/CMakeLists.txt index 283432b8e9..c34c68f71e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,9 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.7) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED on) -include(CMakeDependentOption) - -project(EasyRPG_Player CXX C) -set(PACKAGE_VERSION "0.5.3") +project(EasyRPG_Player VERSION 0.5.3 LANGUAGES CXX) # Source Files -set(PLAYER_SRCS +add_library(${PROJECT_NAME} src/async_handler.cpp src/audio_al.cpp src/audio.cpp @@ -168,59 +163,38 @@ set(PLAYER_SRCS src/window_varlist.cpp ) +include(CMakeDependentOption) + # Include directories -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src") +target_include_directories( + ${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src) -# Extra FindModule files +# Extra CMake Module files list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules") -# Add compile flags -if(CMAKE_GENERATOR MATCHES "Makefile") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") -endif() +include(ConfigureWindows) +include(PlayerFindPackage) + +# C++11 is required +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11) if(CMAKE_BUILD_TYPE MATCHES "Debug") - add_definitions(-D_DEBUG) + target_compile_definitions(${PROJECT_NAME} PUBLIC _DEBUG=1) endif() -add_definitions(-DUSE_SDL=2) +target_compile_definitions(${PROJECT_NAME} PUBLIC USE_SDL=2) # Endianess check if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) include(TestBigEndian) test_big_endian(WORDS_BIGENDIAN) if(WORDS_BIGENDIAN) - add_definitions(-DWORDS_BIGENDIAN) + target_compile_definitions(${PROJECT_NAME} PUBLIC WORDS_BIGENDIAN=1) endif() endif() -# Adds a library to the liblist if COND is true and the lib is found -# When COND is REQUIRED the lib is required -function(find_lib LIBNAME COND) - set(REQ OFF) - if(${COND} MATCHES "REQUIRED") - set(COND ON) - set(REQ ON) - endif() - - if(${COND}) - if(${REQ}) - find_package(${LIBNAME} REQUIRED) - else() - find_package(${LIBNAME}) - endif() - - if(${${LIBNAME}_FOUND}) - string(TOUPPER ${LIBNAME} LIBNAMEUP) - include_directories(${${LIBNAMEUP}_INCLUDE_DIRS}) - set(EASYRPG_PLAYER_LIBRARIES ${EASYRPG_PLAYER_LIBRARIES} ${${LIBNAMEUP}_LIBRARIES} PARENT_SCOPE) - endif() - - set(${LIBNAME}_FOUND ${${LIBNAME}_FOUND} PARENT_SCOPE) - endif() -endfunction() - # liblcf option(PLAYER_BUILD_LIBLCF "Instead of detecting liblcf the liblcf repository is cloned into lib/liblcf and built together with the Player. This is convenient for development" OFF) set(PLAYER_BUILD_LIBLCF_GIT "https://github.com/EasyRPG/liblcf.git" CACHE STRING "Git repository of liblcf to clone when building liblcf. Requires PLAYER_BUILD_LIBLCF=ON.") @@ -230,40 +204,54 @@ if(PLAYER_BUILD_LIBLCF) set(LIBLCF_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/liblcf") find_package(Git REQUIRED) if(NOT EXISTS ${LIBLCF_PATH}) - execute_process(COMMAND ${GIT_EXECUTABLE} clone "--depth=1" - "${PLAYER_BUILD_LIBLCF_GIT}" - "${LIBLCF_PATH}") + execute_process(COMMAND ${GIT_EXECUTABLE} clone "--depth=1" + "${PLAYER_BUILD_LIBLCF_GIT}" + "${LIBLCF_PATH}") endif() + SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build liblcf shared library") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/liblcf/builds/cmake/Modules") - add_subdirectory( - ${LIBLCF_PATH} - ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/liblcf) + + add_subdirectory(${LIBLCF_PATH}) + target_link_libraries(${PROJECT_NAME} lcf) else() # Use system package - find_lib(liblcf REQUIRED) + find_package(liblcf REQUIRED) + target_link_libraries(${PROJECT_NAME} liblcf::liblcf) endif() # Detect all required libraries -foreach(i Pixman PNG ZLIB SDL2) - find_lib(${i} REQUIRED) -endforeach() +find_package(PNG REQUIRED) +target_link_libraries(${PROJECT_NAME} PNG::PNG) + +find_package(Pixman REQUIRED) +target_link_libraries(${PROJECT_NAME} PIXMAN::PIXMAN) + +find_package(SDL2 REQUIRED) +target_link_libraries(${PROJECT_NAME} SDL2::SDL2main) # Always enable Wine registry support on non-Windows if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows") - add_definitions(-DHAVE_WINE) + target_compile_definitions(${PROJECT_NAME} PUBLIC HAVE_WINE=1) endif() # freetype and harfbuzz option(PLAYER_WITH_FREETYPE "Support FreeType font rendering" ON) CMAKE_DEPENDENT_OPTION(PLAYER_WITH_HARFBUZZ "Enable HarfBuzz text shaping (Requires FreeType)" ON "PLAYER_WITH_FREETYPE" OFF) -find_lib("Freetype" PLAYER_WITH_FREETYPE) + +player_find_package( + NAME Freetype + CONDITION PLAYER_WITH_FREETYPE + DEFINITION HAVE_FREETYPE + FOUND Freetype + TARGET Freetype::Freetype) + if(Freetype_FOUND) - add_definitions(-DHAVE_FREETYPE) - find_lib("Harfbuzz" PLAYER_WITH_HARFBUZZ) - if(Harfbuzz_FOUND) - add_definitions(-DHAVE_HARFBUZZ) - endif() + player_find_package( + NAME Harfbuzz + CONDITION PLAYER_WITH_HARFBUZZ + DEFINITION HAVE_HARFBUZZ + TARGET Harfbuzz::Harfbuzz) endif() # Sound system to use @@ -273,8 +261,11 @@ set_property(CACHE PLAYER_AUDIO_BACKEND PROPERTY STRINGS Auto SDL2 SDL2_mixer Op # Configure Audio backends if(${PLAYER_AUDIO_BACKEND} MATCHES "Auto") option(PLAYER_WITH_SDL2_MIXER "Use SDL2 mixer when available." ON) - find_lib("SDL2_mixer" PLAYER_WITH_SDL2_MIXER) - if(SDL2_mixer_FOUND) + player_find_package( + NAME SDL2_mixer + CONDITION PLAYER_WITH_SDL2_MIXER + TARGET SDL2::MIXER) + if(SDL2_MIXER_FOUND) set(PLAYER_AUDIO_BACKEND "SDL2_mixer") else() set(PLAYER_AUDIO_BACKEND "SDL2") @@ -282,41 +273,30 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "Auto") endif() if(${PLAYER_AUDIO_BACKEND} MATCHES "^SDL2$") - add_definitions(-DSUPPORT_AUDIO) - - # wildmidi (on for non-mixer) - option(PLAYER_WITH_WILDMIDI "Play MIDI audio with wildmidi." ON) - find_lib("WildMidi" PLAYER_WITH_WILDMIDI) - if(WildMidi_FOUND) - add_definitions(-DHAVE_WILDMIDI) - endif() + target_compile_definitions(${PROJECT_NAME} PUBLIC SUPPORT_AUDIO=1) # Provide fmmidi options option(PLAYER_ENABLE_FMMIDI "Enable internal MIDI sequencer. Will be used when external MIDI library fails." ON) if(${PLAYER_ENABLE_FMMIDI} MATCHES "ON") - add_definitions(-DWANT_FMMIDI) + target_compile_definitions(${PROJECT_NAME} PUBLIC WANT_FMMIDI=1) endif() elseif(${PLAYER_AUDIO_BACKEND} MATCHES "SDL2_mixer") - add_definitions(-DSUPPORT_AUDIO) + target_compile_definitions(${PROJECT_NAME} PUBLIC SUPPORT_AUDIO=1) # SDL2_mixer Audio - find_lib(SDL2_mixer REQUIRED) - add_definitions(-DHAVE_SDL_MIXER) - - # wildmidi (optional, OFF) - option(PLAYER_WITH_WILDMIDI "Play MIDI audio with wildmidi. (optional)" OFF) - find_lib("WildMidi" PLAYER_WITH_WILDMIDI) - if(WildMidi_FOUND) - add_definitions(-DHAVE_WILDMIDI) - endif() + player_find_package( + NAME SDL2_mixer + DEFINITION HAVE_SDL_MIXER + TARGET SDL2::MIXER + REQUIRED) # Provide fmmidi options set(PLAYER_ENABLE_FMMIDI "Fallback" CACHE STRING "Enable internal MIDI sequencer. Fallback (default) mode will use it when the external MIDI library fails. Options: Fallback ON OFF") set_property(CACHE PLAYER_ENABLE_FMMIDI PROPERTY STRINGS Fallback ON OFF) if(${PLAYER_ENABLE_FMMIDI} MATCHES "Fallback") - add_definitions(-DWANT_FMMIDI=2) + target_compile_definitions(${PROJECT_NAME} PUBLIC WANT_FMMIDI=2) elseif(${PLAYER_ENABLE_FMMIDI} MATCHES "ON") - add_definitions(-DWANT_FMMIDI=1) + target_compile_definitions(${PROJECT_NAME} PUBLIC WANT_FMMIDI=1) elseif(${PLAYER_ENABLE_FMMIDI} MATCHES "OFF") # noop else() @@ -324,14 +304,14 @@ elseif(${PLAYER_AUDIO_BACKEND} MATCHES "SDL2_mixer") endif() elseif(${PLAYER_AUDIO_BACKEND} MATCHES "OpenAL") # OpenAL Audio - add_definitions(-DSUPPORT_AUDIO) + target_compile_definitions(${PROJECT_NAME} PUBLIC SUPPORT_AUDIO=1) find_package(OpenAL REQUIRED) - find_package(SndFile REQUIRED) + find_package(LibSndFile REQUIRED) find_package(FluidSynth REQUIRED) - include_directories(${OPENAL_INCLUDE_DIR} ${SNDFILE_INCLUDE_DIR} ${FLUIDSYNTH_INCLUDE_DIR}) - list(APPEND EASYRPG_PLAYER_LIBRARIES ${OPENAL_LIBRARY} ${SNDFILE_LIBRARIES} ${FLUIDSYNTH_LIBRARY}) - add_definitions(-DHAVE_OPENAL) + target_include_directories(${PROJECT_NAME} PUBLIC ${OPENAL_INCLUDE_DIR}) + target_link_libraries(${PROJECT_NAME} ${OPENAL_LIBRARY} LibSndFile::LibSndFile Fluidsynth::Fluidsynth) + target_compile_definitions(${PROJECT_NAME} PUBLIC HAVE_OPENAL=1) elseif(${PLAYER_AUDIO_BACKEND} MATCHES "OFF") else() @@ -341,99 +321,92 @@ endif() if(${PLAYER_AUDIO_BACKEND} MATCHES "^SDL.*$") # speexdsp option(PLAYER_WITH_SPEEXDSP "Resample audio with speexdsp." ON) - find_lib("speexdsp" PLAYER_WITH_SPEEXDSP) - if(speexdsp_FOUND) - add_definitions(-DHAVE_LIBSPEEXDSP) - endif() + player_find_package( + NAME speexdsp + CONDITION PLAYER_WITH_SPEEXDSP + DEFINITION HAVE_LIBSPEEXDSP + TARGET speexdsp::speexdsp) # mpg123 option(PLAYER_WITH_MPG123 "Play MP3 audio with libmpg123." ON) - find_lib("mpg123" PLAYER_WITH_MPG123) - if(mpg123_FOUND) - add_definitions(-DHAVE_MPG123) - endif() + player_find_package( + NAME mpg123 + CONDITION PLAYER_WITH_MPG123 + DEFINITION HAVE_MPG123 + TARGET mpg123::mpg123) # libsndfile option(PLAYER_WITH_LIBSNDFILE "Play WAV audio with libsndfile." ON) - find_lib("SndFile" PLAYER_WITH_LIBSNDFILE) - if(SndFile_FOUND) - add_definitions(-DHAVE_LIBSNDFILE) - endif() + player_find_package( + NAME LibSndFile + CONDITION PLAYER_WITH_LIBSNDFILE + DEFINITION HAVE_LIBSNDFILE + TARGET LibSndFile::LibSndFile) # libvorbis option(PLAYER_WITH_OGGVORBIS "Play Ogg Vorbis audio with libvorbis." ON) - find_lib("OggVorbis" PLAYER_WITH_OGGVORBIS) - if(OggVorbis_FOUND) - add_definitions(-DHAVE_OGGVORBIS) - endif() + player_find_package( + NAME Vorbisfile + CONDITION PLAYER_WITH_OGGVORBIS + DEFINITION HAVE_OGGVORBIS + TARGET Vorbisfile::Vorbisfile) # opusfile option(PLAYER_WITH_OPUS "Play Opus audio with opusfile." ON) - find_lib("Opus" PLAYER_WITH_OPUS) - if(Opus_FOUND) - add_definitions(-DHAVE_OPUS) - endif() + player_find_package( + NAME Opusfile + CONDITION PLAYER_WITH_OPUS + DEFINITION HAVE_OPUS + TARGET Opusfile::Opusfile) + + # wildmidi + option(PLAYER_WITH_WILDMIDI "Play MIDI audio with wildmidi." ON) + player_find_package( + NAME WildMidi + CONDITION PLAYER_WITH_WILDMIDI + DEFINITION HAVE_WILDMIDI + TARGET WildMidi::WildMidi) # xmp (lite) option(PLAYER_WITH_XMP "Play MOD audio with libxmp." ON) - find_lib("XMP" PLAYER_WITH_XMP) - if(XMP_FOUND) - add_definitions(-DHAVE_XMP) - endif() + player_find_package( + NAME XMP + CONDITION PLAYER_WITH_XMP + DEFINITION HAVE_XMP + TARGET XMP::XMP) if(NOT ${PLAYER_ENABLE_FMMIDI} MATCHES "OFF") - list(APPEND PLAYER_SRCS + target_sources(${PROJECT_NAME} PRIVATE src/midisequencer.cpp - src/midisynth.cpp - ) + src/midisynth.cpp) endif() endif() -# Additional include directories -if(PLAYER_BUILD_LIBLCF) - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib/liblcf/src") - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib/liblcf/src/generated") +# Executable +# Windows: Only open console for Debug builds +if(CMAKE_BUILD_TYPE MATCHES "Debug") + add_executable(${PROJECT_NAME}_exe "src/main.cpp") +else() + add_executable(${PROJECT_NAME}_exe WIN32 "src/main.cpp") endif() -# Libraries -set(EASYRPG_PLAYER_LIBRARIES_ALL "${PROJECT_NAME}_Static" ${EASYRPG_PLAYER_LIBRARIES}) -if(PLAYER_BUILD_LIBLCF) - list(APPEND EASYRPG_PLAYER_LIBRARIES_ALL lcf) +if(WIN32) + set_target_properties(${PROJECT_NAME}_exe PROPERTIES OUTPUT_NAME "Player") +else() + set_target_properties(${PROJECT_NAME}_exe PROPERTIES OUTPUT_NAME "easyrpg-player") endif() -# Output path -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin) -set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib) - -# Entry point -set(EXE_FILES "src/main.cpp") - -# Add prefix (CMAKE_CURRENT_SOURCE_DIR) to list elements -FUNCTION(PREPEND var prefix) - SET(listVar "") - FOREACH(f ${ARGN}) - LIST(APPEND listVar "${prefix}/${f}") - ENDFOREACH(f) - SET(${var} "${listVar}" PARENT_SCOPE) -ENDFUNCTION(PREPEND) - -PREPEND(PLAYER_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${PLAYER_SRCS}) -PREPEND(EXE_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${EXE_FILES}) - -# Static library -if(CMAKE_SYSTEM_NAME MATCHES "Windows") - list(APPEND PLAYER_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/resources/player.rc") +# Add Windows resources +if(WIN32) + target_sources(${PROJECT_NAME}_exe PRIVATE "resources/player.rc") endif() -add_library(${PROJECT_NAME}_Static STATIC ${PLAYER_SRCS}) -# Executable -add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${EXE_FILES}) -target_link_libraries(${PROJECT_NAME} ${EASYRPG_PLAYER_LIBRARIES_ALL}) -add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_Static) -if(PLAYER_BUILD_LIBLCF) - add_dependencies(${PROJECT_NAME} lcf) -endif() -install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} DESTINATION bin) +target_link_libraries(${PROJECT_NAME}_exe ${PROJECT_NAME}) + +# installation +include(GNUInstallDirs) +install(TARGETS ${PROJECT_NAME}_exe + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) # manpage # Handled as extra target "man" @@ -441,7 +414,7 @@ set(MAN_NAME easyrpg-player.6) find_program(A2X_EXECUTABLE NAMES a2x a2x.py) if(NOT A2X_EXECUTABLE STREQUAL "A2X_EXECUTABLE-NOTFOUND") add_custom_command(OUTPUT resources/${MAN_NAME} - COMMAND ${A2X_EXECUTABLE} -a player_version="${PACKAGE_VERSION}" -f manpage -D ${CMAKE_CURRENT_BINARY_DIR}/resources ${CMAKE_CURRENT_SOURCE_DIR}/resources/${MAN_NAME}.adoc + COMMAND ${A2X_EXECUTABLE} -a player_version="${PROJECT_VERSION}" -f manpage -D ${CMAKE_CURRENT_BINARY_DIR}/resources ${CMAKE_CURRENT_SOURCE_DIR}/resources/${MAN_NAME}.adoc DEPENDS resources/${MAN_NAME}.adoc COMMENT "(Re-)building manpage ${MAN_NAME}" VERBATIM) @@ -471,14 +444,14 @@ if(DOXYGEN_FOUND) add_custom_target(player_doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/resources/Doxyfile - DEPENDS ${PLAYER_SRCS} ${EXE_FILES} + DEPENDS ${PROJECT_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/resources COMMENT "Generating API documentation with Doxygen" VERBATIM) - add_custom_target(doc) - add_dependencies(doc player_doc) - if(PLAYER_BUILD_LIBLCF) - add_dependencies(doc liblcf_doc) + if(NOT TARGET doc) + # Handle liblcf doc target + add_custom_target(doc) endif() + add_dependencies(doc player_doc) endif() # Unit tests @@ -506,12 +479,11 @@ if(PLAYER_ENABLE_TESTS) foreach(i ${TEST_FILES}) get_filename_component(name "${i}" NAME_WE) add_executable(test_${name} ${i}) - target_link_libraries(test_${name} ${EASYRPG_PLAYER_LIBRARIES_ALL}) - add_dependencies(test_${name} ${PROJECT_NAME}_Static) + target_link_libraries(test_${name} ${PROJECT_NAME}) add_test( NAME test_${name} WORKING_DIRECTORY ${TEST_GAME_PATH} - COMMAND ${EXECUTABLE_OUTPUT_PATH}/test_${name}) + COMMAND ${PROJECT_BINARY_DIR}/test_${name}) set_tests_properties(test_${name} PROPERTIES ENVIRONMENT "${TEST_ENVS}") endforeach() @@ -527,14 +499,14 @@ message(STATUS "Audio backend: ${PLAYER_AUDIO_BACKEND}") if(${PLAYER_AUDIO_BACKEND} MATCHES "^SDL2.*$") message(STATUS "") - if(SndFile_FOUND) - message(STATUS "WAV playback: libsndfile") + if(LIBSNDFILE_FOUND) + message(STATUS "WAV playback: libsndfile") else() set(SDL_MIXER_USED ON) - message(STATUS "WAV playback: SDL2_mixer") + message(STATUS "WAV playback: SDL2_mixer") endif() - if(WildMidi_FOUND) + if(WILDMIDI_FOUND) if(${PLAYER_ENABLE_FMMIDI} MATCHES "(Fallback|ON)") message(STATUS "MIDI playback: WildMidi. Fallback to built-in (FmMidi)") else() @@ -552,16 +524,16 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^SDL2.*$") endif() endif() - if(mpg123_FOUND) - message(STATUS "MP3 playback: mpg123") + if(MPG123_FOUND) + message(STATUS "MP3 playback: mpg123") elseif(SDL2_mixer_FOUND) set(SDL_MIXER_USED ON) - message(STATUS "MP3 playback: SDL2_mixer. Some MP3 files will crash or play noise.") + message(STATUS "MP3 playback: SDL2_mixer") else() - message(STATUS "MP3 playback: None") + message(STATUS "MP3 playback: None") endif() - if(OggVorbis_FOUND) + if(VORBISFILE_FOUND) message(STATUS "Ogg Vorbis playback: libvorbis") elseif(SDL2_mixer_FOUND) set(SDL_MIXER_USED ON) @@ -571,27 +543,27 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^SDL2.*$") endif() if(XMP_FOUND) - message(STATUS "MOD playback: libxmp") + message(STATUS "MOD playback: libxmp") elseif(SDL2_mixer_FOUND) set(SDL_MIXER_USED ON) - message(STATUS "MOD playback: SDL2_mixer") + message(STATUS "MOD playback: SDL2_mixer") else() - message(STATUS "MOD playback: None") + message(STATUS "MOD playback: None") endif() - if(Opus_FOUND) + if(OPUSFILE_FOUND) message(STATUS "Opus playback: opusfile") else() message(STATUS "Opus playback: None") endif() - if(speexdsp_FOUND) - message(STATUS "Resampler: speexdsp") + if(SPEEXDSP_FOUND) + message(STATUS "Resampler: speexdsp") elseif(SDL2_mixer_FOUND) set(SDL_MIXER_USED ON) - message(STATUS "Resampler: SDL2") + message(STATUS "Resampler: SDL2") else() - message(STATUS "Resampler: None") + message(STATUS "Resampler: None") endif() if(SDL_MIXER_USED) @@ -604,12 +576,12 @@ endif() message(STATUS "") -if(Harfbuzz_FOUND) - message(STATUS "Font rendering: Freetype with Harfbuzz / built-in (Shinonome)") -elseif(FreeType_FOUND) - message(STATUS "Font rendering: Freetype and built-in (Shinonome)") +if(HARFBUZZ_FOUND) + message(STATUS "Font rendering: Freetype with Harfbuzz / built-in") +elseif(Freetype_FOUND) + message(STATUS "Font rendering: Freetype and built-in") else() - message(STATUS "Font rendering: built-in (Shinonome)") + message(STATUS "Font rendering: built-in") endif() message(STATUS "") diff --git a/builds/cmake/Modules/ConfigureWindows.cmake b/builds/cmake/Modules/ConfigureWindows.cmake new file mode 100644 index 0000000000..7f72febc39 --- /dev/null +++ b/builds/cmake/Modules/ConfigureWindows.cmake @@ -0,0 +1,44 @@ +if(WIN32) + option(SHARED_RUNTIME "Windows: Build using the shared runtime library (/MD), disable for static runtime (/MT)" ON) + + # Set compiler options. + set(variables + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_MINSIZEREL + CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_RELWITHDEBINFO + ) + if(SHARED_RUNTIME) + message(STATUS "Windows: Using dynamic runtime library (/MD)") + foreach(variable ${variables}) + if(${variable} MATCHES "/MT") + string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}") + endif() + endforeach() + else() + message(STATUS "Windows: Using static runtime library (/MT)") + foreach(variable ${variables}) + if(${variable} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}") + endif() + endforeach() + endif() + + # Target Unicode API + add_definitions(-D_UNICODE) + add_definitions(-DUNICODE) + + # Disable API deprecation warnings + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif() + +if(MSVC) + option(MSVC_MULTICORE "MSVC: Build using multiple cores (/MP)" ON) + if (MSVC_MULTICORE) + add_compile_options(/MP) + endif() +endif() diff --git a/builds/cmake/Modules/FindFluidSynth.cmake b/builds/cmake/Modules/FindFluidSynth.cmake index 1dda99749f..2bd44d7645 100644 --- a/builds/cmake/Modules/FindFluidSynth.cmake +++ b/builds/cmake/Modules/FindFluidSynth.cmake @@ -1,10 +1,64 @@ -find_library(FLUIDSYNTH_LIBRARY "fluidsynth") -find_path(FLUIDSYNTH_INCLUDE_DIR "fluidsynth.h") +#.rst: +# FindFluidSynth +# ----------- +# +# Find the FluidSynth Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``fluidsynth::fluidsynth`` +# The ``FluidSynth`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``FLUIDSYNTH_INCLUDE_DIRS`` +# where to find FluidSynth headers. +# ``FLUIDSYNTH_LIBRARIES`` +# the libraries to link against to use FluidSynth. +# ``FLUIDSYNTH_FOUND`` +# true if the FluidSynth headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_FLUIDSYNTH QUIET fluidsynth) + +# Look for the header file. +find_path(FLUIDSYNTH_INCLUDE_DIR + NAMES fluidsynth.h + PATH_SUFFIXES libfluidsynth fluidsynth + HINTS ${PC_FLUIDSYNTH_INCLUDE_DIRS}) + +# Look for the library. +# Allow FLUIDSYNTH_LIBRARY to be set manually, as the location of the FluidSynth library +if(NOT FLUIDSYNTH_LIBRARY) + find_library(FLUIDSYNTH_LIBRARY + NAMES libfluidsynth fluidsynth + HINTS ${PC_FLUIDSYNTH_LIBRARY_DIRS}) +endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(FluidSynth DEFAULT_MSG FLUIDSYNTH_LIBRARY FLUIDSYNTH_INCLUDE_DIR) +find_package_handle_standard_args(FluidSynth + REQUIRED_VARS FLUIDSYNTH_LIBRARY FLUIDSYNTH_INCLUDE_DIR) + +if(FLUIDSYNTH_FOUND) + set(FLUIDSYNTH_INCLUDE_DIRS ${FLUIDSYNTH_INCLUDE_DIR}) + + if(NOT FLUIDSYNTH_LIBRARIES) + set(FLUIDSYNTH_LIBRARIES ${FLUIDSYNTH_LIBRARIES}) + endif() -set(FLUIDSYNTH_INCLUDE_DIRS ${FLUIDSYNTH_INCLUDE_DIR}) -set(FLUIDSYNTH_LIBRARIES ${FLUIDSYNTH_LIBRARY}) + if(NOT TARGET fluidsynth::fluidsynth) + add_library(fluidsynth::fluidsynth UNKNOWN IMPORTED) + set_target_properties(fluidsynth::fluidsynth PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${FLUIDSYNTH_INCLUDE_DIRS}" + IMPORTED_LOCATION "${FLUIDSYNTH_LIBRARY}") + endif() +endif() mark_as_advanced(FLUIDSYNTH_INCLUDE_DIR FLUIDSYNTH_LIBRARY) diff --git a/builds/cmake/Modules/FindFreetype.cmake b/builds/cmake/Modules/FindFreetype.cmake new file mode 100644 index 0000000000..e16523c193 --- /dev/null +++ b/builds/cmake/Modules/FindFreetype.cmake @@ -0,0 +1,205 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#.rst: +# FindFreetype +# ------------ +# +# Find the FreeType font renderer includes and library. +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` target: +# +# ``Freetype::Freetype`` +# The Freetype ``freetype`` library, if found +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``FREETYPE_FOUND`` +# true if the Freetype headers and libraries were found +# ``FREETYPE_INCLUDE_DIRS`` +# directories containing the Freetype headers. This is the +# concatenation of the variables: +# +# ``FREETYPE_INCLUDE_DIR_ft2build`` +# directory holding the main Freetype API configuration header +# ``FREETYPE_INCLUDE_DIR_freetype2`` +# directory holding Freetype public headers +# ``FREETYPE_LIBRARIES`` +# the library to link against +# ``FREETYPE_VERSION_STRING`` +# the version of freetype found (since CMake 2.8.8) +# +# Hints +# ^^^^^ +# +# The user may set the environment variable ``FREETYPE_DIR`` to the root +# directory of a Freetype installation. + +# Created by Eric Wing. +# Modifications by Alexander Neundorf. +# This file has been renamed to "FindFreetype.cmake" instead of the correct +# "FindFreeType.cmake" in order to be compatible with the one from KDE4, Alex. + +# Ugh, FreeType seems to use some #include trickery which +# makes this harder than it should be. It looks like they +# put ft2build.h in a common/easier-to-find location which +# then contains a #include to a more specific header in a +# more specific location (#include ). +# Then from there, they need to set a bunch of #define's +# so you can do something like: +# #include FT_FREETYPE_H +# Unfortunately, using CMake's mechanisms like include_directories() +# wants explicit full paths and this trickery doesn't work too well. +# I'm going to attempt to cut out the middleman and hope +# everything still works. + +set(FREETYPE_FIND_ARGS + HINTS + ENV FREETYPE_DIR + PATHS + ENV GTKMM_BASEPATH + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] +) + +find_path( + FREETYPE_INCLUDE_DIR_ft2build + ft2build.h + ${FREETYPE_FIND_ARGS} + PATH_SUFFIXES + include/freetype2 + include + freetype2 +) + +find_path( + FREETYPE_INCLUDE_DIR_freetype2 + NAMES + freetype/config/ftheader.h + config/ftheader.h + ${FREETYPE_FIND_ARGS} + PATH_SUFFIXES + include/freetype2 + include + freetype2 +) + +if(NOT FREETYPE_LIBRARY) + find_library(FREETYPE_LIBRARY_RELEASE + NAMES + freetype + libfreetype + freetype219 + ${FREETYPE_FIND_ARGS} + PATH_SUFFIXES + lib + ) + find_library(FREETYPE_LIBRARY_DEBUG + NAMES + freetyped + libfreetyped + freetype219d + ${FREETYPE_FIND_ARGS} + PATH_SUFFIXES + lib + ) + include(SelectLibraryConfigurations) + select_library_configurations(FREETYPE) +else() + # on Windows, ensure paths are in canonical format (forward slahes): + file(TO_CMAKE_PATH "${FREETYPE_LIBRARY}" FREETYPE_LIBRARY) +endif() + +unset(FREETYPE_FIND_ARGS) + +# set the user variables +if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2) + set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}") + list(REMOVE_DUPLICATES FREETYPE_INCLUDE_DIRS) +endif() +set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}") + +if(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h") + set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h") +elseif(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h") + set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h") +endif() + +if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H) + file(STRINGS "${FREETYPE_H}" freetype_version_str + REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$") + + unset(FREETYPE_VERSION_STRING) + foreach(VPART MAJOR MINOR PATCH) + foreach(VLINE ${freetype_version_str}) + if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$") + set(FREETYPE_VERSION_PART "${CMAKE_MATCH_1}") + if(FREETYPE_VERSION_STRING) + string(APPEND FREETYPE_VERSION_STRING ".${FREETYPE_VERSION_PART}") + else() + set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}") + endif() + unset(FREETYPE_VERSION_PART) + endif() + endforeach() + endforeach() +endif() + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( + Freetype + REQUIRED_VARS + FREETYPE_LIBRARY + FREETYPE_INCLUDE_DIRS + VERSION_VAR + FREETYPE_VERSION_STRING +) + +mark_as_advanced( + FREETYPE_INCLUDE_DIR_freetype2 + FREETYPE_INCLUDE_DIR_ft2build +) + +if(Freetype_FOUND) + if(NOT TARGET Freetype::Freetype) + add_library(Freetype::Freetype UNKNOWN IMPORTED) + set_target_properties(Freetype::Freetype PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${FREETYPE_INCLUDE_DIRS}") + + # Handle circular dependency on harfbuzz + find_package(Harfbuzz QUIET) + if(HARFBUZZ_FOUND) + set_target_properties(Freetype::Freetype PROPERTIES + INTERFACE_LINK_LIBRARIES Harfbuzz::Harfbuzz) + endif() + + if(FREETYPE_LIBRARY_RELEASE) + set_property(TARGET Freetype::Freetype APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(Freetype::Freetype PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${FREETYPE_LIBRARY_RELEASE}") + endif() + + if(FREETYPE_LIBRARY_DEBUG) + set_property(TARGET Freetype::Freetype APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(Freetype::Freetype PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" + IMPORTED_LOCATION_DEBUG "${FREETYPE_LIBRARY_DEBUG}") + endif() + + if(NOT FREETYPE_LIBRARY_RELEASE AND NOT FREETYPE_LIBRARY_DEBUG) + set_target_properties(Freetype::Freetype PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${FREETYPE_LIBRARY}") + endif() + endif() +endif() diff --git a/builds/cmake/Modules/FindHarfbuzz.cmake b/builds/cmake/Modules/FindHarfbuzz.cmake index 45956c80e6..df6279dec1 100644 --- a/builds/cmake/Modules/FindHarfbuzz.cmake +++ b/builds/cmake/Modules/FindHarfbuzz.cmake @@ -1,19 +1,66 @@ -# HARFBUZZ_INCLUDE_DIR - harfbuzz include directory -# Harfbuzz_FOUND - wether harfbuzz is found -# HARFBUZZ_LIBRARY - harfbuzz library +#.rst: +# FindHarfbuzz +# ----------- +# +# Find the Harfbuzz Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``Harfbuzz::Harfbuzz`` +# The ``Harfbuzz`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``HARFBUZZ_INCLUDE_DIRS`` +# where to find Harfbuzz headers. +# ``HARFBUZZ_LIBRARIES`` +# the libraries to link against to use Harfbuzz. +# ``HARFBUZZ_FOUND`` +# true if the Harfbuzz headers and libraries were found. -include(FindPackageHandleStandardArgs) +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_HARFBUZZ QUIET harfbuzz) -find_path(HARFBUZZ_INCLUDE_DIR_INTERNAL harfbuzz/hb.h) -find_library(HARFBUZZ_LIBRARY harfbuzz) -if(EXISTS "${HARFBUZZ_INCLUDE_DIR_INTERNAL}") - set(HARFBUZZ_INCLUDE_DIR "${HARFBUZZ_INCLUDE_DIR_INTERNAL}/harfbuzz") +# Look for the header file. +find_path(HARFBUZZ_INCLUDE_DIR + NAMES hb.h + PATH_SUFFIXES libharfbuzz harfbuzz + HINTS ${PC_HARFBUZZ_INCLUDE_DIRS}) + +# Look for the library. +# Allow HARFBUZZ_LIBRARY to be set manually, as the location of the Harfbuzz library +if(NOT HARFBUZZ_LIBRARY) + find_library(HARFBUZZ_LIBRARY + NAMES libharfbuzz harfbuzz + HINTS ${PC_HARFBUZZ_LIBRARY_DIRS}) endif() +include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Harfbuzz - REQUIRED_VARS HARFBUZZ_INCLUDE_DIR HARFBUZZ_LIBRARY) + REQUIRED_VARS HARFBUZZ_LIBRARY HARFBUZZ_INCLUDE_DIR) -set(HARFBUZZ_INCLUDE_DIRS ${HARFBUZZ_INCLUDE_DIR}) -set(HARFBUZZ_LIBRARIES ${HARFBUZZ_LIBRARY}) +if(HARFBUZZ_FOUND) + set(HARFBUZZ_INCLUDE_DIRS ${HARFBUZZ_INCLUDE_DIR}) + + if(NOT HARFBUZZ_LIBRARIES) + set(HARFBUZZ_LIBRARIES ${HARFBUZZ_LIBRARIES}) + endif() + + if(NOT TARGET Harfbuzz::Harfbuzz) + add_library(Harfbuzz::Harfbuzz UNKNOWN IMPORTED) + find_library(Freetype REQUIRED) + set_target_properties(Harfbuzz::Harfbuzz PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HARFBUZZ_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES Freetype::Freetype + IMPORTED_LOCATION "${HARFBUZZ_LIBRARY}") + endif() +endif() mark_as_advanced(HARFBUZZ_INCLUDE_DIR HARFBUZZ_LIBRARY) diff --git a/builds/cmake/Modules/FindLibSndFile.cmake b/builds/cmake/Modules/FindLibSndFile.cmake new file mode 100644 index 0000000000..c53bc05f1c --- /dev/null +++ b/builds/cmake/Modules/FindLibSndFile.cmake @@ -0,0 +1,64 @@ +#.rst: +# FindLibSndFile +# ----------- +# +# Find the LibSndFile Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``LibSndFile::LibSndFile`` +# The ``LibSndFile`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``LIBSNDFILE_INCLUDE_DIRS`` +# where to find LibSndFile headers. +# ``LIBSNDFILE_LIBRARIES`` +# the libraries to link against to use LibSndFile. +# ``LIBSNDFILE_FOUND`` +# true if the LibSndFile headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_LIBSNDFILE QUIET sndfile) + +# Look for the header file. +find_path(LIBSNDFILE_INCLUDE_DIR + NAMES sndfile.h + PATH_SUFFIXES libsndfile sndfile + HINTS ${PC_LIBSNDFILE_INCLUDE_DIRS}) + +# Look for the library. +# Allow LIBSNDFILE_LIBRARY to be set manually, as the location of the LibSndFile library +if(NOT LIBSNDFILE_LIBRARY) + find_library(LIBSNDFILE_LIBRARY + NAMES libsndfile sndfile + HINTS ${PC_LIBSNDFILE_LIBRARY_DIRS}) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LibSndFile + REQUIRED_VARS LIBSNDFILE_LIBRARY LIBSNDFILE_INCLUDE_DIR) + +if(LIBSNDFILE_FOUND) + set(LIBSNDFILE_INCLUDE_DIRS ${LIBSNDFILE_INCLUDE_DIR}) + + if(NOT LIBSNDFILE_LIBRARIES) + set(LIBSNDFILE_LIBRARIES ${LIBSNDFILE_LIBRARIES}) + endif() + + if(NOT TARGET LibSndFile::LibSndFile) + add_library(LibSndFile::LibSndFile UNKNOWN IMPORTED) + set_target_properties(LibSndFile::LibSndFile PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBSNDFILE_INCLUDE_DIRS}" + IMPORTED_LOCATION "${LIBSNDFILE_LIBRARY}") + endif() +endif() + +mark_as_advanced(LIBSNDFILE_INCLUDE_DIR LIBSNDFILE_LIBRARY) diff --git a/builds/cmake/Modules/FindOggVorbis.cmake b/builds/cmake/Modules/FindOggVorbis.cmake deleted file mode 100644 index 43a444bb40..0000000000 --- a/builds/cmake/Modules/FindOggVorbis.cmake +++ /dev/null @@ -1,10 +0,0 @@ -find_path(OGGVORBIS_INCLUDE_DIR vorbis/vorbisfile.h) -find_library(OGGVORBIS_LIBRARY NAMES vorbisfile libvorbisfile) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(OggVorbis DEFAULT_MSG OGGVORBIS_INCLUDE_DIR OGGVORBIS_LIBRARY) - -set(OGGVORBIS_INCLUDE_DIRS ${OGGVORBIS_INCLUDE_DIR}) -set(OGGVORBIS_LIBRARIES ${OGGVORBIS_LIBRARY}) - -mark_as_advanced(OGGVORBIS_INCLUDE_DIR OGGVORBIS_LIBRARY) diff --git a/builds/cmake/Modules/FindOpus.cmake b/builds/cmake/Modules/FindOpus.cmake deleted file mode 100644 index 55c638dcc5..0000000000 --- a/builds/cmake/Modules/FindOpus.cmake +++ /dev/null @@ -1,13 +0,0 @@ -find_path(OPUS_INCLUDE_DIR_INTERNAL opus/opusfile.h) -find_library(OPUS_LIBRARY NAMES opusfile libopusfile) -if(EXISTS "${OPUS_INCLUDE_DIR_INTERNAL}") - set(OPUS_INCLUDE_DIR "${OPUS_INCLUDE_DIR_INTERNAL}/opus") -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Opus DEFAULT_MSG OPUS_INCLUDE_DIR OPUS_LIBRARY) - -set(OPUS_INCLUDE_DIRS ${OPUS_INCLUDE_DIR}) -set(OPUS_LIBRARIES ${OPUS_LIBRARY}) - -mark_as_advanced(OPUS_INCLUDE_DIR OPUS_LIBRARY) diff --git a/builds/cmake/Modules/FindOpusfile.cmake b/builds/cmake/Modules/FindOpusfile.cmake new file mode 100644 index 0000000000..1d4e17cd2c --- /dev/null +++ b/builds/cmake/Modules/FindOpusfile.cmake @@ -0,0 +1,69 @@ +#.rst: +# FindOpusfile +# ----------- +# +# Find the Opusfile Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``Opusfile::Opusfile`` +# The ``Opusfile`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``OPUSFILE_INCLUDE_DIRS`` +# where to find Opusfile headers. +# ``OPUSFILE_LIBRARIES`` +# the libraries to link against to use Opusfile. +# ``OPUSFILE_FOUND`` +# true if the Opusfile headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_OPUSFILE QUIET opusfile) + +# Look for the header file. +find_path(OPUSFILE_INCLUDE_DIR + NAMES opusfile.h + PATH_SUFFIXES opus + HINTS ${PC_OPUSFILE_INCLUDE_DIRS}) + +# Look for the library. +# Allow OPUSFILE_LIBRARY to be set manually, as the location of the Opusfile library +if(NOT OPUSFILE_LIBRARY) + find_library(OPUSFILE_LIBRARY + NAMES libopusfile opusfile + HINTS ${PC_OPUSFILE_LIBRARY_DIRS}) +endif() + +# Additional dependencies +find_library(OPUS_LIBRARY + NAMES libopus opus) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Opusfile + REQUIRED_VARS OPUSFILE_LIBRARY OPUSFILE_INCLUDE_DIR) + +if(OPUSFILE_FOUND) + set(OPUSFILE_INCLUDE_DIRS ${OPUSFILE_INCLUDE_DIR}) + + if(NOT OPUSFILE_LIBRARIES) + set(OPUSFILE_LIBRARIES ${OPUSFILE_LIBRARIES}) + endif() + + if(NOT TARGET Opusfile::Opusfile) + add_library(Opusfile::Opusfile UNKNOWN IMPORTED) + set_target_properties(Opusfile::Opusfile PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OPUSFILE_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES ${OPUS_LIBRARY} + IMPORTED_LOCATION "${OPUSFILE_LIBRARY}") + endif() +endif() + +mark_as_advanced(OPUSFILE_INCLUDE_DIR OPUSFILE_LIBRARY OPUS_LIBRARY) diff --git a/builds/cmake/Modules/FindPixman.cmake b/builds/cmake/Modules/FindPixman.cmake index f6bc031063..276ed80f63 100644 --- a/builds/cmake/Modules/FindPixman.cmake +++ b/builds/cmake/Modules/FindPixman.cmake @@ -1,19 +1,89 @@ -# PIXMAN_INCLUDE_DIR - pixman include directory -# Pixman_FOUND - wether pixman is found -# PIXMAN_LIBRARY - pixman library +#.rst: +# FindPixman +# ----------- +# +# Find the Pixman Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``PIXMAN::PIXMAN`` +# The ``Pixman`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``PIXMAN_INCLUDE_DIRS`` +# where to find Pixman headers. +# ``PIXMAN_LIBRARIES`` +# the libraries to link against to use Pixman. +# ``PIXMAN_FOUND`` +# true if the Pixman headers and libraries were found. -include(FindPackageHandleStandardArgs) +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_PIXMAN QUIET pixman-1) + +# Look for the header file. +find_path(PIXMAN_INCLUDE_DIR + NAMES pixman.h + PATH_SUFFIXES libpixman-1 pixman-1 + HINTS ${PC_PIXMAN_INCLUDE_DIRS}) -find_path(PIXMAN_INCLUDE_DIR_INTERNAL pixman-1/pixman.h) -find_library(PIXMAN_LIBRARY pixman-1) -if(EXISTS "${PIXMAN_INCLUDE_DIR_INTERNAL}") - set(PIXMAN_INCLUDE_DIR "${PIXMAN_INCLUDE_DIR_INTERNAL}/pixman-1") +# Look for the library. +# Allow PIXMAN_LIBRARY to be set manually, as the location of the Pixman library +if(NOT PIXMAN_LIBRARY) + find_library(PIXMAN_LIBRARY_RELEASE + NAMES libpixman-1 pixman-1 + HINTS ${PC_PIXMAN_LIBRARY_DIRS}) + + find_library(PIXMAN_LIBRARY_DEBUG + NAMES libpixman-1d pixman-1d + HINTS ${PC_PIXMAN_LIBRARY_DIRS}) + + include(SelectLibraryConfigurations) + select_library_configurations(PIXMAN) endif() +include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Pixman - REQUIRED_VARS PIXMAN_INCLUDE_DIR PIXMAN_LIBRARY) + REQUIRED_VARS PIXMAN_LIBRARY PIXMAN_INCLUDE_DIR) -set(PIXMAN_INCLUDE_DIRS ${PIXMAN_INCLUDE_DIR}) -set(PIXMAN_LIBRARIES ${PIXMAN_LIBRARY}) +if(PIXMAN_FOUND) + set(PIXMAN_INCLUDE_DIRS ${PIXMAN_INCLUDE_DIR}) + + if(NOT PIXMAN_LIBRARIES) + set(PIXMAN_LIBRARIES ${PIXMAN_LIBRARIES}) + endif() + + if(NOT TARGET PIXMAN::PIXMAN) + add_library(PIXMAN::PIXMAN UNKNOWN IMPORTED) + set_target_properties(PIXMAN::PIXMAN PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${PIXMAN_INCLUDE_DIRS}") + + if(PIXMAN_LIBRARY_RELEASE) + set_property(TARGET PIXMAN::PIXMAN APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(PIXMAN::PIXMAN PROPERTIES + IMPORTED_LOCATION_RELEASE "${PIXMAN_LIBRARY_RELEASE}") + endif() + + if(PIXMAN_LIBRARY_DEBUG) + set_property(TARGET PIXMAN::PIXMAN APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(PIXMAN::PIXMAN PROPERTIES + IMPORTED_LOCATION_DEBUG "${PIXMAN_LIBRARY_DEBUG}") + endif() + + if(NOT PIXMAN_LIBRARY_RELEASE AND NOT PIXMAN_LIBRARY_DEBUG) + set_property(TARGET PIXMAN::PIXMAN APPEND PROPERTY + IMPORTED_LOCATION "${PIXMAN_LIBRARY}") + endif() + endif() +endif() mark_as_advanced(PIXMAN_INCLUDE_DIR PIXMAN_LIBRARY) diff --git a/builds/cmake/Modules/FindSDL2.cmake b/builds/cmake/Modules/FindSDL2.cmake index 66bdd339b6..713aec323a 100644 --- a/builds/cmake/Modules/FindSDL2.cmake +++ b/builds/cmake/Modules/FindSDL2.cmake @@ -1,235 +1,273 @@ -# - Locate SDL library -# This module defines -# SDL2_LIBRARY, the name of the library to link against -# SDL2_FOUND, if false, do not try to link to SDL -# SDL2_INCLUDE_DIR, where to find SDL.h -# SDL2_VERSION_STRING, human-readable string containing the version of SDL +# - Find SDL2 +# Find the SDL2 headers and libraries # -# This module responds to the the flag: -# SDL2_BUILDING_LIBRARY -# If this is defined, then no SDL2_main will be linked in because -# only applications need main(). -# Otherwise, it is assumed you are building an application and this -# module will attempt to locate and set the the proper link flags -# as part of the returned SDL2_LIBRARY variable. +# SDL2::SDL2 - Imported target to use for building a library +# SDL2::SDL2main - Imported interface target to use if you want SDL and SDLmain. +# SDL2_FOUND - True if SDL2 was found. +# SDL2_DYNAMIC - If we found a DLL version of SDL (meaning you might want to copy a DLL from SDL2::SDL2) # -# Don't forget to include SDLmain.h and SDLmain.m your project for the -# OS X framework based version. (Other versions link to -lSDL2main which -# this module will try to find on your behalf.) Also for OS X, this -# module will automatically add the -framework Cocoa on your behalf. +# Original Author: +# 2015 Ryan Pavlik # -# -# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration -# and no SDL2_LIBRARY, it means CMake did not find your SDL library -# (SDL.dll, libsdl.so, SDL.framework, etc). -# Set SDL2_LIBRARY_TEMP to point to your SDL library, and configure again. -# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value -# as appropriate. These values are used to generate the final SDL2_LIBRARY -# variable, but when these values are unset, SDL2_LIBRARY does not get created. -# -# -# $SDLDIR is an environment variable that would -# correspond to the ./configure --prefix=$SDLDIR -# used in building SDL. -# l.e.galup 9-20-02 -# -# Modified by Eric Wing. -# Added code to assist with automated building by using environmental variables -# and providing a more controlled/consistent search behavior. -# Added new modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). -# Also corrected the header search path to follow "proper" SDL guidelines. -# Added a search for SDLmain which is needed by some platforms. -# Added a search for threads which is needed by some platforms. -# Added needed compile switches for MinGW. -# -# On OSX, this will prefer the Framework version (if found) over others. -# People will have to manually change the cache values of -# SDL2_LIBRARY to override this selection or set the CMake environment -# CMAKE_INCLUDE_PATH to modify the search paths. -# -# Note that the header path has changed from SDL/SDL.h to just SDL.h -# This needed to change because "proper" SDL convention -# is #include "SDL.h", not . This is done for portability -# reasons because not all systems place things in SDL/ (see FreeBSD). -# -# Modified by Gabriel Kind for EasyRPG project to find SDL2. -# -#============================================================================= -# Copyright 2003-2009 Kitware, Inc. -# Copyright 2012 Benjamin Eikel -# Copyright 2013 Gabriel Kind -# -#============================================================================= -# CMake - Cross Platform Makefile Generator -# Copyright 2000-2011 Kitware, Inc., Insight Software Consortium -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the names of Kitware, Inc., the Insight Software Consortium, -# nor the names of their contributors may be used to endorse or promote -# products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# ------------------------------------------------------------------------------ -# -# The above copyright and license notice applies to distributions of -# CMake in source and binary form. Some source files contain additional -# notices of original copyright by their contributors; see each source -# for details. Third-party software packages supplied with CMake under -# compatible licenses provide their own copyright notices documented in -# corresponding subdirectories. -# -# ------------------------------------------------------------------------------ -# -# CMake was initially developed by Kitware with the following sponsorship: -# -# * National Library of Medicine at the National Institutes of Health -# as part of the Insight Segmentation and Registration Toolkit (ITK). -# -# * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel -# Visualization Initiative. -# -# * National Alliance for Medical Image Computing (NAMIC) is funded by the -# National Institutes of Health through the NIH Roadmap for Medical Research, -# Grant U54 EB005149. -# -# * Kitware, Inc. -# - -find_path(SDL2_INCLUDE_DIR SDL.h - HINTS - ENV SDL2DIR - PATH_SUFFIXES include/SDL2 SDL2 -) - -# SDL-1.1 is the name used by FreeBSD ports... -# don't confuse it for the version number. -find_library(SDL2_LIBRARY_TEMP - NAMES SDL2 SDL2-2.0 - HINTS - ENV SDL2DIR - PATH_SUFFIXES lib -) - -if(NOT SDL2_BUILDING_LIBRARY) - if(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") - # Non-OS X framework versions expect you to also dynamically link to - # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms - # seem to provide SDL2main for compatibility even though they don't - # necessarily need it. - find_library(SDL2MAIN_LIBRARY - NAMES SDL2main SDL2main-2.0 - HINTS - ENV SDL2DIR - PATH_SUFFIXES lib - PATHS - /sw - /opt/local - /opt/csw - /opt - ) - endif() +# Copyright Sensics, Inc. 2015. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# Set up architectures (for windows) and prefixes (for mingw builds) +if(WIN32) + if(MINGW) + include(MinGWSearchPathExtras OPTIONAL) + if(MINGWSEARCH_TARGET_TRIPLE) + set(SDL2_PREFIX ${MINGWSEARCH_TARGET_TRIPLE}) + endif() + endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(SDL2_LIB_PATH_SUFFIX lib/x64) + if(NOT MSVC AND NOT SDL2_PREFIX) + set(SDL2_PREFIX x86_64-w64-mingw32) + endif() + else() + set(SDL2_LIB_PATH_SUFFIX lib/x86) + if(NOT MSVC AND NOT SDL2_PREFIX) + set(SDL2_PREFIX i686-w64-mingw32) + endif() + endif() endif() -# SDL may require threads on your system. -# The Apple build may not need an explicit flag because one of the -# frameworks may already provide it. -# But for non-OSX systems, I will use the CMake Threads package. -if(NOT APPLE) - find_package(Threads) +if(SDL2_PREFIX) + set(SDL2_ORIGPREFIXPATH ${CMAKE_PREFIX_PATH}) + if(SDL2_ROOT_DIR) + list(APPEND CMAKE_PREFIX_PATH "${SDL2_ROOT_DIR}") + endif() + if(CMAKE_PREFIX_PATH) + foreach(_prefix ${CMAKE_PREFIX_PATH}) + list(APPEND CMAKE_PREFIX_PATH "${_prefix}/${SDL2_PREFIX}") + endforeach() + endif() + if(MINGWSEARCH_PREFIXES) + list(APPEND CMAKE_PREFIX_PATH ${MINGWSEARCH_PREFIXES}) + endif() endif() -# MinGW needs an additional library, mwindows -# It's total link flags should look like -lmingw32 -lSDL2main -lSDL -lmwindows -# (Actually on second look, I think it only needs one of the m* libraries.) -if(MINGW) - set(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +# Invoke pkgconfig for hints +find_package(PkgConfig QUIET) +set(SDL2_INCLUDE_HINTS) +set(SDL2_LIB_HINTS) +if(PKG_CONFIG_FOUND) + pkg_search_module(SDL2PC QUIET sdl2) + if(SDL2PC_INCLUDE_DIRS) + set(SDL2_INCLUDE_HINTS ${SDL2PC_INCLUDE_DIRS}) + endif() + if(SDL2PC_LIBRARY_DIRS) + set(SDL2_LIB_HINTS ${SDL2PC_LIBRARY_DIRS}) + endif() endif() -if(SDL2_LIBRARY_TEMP) - # For SDL2main - if(SDL2MAIN_LIBRARY AND NOT SDL2_BUILDING_LIBRARY) - list(FIND SDL2_LIBRARY_TEMP "${SDL2MAIN_LIBRARY}" _SDL2_MAIN_INDEX) - if(_SDL2_MAIN_INDEX EQUAL -1) - set(SDL2_LIBRARY_TEMP "${SDL2MAIN_LIBRARY}" ${SDL2_LIBRARY_TEMP}) - endif() - unset(_SDL2_MAIN_INDEX) - endif() - - # For OS X, SDL uses Cocoa as a backend so it must link to Cocoa. - # CMake doesn't display the -framework Cocoa string in the UI even - # though it actually is there if I modify a pre-used variable. - # I think it has something to do with the CACHE STRING. - # So I use a temporary variable until the end so I can set the - # "real" variable in one-shot. - if(APPLE) - set(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") - endif() - - # For threads, as mentioned Apple doesn't need this. - # In fact, there seems to be a problem if I used the Threads package - # and try using this line, so I'm just skipping it entirely for OS X. - if(NOT APPLE) - set(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) - endif() - - # For MinGW library - if(MINGW) - set(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) - endif() - - # Set the final string here so the GUI reflects the final state. - set(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found") - # Set the temp variable to INTERNAL so it is not seen in the CMake GUI - set(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") +include(FindPackageHandleStandardArgs) + +find_library(SDL2_LIBRARY + NAMES + SDL2 + HINTS + ${SDL2_LIB_HINTS} + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES lib SDL2 ${SDL2_LIB_PATH_SUFFIX}) + +set(_sdl2_framework FALSE) +# Some special-casing if we've found/been given a framework. +# Handles whether we're given the library inside the framework or the framework itself. +if(APPLE AND "${SDL2_LIBRARY}" MATCHES "(/[^/]+)*.framework(/.*)?$") + set(_sdl2_framework TRUE) + set(SDL2_FRAMEWORK "${SDL2_LIBRARY}") + # Move up in the directory tree as required to get the framework directory. + while("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework(/.*)$" AND NOT "${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") + get_filename_component(SDL2_FRAMEWORK "${SDL2_FRAMEWORK}" DIRECTORY) + endwhile() + if("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$") + set(SDL2_FRAMEWORK_NAME ${CMAKE_MATCH_1}) + # If we found a framework, do a search for the header ahead of time that will be more likely to get the framework header. + find_path(SDL2_INCLUDE_DIR + NAMES + SDL_haptic.h # this file was introduced with SDL2 + HINTS + "${SDL2_FRAMEWORK}/Headers/") + else() + # For some reason we couldn't get the framework directory itself. + # Shouldn't happen, but might if something is weird. + unset(SDL2_FRAMEWORK) + endif() endif() -if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") - file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}") - set(SDL2_VERSION_STRING ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH}) - unset(SDL2_VERSION_MAJOR_LINE) - unset(SDL2_VERSION_MINOR_LINE) - unset(SDL2_VERSION_PATCH_LINE) - unset(SDL2_VERSION_MAJOR) - unset(SDL2_VERSION_MINOR) - unset(SDL2_VERSION_PATCH) +find_path(SDL2_INCLUDE_DIR + NAMES + SDL_haptic.h # this file was introduced with SDL2 + HINTS + ${SDL2_INCLUDE_HINTS} + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES include include/sdl2 include/SDL2 SDL2) + +if(WIN32 AND SDL2_LIBRARY) + find_file(SDL2_RUNTIME_LIBRARY + NAMES + SDL2.dll + libSDL2.dll + HINTS + ${SDL2_LIB_HINTS} + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES bin lib ${SDL2_LIB_PATH_SUFFIX}) +endif() + + +if(WIN32 OR ANDROID OR IOS OR (APPLE AND NOT _sdl2_framework)) + set(SDL2_EXTRA_REQUIRED SDL2_SDLMAIN_LIBRARY) + find_library(SDL2_SDLMAIN_LIBRARY + NAMES + SDL2main + PATHS + ${SDL2_ROOT_DIR} + ENV SDL2DIR + PATH_SUFFIXES lib ${SDL2_LIB_PATH_SUFFIX}) +endif() + +if(MINGW AND NOT SDL2PC_FOUND) + find_library(SDL2_MINGW_LIBRARY mingw32) + find_library(SDL2_MWINDOWS_LIBRARY mwindows) endif() +if(SDL2_PREFIX) + # Restore things the way they used to be. + set(CMAKE_PREFIX_PATH ${SDL2_ORIGPREFIXPATH}) +endif() + +# handle the QUIETLY and REQUIRED arguments and set QUATLIB_FOUND to TRUE if +# all listed variables are TRUE include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2 + DEFAULT_MSG + SDL2_LIBRARY + SDL2_INCLUDE_DIR + ${SDL2_EXTRA_REQUIRED}) + +if(SDL2_FOUND) + if(NOT TARGET SDL2::SDL2) + # Create SDL2::SDL2 + if(WIN32 AND SDL2_RUNTIME_LIBRARY) + set(SDL2_DYNAMIC TRUE) + add_library(SDL2::SDL2 SHARED IMPORTED) + set_target_properties(SDL2::SDL2 + PROPERTIES + IMPORTED_IMPLIB "${SDL2_LIBRARY}" + IMPORTED_LOCATION "${SDL2_RUNTIME_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + ) + else() + add_library(SDL2::SDL2 UNKNOWN IMPORTED) + if(SDL2_FRAMEWORK AND SDL2_FRAMEWORK_NAME) + # Handle the case that SDL2 is a framework and we were able to decompose it above. + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_FRAMEWORK}/${SDL2_FRAMEWORK_NAME}") + elseif(_sdl2_framework AND SDL2_LIBRARY MATCHES "(/[^/]+)*.framework$") + # Handle the case that SDL2 is a framework and SDL_LIBRARY is just the framework itself. -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 - REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR - VERSION_VAR SDL2_VERSION_STRING) + # This takes the basename of the framework, without the extension, + # and sets it (as a child of the framework) as the imported location for the target. + # This is the library symlink inside of the framework. + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARY}/${CMAKE_MATCH_1}") + else() + # Handle non-frameworks (including non-Mac), as well as the case that we're given the library inside of the framework + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARY}") + endif() + set_target_properties(SDL2::SDL2 + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR};${SDL2PC_INCLUDE_DIRS}" + ) + endif() -set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR}) -set(SDL2_LIBRARIES ${SDL2_LIBRARY}) + if(APPLE) + # Need Cocoa here, is always a framework + find_library(SDL2_COCOA_LIBRARY Cocoa) + list(APPEND SDL2_EXTRA_REQUIRED SDL2_COCOA_LIBRARY) + if(SDL2_COCOA_LIBRARY) + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LINK_INTERFACE_LIBRARIES ${SDL2_COCOA_LIBRARY}) + endif() + endif() + + + # Compute what to do with SDL2main + set(SDL2MAIN_LIBRARIES SDL2::SDL2) + add_library(SDL2::SDL2main INTERFACE IMPORTED) + if(SDL2_SDLMAIN_LIBRARY) + add_library(SDL2::SDL2main_real STATIC IMPORTED) + set_target_properties(SDL2::SDL2main_real + PROPERTIES + IMPORTED_LOCATION "${SDL2_SDLMAIN_LIBRARY}") + set(SDL2MAIN_LIBRARIES SDL2::SDL2main_real ${SDL2MAIN_LIBRARIES}) + endif() + if(MINGW) + # MinGW requires some additional libraries to appear earlier in the link line. + if(SDL2PC_LIBRARIES) + # Use pkgconfig-suggested extra libraries if available. + list(REMOVE_ITEM SDL2PC_LIBRARIES SDL2main SDL2) + set(SDL2MAIN_LIBRARIES ${SDL2PC_LIBRARIES} ${SDL2MAIN_LIBRARIES}) + else() + # fall back to extra libraries specified in pkg-config in + # an official binary distro of SDL2 for MinGW I downloaded + if(SDL2_MINGW_LIBRARY) + set(SDL2MAIN_LIBRARIES ${SDL2_MINGW_LIBRARY} ${SDL2MAIN_LIBRARIES}) + endif() + if(SDL2_MWINDOWS_LIBRARY) + set(SDL2MAIN_LIBRARIES ${SDL2_MWINDOWS_LIBRARY} ${SDL2MAIN_LIBRARIES}) + endif() + endif() + set_target_properties(SDL2::SDL2main + PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "main=SDL_main") + endif() + set_target_properties(SDL2::SDL2main + PROPERTIES + INTERFACE_LINK_LIBRARIES "${SDL2MAIN_LIBRARIES}") + + if(WIN32) + set_property(TARGET SDL2::SDL2 APPEND_STRING PROPERTY + INTERFACE_LINK_LIBRARIES "winmm;imm32;version") + elseif(APPLE) + find_library(COREVIDEO CoreVideo) + find_library(COCOA_LIBRARY Cocoa) + find_library(IOKIT IOKit) + find_library(FORCEFEEDBACK ForceFeedback) + find_library(CARBON_LIBRARY Carbon) + find_library(COREAUDIO CoreAudio) + find_library(AUDIOTOOLBOX AudioToolbox) + find_library(ICONV_LIBRARY iconv) + set_property(TARGET SDL2::SDL2 APPEND_STRING PROPERTY + INTERFACE_LINK_LIBRARIES ${COREVIDEO} ${COCOA_LIBRARY} + ${IOKIT} ${FORCEFEEDBACK} ${CARBON_LIBRARY} + ${COREAUDIO} ${AUDIOTOOLBOX} ${ICONV_LIBRARY}) + else() + # Remove -lSDL2 -lSDL2main from the pkg-config linker line, + # to prevent linking against the system library + list(REMOVE_ITEM SDL2PC_STATIC_LIBRARIES SDL2main SDL2) + set_property(TARGET SDL2::SDL2 APPEND_STRING PROPERTY + INTERFACE_LINK_LIBRARIES "${SDL2PC_STATIC_LIBRARIES}") + endif() + endif() + mark_as_advanced(SDL2_ROOT_DIR) +endif() -mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY) +mark_as_advanced(SDL2_LIBRARY + SDL2_RUNTIME_LIBRARY + SDL2_INCLUDE_DIR + SDL2_SDLMAIN_LIBRARY + SDL2_COCOA_LIBRARY + SDL2_MINGW_LIBRARY + SDL2_MWINDOWS_LIBRARY) diff --git a/builds/cmake/Modules/FindSDL2_mixer.cmake b/builds/cmake/Modules/FindSDL2_mixer.cmake index 2b6291783c..a11b7918fa 100644 --- a/builds/cmake/Modules/FindSDL2_mixer.cmake +++ b/builds/cmake/Modules/FindSDL2_mixer.cmake @@ -1,140 +1,100 @@ -# - Locate SDL2_mixer library -# This module defines: -# SDL2_MIXER_LIBRARIES, the name of the library to link against -# SDL2_MIXER_INCLUDE_DIRS, where to find the headers -# SDL2_MIXER_FOUND, if false, do not try to link against -# SDL2_MIXER_VERSION_STRING - human-readable string containing the version of SDL2_mixer +#.rst: +# FindSDL2_mixer +# ----------- # -# For backward compatiblity the following variables are also set: -# SDL2MIXER_LIBRARY (same value as SDL2_MIXER_LIBRARIES) -# SDL2MIXER_INCLUDE_DIR (same value as SDL2_MIXER_INCLUDE_DIRS) -# SDL2MIXER_FOUND (same value as SDL2_MIXER_FOUND) +# Find the SDL2_mixer Library # -# $SDLDIR is an environment variable that would -# correspond to the ./configure --prefix=$SDLDIR -# used in building SDL. +# Imported Targets +# ^^^^^^^^^^^^^^^^ # -# Created by Eric Wing. This was influenced by the FindSDL.cmake -# module, but with modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). +# This module defines the following :prop_tgt:`IMPORTED` targets: # -# Modified by Gabriel Kind for EasyRPG project to find SDL2_mixer. +# ``SDL2::MIXER`` +# The ``SDL2_mixer`` library, if found. # -#============================================================================= -# Copyright 2003-2009 Kitware, Inc. -# Copyright 2012 Benjamin Eikel -# Copyright 2013 Gabriel Kind +# Result Variables +# ^^^^^^^^^^^^^^^^ # -#============================================================================= -# CMake - Cross Platform Makefile Generator -# Copyright 2000-2011 Kitware, Inc., Insight Software Consortium -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the names of Kitware, Inc., the Insight Software Consortium, -# nor the names of their contributors may be used to endorse or promote -# products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# ------------------------------------------------------------------------------ -# -# The above copyright and license notice applies to distributions of -# CMake in source and binary form. Some source files contain additional -# notices of original copyright by their contributors; see each source -# for details. Third-party software packages supplied with CMake under -# compatible licenses provide their own copyright notices documented in -# corresponding subdirectories. -# -# ------------------------------------------------------------------------------ -# -# CMake was initially developed by Kitware with the following sponsorship: -# -# * National Library of Medicine at the National Institutes of Health -# as part of the Insight Segmentation and Registration Toolkit (ITK). -# -# * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel -# Visualization Initiative. -# -# * National Alliance for Medical Image Computing (NAMIC) is funded by the -# National Institutes of Health through the NIH Roadmap for Medical Research, -# Grant U54 EB005149. -# -# * Kitware, Inc. -# +# This module will set the following variables in your project: +# +# ``SDL2_MIXER_INCLUDE_DIRS`` +# where to find SDL2_mixer headers. +# ``SDL2_MIXER_LIBRARIES`` +# the libraries to link against to use SDL2_mixer. +# ``SDL2_MIXER_FOUND`` +# true if the SDL2_mixer headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_SDL2_MIXER QUIET SDL2_mixer) -if(NOT SDL2_MIXER_INCLUDE_DIR AND SDL2MIXER_INCLUDE_DIR) - set(SDL2_MIXER_INCLUDE_DIR ${SDL2MIXER_INCLUDE_DIR} CACHE PATH "directory cache -entry initialized from old variable name") +# Look for the header file. +find_path(SDL2_MIXER_INCLUDE_DIR + NAMES SDL_mixer.h + PATH_SUFFIXES include/SDL2 + HINTS ${PC_SDL2_MIXER_INCLUDE_DIRS}) + +# Look for the library. +# Allow SDL2_MIXER_LIBRARY to be set manually, as the location of the SDL2_mixer library +if(NOT SDL2_MIXER_LIBRARY) + find_library(SDL2_MIXER_LIBRARY + NAMES libSDL2_mixer SDL2_mixer + HINTS ${PC_SDL2_MIXER_LIBRARY_DIRS}) endif() -find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h - HINTS - ENV SDL2MIXERDIR - ENV SDL2DIR - PATH_SUFFIXES include/SDL2 include -) -if(NOT SDL2_MIXER_LIBRARY AND SDL2MIXER_LIBRARY) - set(SDL2_MIXER_LIBRARY ${SDL2MIXER_LIBRARY} CACHE FILEPATH "file cache entry -initialized from old variable name") +set(SDL2_MIXER_EXTRA_DEPS "") + +# Find additional dependencies +find_library(VORBIS_LIBRARY + NAMES libvorbis vorbis + HINTS ${PC_SDL2_MIXER_LIBRARY_DIRS}) +if(VORBIS_LIBRARY_FOUND) + # Required dependency of vorbis + find_library(OGG_LIBRARY + NAMES libogg ogg + HINTS ${PC_SDL2_MIXER_LIBRARY_DIRS}) + + list(APPEND SDL2_MIXER_EXTRA_DEPS ${VORBIS_LIBRARY} ${OGG_LIBRARY}) endif() -find_library(SDL2_MIXER_LIBRARY - NAMES SDL2_mixer - HINTS - ENV SDLMIXERDIR - ENV SDLDIR - PATH_SUFFIXES lib -) -if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") - file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") - set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) - unset(SDL2_MIXER_VERSION_MAJOR_LINE) - unset(SDL2_MIXER_VERSION_MINOR_LINE) - unset(SDL2_MIXER_VERSION_PATCH_LINE) - unset(SDL2_MIXER_VERSION_MAJOR) - unset(SDL2_MIXER_VERSION_MINOR) - unset(SDL2_MIXER_VERSION_PATCH) +find_package(mpg123 QUIET) +if(MPG123_FOUND) + list(APPEND SDL2_MIXER_EXTRA_DEPS mpg123::mpg123) endif() -set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) -set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) +find_library(FLAC_LIBRARY + NAMES libFLAC FLAC + HINTS ${PC_SDL2_MIXER_LIBRARY_DIRS}) +if(FLAC_LIBRARY_FOUND) + list(APPEND SDL2_MIXER_EXTRA_DEPS ${FLAC_LIBRARY}) +endif() + +find_library(MODPLUG_LIBRARY + NAMES libmodplug modplug + HINTS ${PC_SDL2_MIXER_LIBRARY_DIRS}) +if(MODPLUG_LIBRARY_FOUND) + list(APPEND SDL2_MIXER_EXTRA_DEPS ${MODPLUG_LIBRARY}) +endif() include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SDL2_mixer + REQUIRED_VARS SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer - REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS - VERSION_VAR SDL2_MIXER_VERSION_STRING) +if(SDL2_MIXER_FOUND) + set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) -# for backward compatiblity -set(SDL2MIXER_LIBRARY ${SDL2_MIXER_LIBRARIES}) -set(SDL2MIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS}) -set(SDL2MIXER_FOUND ${SDL2_MIXER_FOUND}) + if(NOT SDL2_MIXER_LIBRARIES) + set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARIES}) + endif() + + if(NOT TARGET SDL2::MIXER) + add_library(SDL2::MIXER UNKNOWN IMPORTED) + set_target_properties(SDL2::MIXER PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_MIXER_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${SDL2_MIXER_EXTRA_DEPS}" + IMPORTED_LOCATION "${SDL2_MIXER_LIBRARY}") + endif() +endif() -mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) +mark_as_advanced(SDL2_MIXER_INCLUDE_DIR SDL2_MIXER_LIBRARY SDL2_MIXER_EXTRA_DEPS + MODPLUG_LIBRARY FLAC_LIBRARY OGG_LIBRARY VORBIS_LIBRARY) diff --git a/builds/cmake/Modules/FindSamplerate.cmake b/builds/cmake/Modules/FindSamplerate.cmake new file mode 100644 index 0000000000..a71d512467 --- /dev/null +++ b/builds/cmake/Modules/FindSamplerate.cmake @@ -0,0 +1,64 @@ +#.rst: +# FindSamplerate +# ----------- +# +# Find the Samplerate Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``Samplerate::Samplerate`` +# The ``Samplerate`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``SAMPLERATE_INCLUDE_DIRS`` +# where to find Samplerate headers. +# ``SAMPLERATE_LIBRARIES`` +# the libraries to link against to use Samplerate. +# ``SAMPLERATE_FOUND`` +# true if the Samplerate headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_SAMPLERATE QUIET samplerate) + +# Look for the header file. +find_path(SAMPLERATE_INCLUDE_DIR + NAMES samplerate.h + PATH_SUFFIXES libsamplerate samplerate + HINTS ${PC_SAMPLERATE_INCLUDE_DIRS}) + +# Look for the library. +# Allow SAMPLERATE_LIBRARY to be set manually, as the location of the Samplerate library +if(NOT SAMPLERATE_LIBRARY) + find_library(SAMPLERATE_LIBRARY + NAMES libsamplerate samplerate + HINTS ${PC_SAMPLERATE_LIBRARY_DIRS}) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Samplerate + REQUIRED_VARS SAMPLERATE_LIBRARY SAMPLERATE_INCLUDE_DIR) + +if(SAMPLERATE_FOUND) + set(SAMPLERATE_INCLUDE_DIRS ${SAMPLERATE_INCLUDE_DIR}) + + if(NOT SAMPLERATE_LIBRARIES) + set(SAMPLERATE_LIBRARIES ${SAMPLERATE_LIBRARIES}) + endif() + + if(NOT TARGET Samplerate::Samplerate) + add_library(Samplerate::Samplerate UNKNOWN IMPORTED) + set_target_properties(Samplerate::Samplerate PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SAMPLERATE_INCLUDE_DIRS}" + IMPORTED_LOCATION "${SAMPLERATE_LIBRARY}") + endif() +endif() + +mark_as_advanced(SAMPLERATE_INCLUDE_DIR SAMPLERATE_LIBRARY) diff --git a/builds/cmake/Modules/FindSndFile.cmake b/builds/cmake/Modules/FindSndFile.cmake deleted file mode 100644 index 289847ece0..0000000000 --- a/builds/cmake/Modules/FindSndFile.cmake +++ /dev/null @@ -1,10 +0,0 @@ -find_path(SNDFILE_INCLUDE_DIR sndfile.h) -find_library(SNDFILE_LIBRARY NAMES sndfile libsndfile) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(SndFile DEFAULT_MSG SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY) - -set(SNDFILE_INCLUDE_DIRS ${SNDFILE_INCLUDE_DIR}) -set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY}) - -mark_as_advanced(SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY) diff --git a/builds/cmake/Modules/FindVorbisfile.cmake b/builds/cmake/Modules/FindVorbisfile.cmake new file mode 100644 index 0000000000..22176267a6 --- /dev/null +++ b/builds/cmake/Modules/FindVorbisfile.cmake @@ -0,0 +1,74 @@ +#.rst: +# FindVorbisfile +# ----------- +# +# Find the Vorbisfile Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``Vorbisfile::VorbisFile`` +# The ``Vorbisfile`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``VORBISFILE_INCLUDE_DIRS`` +# where to find Vorbisfile headers. +# ``VORBISFILE_LIBRARIES`` +# the libraries to link against to use Vorbisfile. +# ``VORBISFILE_FOUND`` +# true if the Vorbisfile headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_VORBISFILE QUIET vorbisfile) + +# Look for the header file. +find_path(VORBISFILE_INCLUDE_DIR + NAMES vorbisfile.h + PATH_SUFFIXES vorbis + HINTS ${PC_VORBISFILE_INCLUDE_DIRS}) + +# Look for the library. +# Allow VORBISFILE_LIBRARY to be set manually, as the location of the Vorbisfile library +if(NOT VORBISFILE_LIBRARY) + find_library(VORBISFILE_LIBRARY + NAMES libvorbisfile vorbisfile + HINTS ${PC_VORBISFILE_LIBRARY_DIRS}) +endif() + +# Find additional dependencies +find_library(VORBIS_LIBRARY + NAMES libvorbis vorbis + HINTS ${PC_VORBISFILE_LIBRARY_DIRS}) + +find_library(OGG_LIBRARY + NAMES libogg ogg + HINTS ${PC_VORBISFILE_LIBRARY_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Vorbisfile + REQUIRED_VARS VORBISFILE_LIBRARY VORBISFILE_INCLUDE_DIR) + +if(VORBISFILE_FOUND) + set(VORBISFILE_INCLUDE_DIRS ${VORBISFILE_INCLUDE_DIR}) + + if(NOT VORBISFILE_LIBRARIES) + set(VORBISFILE_LIBRARIES ${VORBISFILE_LIBRARIES}) + endif() + + if(NOT TARGET Vorbisfile::Vorbisfile) + add_library(Vorbisfile::Vorbisfile UNKNOWN IMPORTED) + set_target_properties(Vorbisfile::Vorbisfile PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${VORBISFILE_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${VORBIS_LIBRARY};${OGG_LIBRARY}" + IMPORTED_LOCATION "${VORBISFILE_LIBRARY}") + endif() +endif() + +mark_as_advanced(VORBISFILE_INCLUDE_DIR VORBISFILE_LIBRARY OGG_LIBRARY VORBIS_LIBRARY) diff --git a/builds/cmake/Modules/FindWildMidi.cmake b/builds/cmake/Modules/FindWildMidi.cmake index 5958c85b6f..8104f2ec2d 100644 --- a/builds/cmake/Modules/FindWildMidi.cmake +++ b/builds/cmake/Modules/FindWildMidi.cmake @@ -1,10 +1,68 @@ -find_path(WILDMIDI_INCLUDE_DIR wildmidi_lib.h) -find_library(WILDMIDI_LIBRARY NAMES wildmidi libwildmidi WildMidi libWildMidi) +#.rst: +# FindWildMidi +# ----------- +# +# Find the WildMidi Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``WildMidi::WildMidi`` +# The ``WildMidi`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``WILDMIDI_INCLUDE_DIRS`` +# where to find WildMidi headers. +# ``WILDMIDI_LIBRARIES`` +# the libraries to link against to use WildMidi. +# ``WILDMIDI_FOUND`` +# true if the WildMidi headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_WILDMIDI QUIET wildmidi) + +# Look for the header file. +find_path(WILDMIDI_INCLUDE_DIR + NAMES wildmidi_lib.h + PATH_SUFFIXES libwildmidi wildmidi + HINTS ${PC_WILDMIDI_INCLUDE_DIRS}) + +# Look for the library. +# Allow WILDMIDI_LIBRARY to be set manually, as the location of the WildMidi library +if(NOT WILDMIDI_LIBRARY) + find_library(WILDMIDI_LIBRARY + NAMES libwildmidi wildmidi libWildMidi WildMidi + HINTS ${PC_WILDMIDI_LIBRARY_DIRS}) +endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(WildMidi DEFAULT_MSG WILDMIDI_INCLUDE_DIR WILDMIDI_LIBRARY) +find_package_handle_standard_args(WildMidi + REQUIRED_VARS WILDMIDI_LIBRARY WILDMIDI_INCLUDE_DIR) + +if(WILDMIDI_FOUND) + set(WILDMIDI_INCLUDE_DIRS ${WILDMIDI_INCLUDE_DIR}) + + if(NOT WILDMIDI_LIBRARIES) + set(WILDMIDI_LIBRARIES ${WILDMIDI_LIBRARIES}) + endif() -set(WILDMIDI_INCLUDE_DIRS ${WILDMIDI_INCLUDE_DIR}) -set(WILDMIDI_LIBRARIES ${WILDMIDI_LIBRARY}) + if(NOT TARGET WildMidi::WildMidi) + add_library(WildMidi::WildMidi UNKNOWN IMPORTED) + set_target_properties(WildMidi::WildMidi PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${WILDMIDI_INCLUDE_DIRS}" + IMPORTED_LOCATION "${WILDMIDI_LIBRARY}") + if(WIN32) + set_target_properties(WildMidi::WildMidi PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "WILDMIDI_STATIC=1") + endif() + endif() +endif() mark_as_advanced(WILDMIDI_INCLUDE_DIR WILDMIDI_LIBRARY) diff --git a/builds/cmake/Modules/FindXMP.cmake b/builds/cmake/Modules/FindXMP.cmake index 5e4127e02c..94e72d18f2 100644 --- a/builds/cmake/Modules/FindXMP.cmake +++ b/builds/cmake/Modules/FindXMP.cmake @@ -1,24 +1,68 @@ -include(FindPackageHandleStandardArgs) +#.rst: +# FindXMP +# ----------- +# +# Find the XMP Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``XMP::XMP`` +# The ``XMP`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``XMP_INCLUDE_DIRS`` +# where to find XMP headers. +# ``XMP_LIBRARIES`` +# the libraries to link against to use XMP. +# ``XMP_FOUND`` +# true if the XMP headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_XMP QUIET xmp) + +# Look for the header file. +find_path(XMP_INCLUDE_DIR + NAMES xmp.h + PATH_SUFFIXES libxmp xmp libxmp-lite xmp-lite + HINTS ${PC_XMP_INCLUDE_DIRS}) -find_path(XMP_INCLUDE_DIR_INTERNAL xmp.h) -find_library(XMP_LIBRARY xmp libxmp xmp-lite libxmp-lite) -if(EXISTS "${XMP_INCLUDE_DIR_INTERNAL}") - set(XMP_INCLUDE_DIR "${XMP_INCLUDE_DIR_INTERNAL}") -else() - find_path(XMP_INCLUDE_DIR_INTERNAL libxmp/xmp.h) - if(EXISTS "${XMP_INCLUDE_DIR_INTERNAL}") - set(XMP_INCLUDE_DIR "${XMP_INCLUDE_DIR_INTERNAL}/libxmp") - else() - find_path(XMP_INCLUDE_DIR_INTERNAL libxmp-lite/xmp.h) - if(EXISTS "${XMP_INCLUDE_DIR_INTERNAL}") - set(XMP_INCLUDE_DIR "${XMP_INCLUDE_DIR_INTERNAL}/libxmp-lite") - endif() - endif() +# Look for the library. +# Allow XMP_LIBRARY to be set manually, as the location of the XMP library +if(NOT XMP_LIBRARY) + find_library(XMP_LIBRARY + NAMES libxmp xmp libxmp-lite xmp-lite + HINTS ${PC_XMP_LIBRARY_DIRS}) endif() -find_package_handle_standard_args(XMP REQUIRED_VARS XMP_INCLUDE_DIR XMP_LIBRARY) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(XMP + REQUIRED_VARS XMP_LIBRARY XMP_INCLUDE_DIR) + +if(XMP_FOUND) + set(XMP_INCLUDE_DIRS ${XMP_INCLUDE_DIR}) -set(XMP_INCLUDE_DIRS ${XMP_INCLUDE_DIR}) -set(XMP_LIBRARIES ${XMP_LIBRARY}) + if(NOT XMP_LIBRARIES) + set(XMP_LIBRARIES ${XMP_LIBRARIES}) + endif() + + if(NOT TARGET XMP::XMP) + add_library(XMP::XMP UNKNOWN IMPORTED) + set_target_properties(XMP::XMP PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${XMP_INCLUDE_DIRS}" + IMPORTED_LOCATION "${XMP_LIBRARY}") + if(WIN32) + set_target_properties(XMP::XMP PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "BUILDING_STATIC=1") + endif() + endif() +endif() mark_as_advanced(XMP_INCLUDE_DIR XMP_LIBRARY) diff --git a/builds/cmake/Modules/Findliblcf.cmake b/builds/cmake/Modules/Findliblcf.cmake deleted file mode 100644 index 8932c9ae1e..0000000000 --- a/builds/cmake/Modules/Findliblcf.cmake +++ /dev/null @@ -1,13 +0,0 @@ -find_path(LIBLCF_INCLUDE_DIR_INTERNAL liblcf/reader_lcf.h) -find_library(LIBLCF_LIBRARY NAMES lcf liblcf) -if(EXISTS "${LIBLCF_INCLUDE_DIR_INTERNAL}") - set(LIBLCF_INCLUDE_DIR "${LIBLCF_INCLUDE_DIR_INTERNAL}/liblcf") -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(liblcf DEFAULT_MSG LIBLCF_INCLUDE_DIR LIBLCF_LIBRARY) - -set(LIBLCF_INCLUDE_DIRS ${LIBLCF_INCLUDE_DIR}) -set(LIBLCF_LIBRARIES ${LIBLCF_LIBRARY}) - -mark_as_advanced(LIBLCF_INCLUDE_DIR LIBLCF_LIBRARY) diff --git a/builds/cmake/Modules/Findmpg123.cmake b/builds/cmake/Modules/Findmpg123.cmake index 850d310875..7ad28a2190 100644 --- a/builds/cmake/Modules/Findmpg123.cmake +++ b/builds/cmake/Modules/Findmpg123.cmake @@ -1,10 +1,64 @@ -find_path(MPG123_INCLUDE_DIR mpg123.h) -find_library(MPG123_LIBRARY NAMES mpg123 libmpg123) +#.rst: +# Findmpg123 +# ----------- +# +# Find the mpg123 Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``mpg123::mpg123`` +# The ``mpg123`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``MPG123_INCLUDE_DIRS`` +# where to find mpg123 headers. +# ``MPG123_LIBRARIES`` +# the libraries to link against to use mpg123. +# ``MPG123_FOUND`` +# true if the mpg123 headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_MPG123 QUIET libmpg123) + +# Look for the header file. +find_path(MPG123_INCLUDE_DIR + NAMES mpg123.h + PATH_SUFFIXES libmpg123 mpg123 + HINTS ${PC_MPG123_INCLUDE_DIRS}) + +# Look for the library. +# Allow MPG123_LIBRARY to be set manually, as the location of the mpg123 library +if(NOT MPG123_LIBRARY) + find_library(MPG123_LIBRARY + NAMES libmpg123 mpg123 + HINTS ${PC_MPG123_LIBRARY_DIRS}) +endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(mpg123 DEFAULT_MSG MPG123_INCLUDE_DIR MPG123_LIBRARY) +find_package_handle_standard_args(mpg123 + REQUIRED_VARS MPG123_LIBRARY MPG123_INCLUDE_DIR) + +if(MPG123_FOUND) + set(MPG123_INCLUDE_DIRS ${MPG123_INCLUDE_DIR}) + + if(NOT MPG123_LIBRARIES) + set(MPG123_LIBRARIES ${MPG123_LIBRARIES}) + endif() -set(MPG123_INCLUDE_DIRS ${MPG123_INCLUDE_DIR}) -set(MPG123_LIBRARIES ${MPG123_LIBRARY}) + if(NOT TARGET mpg123::mpg123) + add_library(mpg123::mpg123 UNKNOWN IMPORTED) + set_target_properties(mpg123::mpg123 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${MPG123_INCLUDE_DIRS}" + IMPORTED_LOCATION "${MPG123_LIBRARY}") + endif() +endif() mark_as_advanced(MPG123_INCLUDE_DIR MPG123_LIBRARY) diff --git a/builds/cmake/Modules/Findspeexdsp.cmake b/builds/cmake/Modules/Findspeexdsp.cmake index 176e417532..5dc8942b78 100644 --- a/builds/cmake/Modules/Findspeexdsp.cmake +++ b/builds/cmake/Modules/Findspeexdsp.cmake @@ -1,10 +1,64 @@ -find_path(SPEEXDSP_INCLUDE_DIR speex/speex_resampler.h) -find_library(SPEEXDSP_LIBRARY NAMES speexdsp libspeexdsp) +#.rst: +# Findspeexdsp +# ----------- +# +# Find the speexdsp Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``speexdsp::speexdsp`` +# The ``speexdsp`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``SPEEXDSP_INCLUDE_DIRS`` +# where to find speexdsp headers. +# ``SPEEXDSP_LIBRARIES`` +# the libraries to link against to use speexdsp. +# ``SPEEXDSP_FOUND`` +# true if the speexdsp headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_SPEEXDSP QUIET speexdsp) + +# Look for the header file. +find_path(SPEEXDSP_INCLUDE_DIR + NAMES speex_resampler.h + PATH_SUFFIXES speex + HINTS ${PC_SPEEXDSP_INCLUDE_DIRS}) + +# Look for the library. +# Allow SPEEXDSP_LIBRARY to be set manually, as the location of the speexdsp library +if(NOT SPEEXDSP_LIBRARY) + find_library(SPEEXDSP_LIBRARY + NAMES libspeexdsp speexdsp + HINTS ${PC_SPEEXDSP_LIBRARY_DIRS}) +endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(speexdsp DEFAULT_MSG SPEEXDSP_INCLUDE_DIR SPEEXDSP_LIBRARY) +find_package_handle_standard_args(speexdsp + REQUIRED_VARS SPEEXDSP_LIBRARY SPEEXDSP_INCLUDE_DIR) + +if(SPEEXDSP_FOUND) + set(SPEEXDSP_INCLUDE_DIRS ${SPEEXDSP_INCLUDE_DIR}) + + if(NOT SPEEXDSP_LIBRARIES) + set(SPEEXDSP_LIBRARIES ${SPEEXDSP_LIBRARIES}) + endif() -set(SPEEXDSP_INCLUDE_DIRS ${SPEEXDSP_INCLUDE_DIR}) -set(SPEEXDSP_LIBRARIES ${SPEEXDSP_LIBRARY}) + if(NOT TARGET speexdsp::speexdsp) + add_library(speexdsp::speexdsp UNKNOWN IMPORTED) + set_target_properties(speexdsp::speexdsp PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SPEEXDSP_INCLUDE_DIRS}" + IMPORTED_LOCATION "${SPEEXDSP_LIBRARY}") + endif() +endif() mark_as_advanced(SPEEXDSP_INCLUDE_DIR SPEEXDSP_LIBRARY) diff --git a/builds/cmake/Modules/PlayerFindPackage.cmake b/builds/cmake/Modules/PlayerFindPackage.cmake new file mode 100644 index 0000000000..f5ff5d3f7b --- /dev/null +++ b/builds/cmake/Modules/PlayerFindPackage.cmake @@ -0,0 +1,63 @@ +#.rst: +# PlayerFindPackage +# ----------------- +# +# Helper function that conditionally invokes find_package and automatically +# adds targets and compile time definitions. +# +# Required Arguments +# ^^^^^^^^^^^^^^^^^^ +# +# ``NAME`` (String) +# Name of the library to search. The name must match FindNAME.cmake. +# ``TARGET`` (String) +# Target to import when the library was found. +# +# Optional Arguments +# ^^^^^^^^^^^^^^^^^^ +# +# ``CONDITION`` (Bool) +# When this variable is set to OFF the package is skipped. +# Allows disabling of libraries via the CMake command line. +# ``DEFINITION`` (String) +# Preprocessor definition which is set to 1 when the library was found. +# ``FOUND`` (String) +# Specifies the variable name of the FOUND variable that is checked. +# When missing, the variable is the ``NAME`` argument in upper case. +# ``REQUIRED`` (without arguments) +# The library is required. Forwarded to find_package. +# +# Return variables +# ^^^^^^^^^^^^^^^^ +# +# ``NAME_FOUND`` +# Set to TRUE when the library was found. NAME is the ``NAME`` argument in +# upper case or the ``FOUND`` argument when specified. +# + +function(player_find_package) + cmake_parse_arguments(PARSE_ARGV 0 PLAYER_FIND_PACKAGE "REQUIRED" "NAME;CONDITION;DEFINITION;FOUND;TARGET" "") + string(TOUPPER ${PLAYER_FIND_PACKAGE_NAME} FIND_PACKAGE_NAME) + + set(IS_REQUIRED "") + if(PLAYER_FIND_PACKAGE_REQUIRED) + set(IS_REQUIRED "REQUIRED") + endif() + + if(PLAYER_FIND_PACKAGE_FOUND) + set(FIND_PACKAGE_NAME ${PLAYER_FIND_PACKAGE_FOUND}) + endif() + + # Assume "true" when Condition is empty, otherwise dereference the condition variable + if((NOT PLAYER_FIND_PACKAGE_CONDITION) OR (${PLAYER_FIND_PACKAGE_CONDITION})) + find_package(${PLAYER_FIND_PACKAGE_NAME} ${IS_REQUIRED}) + if (${${FIND_PACKAGE_NAME}_FOUND}) + target_link_libraries(${PROJECT_NAME} ${PLAYER_FIND_PACKAGE_TARGET}) + if(PLAYER_FIND_PACKAGE_DEFINITION) + target_compile_definitions(${PROJECT_NAME} PUBLIC ${PLAYER_FIND_PACKAGE_DEFINITION}=1) + endif() + endif() + endif() + + set(${FIND_PACKAGE_NAME}_FOUND ${${FIND_PACKAGE_NAME}_FOUND} PARENT_SCOPE) +endfunction()