#!/usr/bin/cmake cmake_minimum_required (VERSION 3.18) # ------------------------------------------------------------------------------------------------- project( OGG VERSION 1.3.5 DESCRIPTION "Audio container commonly used for OPUS and Vorbis streams (and also FLAC)" ) include("../../BuildSystem/cmake/cplusplus.cmake") # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/downloads/libogg-1.3.5.tar.gz) message(STATUS "Downloading OGG sources") file( DOWNLOAD https://ftp.osuosl.org/pub/xiph/releases/ogg/libogg-1.3.5.tar.gz ${PROJECT_SOURCE_DIR}/downloads/libogg-1.3.5.tar.gz SHOW_PROGRESS EXPECTED_HASH SHA256=0eb4b4b9420a0f51db142ba3f9c64b333f826532dc0f48c6410ae51f4799b664 STATUS DOWNLOAD_STATUS ) if(NOT DOWNLOAD_STATUS EQUAL 0) file(REMOVE ${PROJECT_SOURCE_DIR}/downloads/libogg-1.3.5.tar.gz) message(FATAL_ERROR "Download failed, stopping build (error ${DOWNLOAD_STATUS})") endif() endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS ${PROJECT_SOURCE_DIR}/build) message(STATUS "Extracting OGG sources") file( ARCHIVE_EXTRACT INPUT ${PROJECT_SOURCE_DIR}/downloads/libogg-1.3.5.tar.gz DESTINATION ${CMAKE_BINARY_DIR}/extract ) file( RENAME ${CMAKE_BINARY_DIR}/extract/libogg-1.3.5 ${PROJECT_SOURCE_DIR}/build ) endif() file( COPY "${PROJECT_SOURCE_DIR}/config.h" DESTINATION "${PROJECT_SOURCE_DIR}/build/include/" ) # ------------------------------------------------------------------------------------------------- set( sourceFiles "build/src/bitwise.c" "build/src/framing.c" ) file( GLOB_RECURSE headerFiles CONFIGURE_DEPENDS "build/include/*.h" ) # ------------------------------------------------------------------------------------------------- add_library(OGG STATIC) add_library(OGG::Static ALIAS OGG) target_compile_definitions( OGG PRIVATE HAVE_CONFIG_H ) target_include_directories( OGG PUBLIC "build/include/" # PRIVATE "build/src/libOGG/include/" ) target_sources( OGG PUBLIC ${headerFiles} PRIVATE ${sourceFiles} ) #set_target_properties(OGG PROPERTIES PREFIX "") set_target_properties(OGG PROPERTIES OUTPUT_NAME "ogg") # ------------------------------------------------------------------------------------------------- #set_property(GLOBAL PROPERTY QUIET_INSTALL ON) #install( # DIRECTORY build/include/ # DESTINATION ${PROJECT_SOURCE_DIR}/Include #) install( TARGETS OGG ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/bin/${NUCLEX_COMPILER_TAG} ) # ------------------------------------------------------------------------------------------------- file( WRITE "${PROJECT_SOURCE_DIR}/OGGConfig.cmake" "#!/usr/bin/cmake # Configuration to include OGG in a CMake-based project. If you want to # reference OGG as an externally compiled static library, do this: # # set(OGG_DIR \"../ThirdParty/ogg\") # find_package(OGG REQUIRED CONFIG) # # target_link_libraries( # MyAwesomeProject # PRIVATE GTest::Static # PRIVATE GTest::Main # ) # # Alternatively, if you want to build OGG together with your project, # use the normal CMakeLists.txt with CMake's add_subdirectory() command: # # add_subdirectory( # \"\${PROJECT_SOURCE_DIR}/../ThirdParty/ogg\" # \"\${CMAKE_BINARY_DIR}/ogg\" # ) # # target_link_libraries( # MyAwesomeProject # PRIVATE OGG # PRIVATE OGGMain # ) # # ------------------------------------------------------------------------------------------------- if(NOT DEFINED NUCLEX_COMPILER_TAG) message( FATAL_ERROR \"NUCLEX_COMPILER_TAG not defined! Include cplusplus.cmake before importing this package \\ in order to generate a tag identifying the platform/compiler/architecture/variant!\" ) endif() # ------------------------------------------------------------------------------------------------- if(NOT EXISTS \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}\") # TODO: Warn and link release build when compiling in debug mode # TODO: Warn and link build for older compiler version if found message( FATAL_ERROR \"Directory '\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}' not found. \\ Please either build and install this project before importing it via \\ find_package() or use this project's main CMakeFiles.txt via add_subdirectory()!\" ) endif() # ------------------------------------------------------------------------------------------------- add_library(OGG::Static STATIC IMPORTED) add_library(OGG::Main STATIC IMPORTED) # This may cause warnings on recent GCC versions (10.0.0+?) with LTO because GCC detects # that the headers used during build (residing in build/) are not the same used when # linking the library (copies resising in Include/). # # CMake doesn't run the install step during build, so the only way to get the headers # in place before building would be by copying them rather than installing them. set_target_properties( OGG::Static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"CXX\" ) set_target_properties( OGG::Main PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"\${CMAKE_CURRENT_LIST_DIR}/Include\" IMPORTED_LINK_INTERFACE_LANGUAGES \"CXX\" ) if(WIN32) set_target_properties( OGG::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/ogg.lib\" ) else() set_target_properties( OGG::Static PROPERTIES IMPORTED_LOCATION \"\${CMAKE_CURRENT_LIST_DIR}/bin/\${NUCLEX_COMPILER_TAG}/libogg.a\" ) endif() message(STATUS \"Imported OGG targets with binaries in '\${CMAKE_CURRENT_LIST_DIR}'\")" ) # -------------------------------------------------------------------------------------------------