Patch out include and pkgconfig files for external libraries

This commit is contained in:
Lukas Dürrenberger 2024-12-12 23:24:49 +01:00
parent cb38877a8c
commit 2e8dc0f94f
6 changed files with 25 additions and 7 deletions

View File

@ -91,6 +91,9 @@ else()
set(BUILD_UTILS OFF) set(BUILD_UTILS OFF)
set(BUILD_DOCS OFF) set(BUILD_DOCS OFF)
set(INSTALL_MANPAGES OFF) set(INSTALL_MANPAGES OFF)
set(INSTALL_DOCS OFF)
set(INSTALL_PKG_CONFIG_MODULE OFF)
set(INSTALL_PKGCONFIG_MODULES OFF)
set(WITH_FORTIFY_SOURCE OFF) set(WITH_FORTIFY_SOURCE OFF)
set(WITH_STACK_PROTECTOR OFF) set(WITH_STACK_PROTECTOR OFF)
set(WITH_AVX OFF) # LLVM/Clang on Windows has issues with AVX2 set(WITH_AVX OFF) # LLVM/Clang on Windows has issues with AVX2
@ -99,23 +102,26 @@ else()
GIT_REPOSITORY https://github.com/xiph/ogg.git GIT_REPOSITORY https://github.com/xiph/ogg.git
GIT_TAG v1.3.5 GIT_TAG v1.3.5
GIT_SHALLOW ON GIT_SHALLOW ON
# patch CMAKE_DEBUG_POSTFIX into the Ogg CMake configuration # patch out parts we don't want of the Ogg CMake configuration
# - installing headers & pkgconfig files
# - add CMAKE_DEBUG_POSTFIX
PATCH_COMMAND ${CMAKE_COMMAND} -DOGG_DIR=${FETCHCONTENT_BASE_DIR}/ogg-src -P ${PROJECT_SOURCE_DIR}/tools/ogg/PatchOgg.cmake) PATCH_COMMAND ${CMAKE_COMMAND} -DOGG_DIR=${FETCHCONTENT_BASE_DIR}/ogg-src -P ${PROJECT_SOURCE_DIR}/tools/ogg/PatchOgg.cmake)
FetchContent_Declare(flac FetchContent_Declare(flac
GIT_REPOSITORY https://github.com/xiph/flac.git GIT_REPOSITORY https://github.com/xiph/flac.git
GIT_TAG 1.4.3 GIT_TAG 1.4.3
GIT_SHALLOW ON GIT_SHALLOW ON
# patch out the annoying parts of the FLAC CMake configuration: # patch out parts we don't want of the FLAC CMake configuration:
# - adding unnecessary libraries that aren't even used # - adding unnecessary libraries that aren't even used
# - installing FLAC++ headers even though BUILD_CXXLIBS is OFF # - installing headers & pkgconfig files
# - add CMAKE_DEBUG_POSTFIX # - add CMAKE_DEBUG_POSTFIX
PATCH_COMMAND ${CMAKE_COMMAND} -DFLAC_DIR=${FETCHCONTENT_BASE_DIR}/flac-src -P ${PROJECT_SOURCE_DIR}/tools/flac/PatchFLAC.cmake) PATCH_COMMAND ${CMAKE_COMMAND} -DFLAC_DIR=${FETCHCONTENT_BASE_DIR}/flac-src -P ${PROJECT_SOURCE_DIR}/tools/flac/PatchFLAC.cmake)
FetchContent_Declare(vorbis FetchContent_Declare(vorbis
GIT_REPOSITORY https://github.com/xiph/vorbis.git GIT_REPOSITORY https://github.com/xiph/vorbis.git
GIT_TAG v1.3.7 GIT_TAG v1.3.7
GIT_SHALLOW ON GIT_SHALLOW ON
# patch out the annoying parts of the Vorbis CMake configuration: # patch out parts we don't want of the Vorbis CMake configuration:
# - Vorbis doesn't check if the Ogg::ogg target exists before calling find_package # - Vorbis doesn't check if the Ogg::ogg target exists before calling find_package
# - installing headers & pkgconfig files
# - add CMAKE_DEBUG_POSTFIX # - add CMAKE_DEBUG_POSTFIX
PATCH_COMMAND ${CMAKE_COMMAND} -DVORBIS_DIR=${FETCHCONTENT_BASE_DIR}/vorbis-src -P ${PROJECT_SOURCE_DIR}/tools/vorbis/PatchVorbis.cmake) PATCH_COMMAND ${CMAKE_COMMAND} -DVORBIS_DIR=${FETCHCONTENT_BASE_DIR}/vorbis-src -P ${PROJECT_SOURCE_DIR}/tools/vorbis/PatchVorbis.cmake)
FetchContent_MakeAvailable(ogg flac vorbis) FetchContent_MakeAvailable(ogg flac vorbis)

View File

@ -119,6 +119,7 @@ else()
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(BUILD_SHARED_LIBS OFF) set(BUILD_SHARED_LIBS OFF)
set(SKIP_INSTALL_HEADERS ON)
set(FT_DISABLE_ZLIB ON) set(FT_DISABLE_ZLIB ON)
set(FT_DISABLE_BZIP2 ON) set(FT_DISABLE_BZIP2 ON)
set(FT_DISABLE_PNG ON) set(FT_DISABLE_PNG ON)
@ -129,7 +130,10 @@ else()
FetchContent_Declare(Freetype FetchContent_Declare(Freetype
GIT_REPOSITORY https://github.com/freetype/freetype.git GIT_REPOSITORY https://github.com/freetype/freetype.git
GIT_TAG VER-2-13-2 GIT_TAG VER-2-13-2
GIT_SHALLOW ON) GIT_SHALLOW ON
# patch out parts we don't want of the FreeType CMake configuration
# - installing pkgconfig files
PATCH_COMMAND ${CMAKE_COMMAND} -DFREETYPE_DIR=${FETCHCONTENT_BASE_DIR}/freetype-src -P ${PROJECT_SOURCE_DIR}/tools/freetype/PatchFreetype.cmake)
FetchContent_MakeAvailable(Freetype) FetchContent_MakeAvailable(Freetype)
set_target_properties(freetype PROPERTIES FOLDER "Dependencies") set_target_properties(freetype PROPERTIES FOLDER "Dependencies")

View File

@ -1,10 +1,10 @@
# prevent FLAC from adding stuff that we don't use
file(READ "${FLAC_DIR}/src/CMakeLists.txt" FLAC_SRC_CMAKELISTS_CONTENTS) file(READ "${FLAC_DIR}/src/CMakeLists.txt" FLAC_SRC_CMAKELISTS_CONTENTS)
string(REGEX REPLACE "\nadd_subdirectory\\(\"share/" "\n\#add_subdirectory(\"share/" FLAC_SRC_CMAKELISTS_CONTENTS "${FLAC_SRC_CMAKELISTS_CONTENTS}") string(REGEX REPLACE "\nadd_subdirectory\\(\"share/" "\n\#add_subdirectory(\"share/" FLAC_SRC_CMAKELISTS_CONTENTS "${FLAC_SRC_CMAKELISTS_CONTENTS}")
file(WRITE "${FLAC_DIR}/src/CMakeLists.txt" "${FLAC_SRC_CMAKELISTS_CONTENTS}") file(WRITE "${FLAC_DIR}/src/CMakeLists.txt" "${FLAC_SRC_CMAKELISTS_CONTENTS}")
file(READ "${FLAC_DIR}/CMakeLists.txt" FLAC_CMAKELISTS_CONTENTS) file(READ "${FLAC_DIR}/CMakeLists.txt" FLAC_CMAKELISTS_CONTENTS)
string(REPLACE "set_target_properties(FLAC grabbag getopt replaygain_analysis replaygain_synthesis utf8 PROPERTIES FOLDER Libraries)" "" FLAC_CMAKELISTS_CONTENTS "${FLAC_CMAKELISTS_CONTENTS}") string(REPLACE "set_target_properties(FLAC grabbag getopt replaygain_analysis replaygain_synthesis utf8 PROPERTIES FOLDER Libraries)" "" FLAC_CMAKELISTS_CONTENTS "${FLAC_CMAKELISTS_CONTENTS}")
string(REPLACE "install(FILES \${FLAC_HEADERS} DESTINATION \"\${CMAKE_INSTALL_INCLUDEDIR}/FLAC\")" "" FLAC_CMAKELISTS_CONTENTS "${FLAC_CMAKELISTS_CONTENTS}")
string(REPLACE "install(FILES \${FLAC++_HEADERS} DESTINATION \"\${CMAKE_INSTALL_INCLUDEDIR}/FLAC++\")" "" FLAC_CMAKELISTS_CONTENTS "${FLAC_CMAKELISTS_CONTENTS}") string(REPLACE "install(FILES \${FLAC++_HEADERS} DESTINATION \"\${CMAKE_INSTALL_INCLUDEDIR}/FLAC++\")" "" FLAC_CMAKELISTS_CONTENTS "${FLAC_CMAKELISTS_CONTENTS}")
string(REPLACE "\n\nadd_subdirectory(\"src\")" "\nset(CMAKE_DEBUG_POSTFIX d)\nadd_subdirectory(\"src\")" FLAC_CMAKELISTS_CONTENTS "${FLAC_CMAKELISTS_CONTENTS}") string(REPLACE "\n\nadd_subdirectory(\"src\")" "\nset(CMAKE_DEBUG_POSTFIX d)\nadd_subdirectory(\"src\")" FLAC_CMAKELISTS_CONTENTS "${FLAC_CMAKELISTS_CONTENTS}")
file(WRITE "${FLAC_DIR}/CMakeLists.txt" "${FLAC_CMAKELISTS_CONTENTS}") file(WRITE "${FLAC_DIR}/CMakeLists.txt" "${FLAC_CMAKELISTS_CONTENTS}")

View File

@ -0,0 +1,3 @@
file(READ "${FREETYPE_DIR}/CMakeLists.txt" FREETYPE_CMAKELISTS_CONTENTS)
string(REPLACE " install(\n FILES \${PROJECT_BINARY_DIR}/freetype2.pc\n DESTINATION \${CMAKE_INSTALL_LIBDIR}/pkgconfig\n COMPONENT pkgconfig)" "" FREETYPE_CMAKELISTS_CONTENTS "${FREETYPE_CMAKELISTS_CONTENTS}")
file(WRITE "${FREETYPE_DIR}/CMakeLists.txt" "${FREETYPE_CMAKELISTS_CONTENTS}")

View File

@ -1,3 +1,4 @@
file(READ "${OGG_DIR}/CMakeLists.txt" OGG_CMAKELISTS_CONTENTS) file(READ "${OGG_DIR}/CMakeLists.txt" OGG_CMAKELISTS_CONTENTS)
string(REPLACE "\n\nadd_library(ogg" "\nset(CMAKE_DEBUG_POSTFIX d)\nadd_library(ogg" OGG_CMAKELISTS_CONTENTS "${OGG_CMAKELISTS_CONTENTS}") string(REPLACE "\n\nadd_library(ogg" "\nset(CMAKE_DEBUG_POSTFIX d)\nadd_library(ogg" OGG_CMAKELISTS_CONTENTS "${OGG_CMAKELISTS_CONTENTS}")
string(REPLACE "PUBLIC_HEADER \"\${OGG_HEADERS}\"" "" OGG_CMAKELISTS_CONTENTS "${OGG_CMAKELISTS_CONTENTS}")
file(WRITE "${OGG_DIR}/CMakeLists.txt" "${OGG_CMAKELISTS_CONTENTS}") file(WRITE "${OGG_DIR}/CMakeLists.txt" "${OGG_CMAKELISTS_CONTENTS}")

View File

@ -1,5 +1,9 @@
# help Vorbis find the Ogg::Ogg target that FetchContent provides
file(READ "${VORBIS_DIR}/CMakeLists.txt" VORBIS_CMAKELISTS_CONTENTS) file(READ "${VORBIS_DIR}/CMakeLists.txt" VORBIS_CMAKELISTS_CONTENTS)
string(REPLACE "find_package(Ogg REQUIRED)" "set(OGG_LIBRARIES Ogg::ogg)" VORBIS_CMAKELISTS_CONTENTS "${VORBIS_CMAKELISTS_CONTENTS}") string(REPLACE "find_package(Ogg REQUIRED)" "set(OGG_LIBRARIES Ogg::ogg)" VORBIS_CMAKELISTS_CONTENTS "${VORBIS_CMAKELISTS_CONTENTS}")
string(REPLACE "\n\nadd_subdirectory(lib)" "\nset(CMAKE_DEBUG_POSTFIX d)\nadd_subdirectory(lib)" VORBIS_CMAKELISTS_CONTENTS "${VORBIS_CMAKELISTS_CONTENTS}") string(REPLACE "\n\nadd_subdirectory(lib)" "\nset(CMAKE_DEBUG_POSTFIX d)\nadd_subdirectory(lib)" VORBIS_CMAKELISTS_CONTENTS "${VORBIS_CMAKELISTS_CONTENTS}")
string(REPLACE "install(\n FILES\n \${CMAKE_CURRENT_BINARY_DIR}/vorbis.pc\n \${CMAKE_CURRENT_BINARY_DIR}/vorbisenc.pc\n \${CMAKE_CURRENT_BINARY_DIR}/vorbisfile.pc\n DESTINATION\n \${CMAKE_INSTALL_LIBDIR}/pkgconfig\n)" "" VORBIS_CMAKELISTS_CONTENTS "${VORBIS_CMAKELISTS_CONTENTS}")
file(WRITE "${VORBIS_DIR}/CMakeLists.txt" "${VORBIS_CMAKELISTS_CONTENTS}") file(WRITE "${VORBIS_DIR}/CMakeLists.txt" "${VORBIS_CMAKELISTS_CONTENTS}")
file(READ "${VORBIS_DIR}/lib/CMakeLists.txt" VORBISLIB_CMAKELISTS_CONTENTS)
string(REPLACE "install(FILES \${VORBIS_PUBLIC_HEADERS} DESTINATION \${CMAKE_INSTALL_FULL_INCLUDEDIR}/vorbis)" "" VORBISLIB_CMAKELISTS_CONTENTS "${VORBISLIB_CMAKELISTS_CONTENTS}")
file(WRITE "${VORBIS_DIR}/lib/CMakeLists.txt" "${VORBISLIB_CMAKELISTS_CONTENTS}")