Skip to content

Commit

Permalink
Update CMakeLists.txt, add option for docs
Browse files Browse the repository at this point in the history
Add SDLSOUND_BUILD_DOCS option to control whether build docs
  • Loading branch information
Sepcnt authored Jan 18, 2024
1 parent c563941 commit 4b2ef15
Showing 1 changed file with 49 additions and 32 deletions.
81 changes: 49 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# fails, define SDL2_DIR environment variable to point to your SDL2
# installation.

set(SDLSOUND_VERSION 2.0.3)
set(SDLSOUND_VERSION 2.0.2)

# Increment this if/when we break backwards compatibility.
set(SDLSOUND_SOVERSION 2)
Expand Down Expand Up @@ -215,8 +215,14 @@ if(SDLSOUND_BUILD_STATIC)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
target_include_directories(SDL2_sound-static PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_link_libraries(SDL2_sound-static PRIVATE "$<BUILD_INTERFACE:${SDL2_LIBRARIES}>" ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
if(TARGET SDL2::SDL2-static)
get_target_property(_sdl2_include_dir SDL2::SDL2-static INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(SDL2_sound-static PUBLIC "$<BUILD_INTERFACE:${_sdl2_include_dir}>")
target_link_libraries(SDL2_sound-static PRIVATE $<BUILD_INTERFACE:SDL2::SDL2-static> ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
else()
target_include_directories(SDL2_sound-static PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_link_libraries(SDL2_sound-static PRIVATE "$<BUILD_INTERFACE:${SDL2_LIBRARIES}>" ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
endif()
set(SDLSOUND_LIB_TARGET SDL2_sound-static)
endif()

Expand All @@ -243,8 +249,14 @@ if(SDLSOUND_BUILD_SHARED)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)
target_include_directories(SDL2_sound PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_link_libraries(SDL2_sound PRIVATE "$<BUILD_INTERFACE:${SDL2_LIBRARIES}>" ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
if(TARGET SDL2::SDL2)
get_target_property(_sdl2_include_dir SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(SDL2_sound PUBLIC "$<BUILD_INTERFACE:${_sdl2_include_dir}>")
target_link_libraries(SDL2_sound PRIVATE $<BUILD_INTERFACE:SDL2::SDL2> ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
else()
target_include_directories(SDL2_sound PUBLIC "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
target_link_libraries(SDL2_sound PRIVATE "$<BUILD_INTERFACE:${SDL2_LIBRARIES}>" ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
endif()
set(SDLSOUND_LIB_TARGET SDL2_sound)
endif()

Expand Down Expand Up @@ -296,7 +308,11 @@ if(SDLSOUND_BUILD_TEST)
endif()
endif()

set(PKGCONFIG_INSTALLDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
if(FREEBSD)
set(PKGCONFIG_INSTALLDIR "libdata/pkgconfig")
else()
set(PKGCONFIG_INSTALLDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()

if(WIN32 AND NOT MINGW)
set(SDLSOUND_INSTALL_CMAKEDIR_DEFAULT "cmake")
Expand Down Expand Up @@ -353,27 +369,32 @@ install(FILES src/SDL_sound.h
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/SDL2_sound.pc
DESTINATION "${PKGCONFIG_INSTALLDIR}")

find_package(Doxygen)
if(DOXYGEN_FOUND)
set(SDLSOUND_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
"${SDLSOUND_OUTPUT_DOXYFILE}"
COPYONLY
)
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${SDLSOUND_VERSION}\"\n")
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")

add_custom_target(
SDL2_sound-docs
${DOXYGEN_EXECUTABLE} "${SDLSOUND_OUTPUT_DOXYFILE}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building documentation..."
)
else()
message(STATUS "Doxygen not found. You won't be able to build documentation.")
option(SDLSOUND_BUILD_DOCS "Build documentation" TRUE)
mark_as_advanced(SDLSOUND_BUILD_DOCS)

if(SDLSOUND_BUILD_DOCS)
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(SDLSOUND_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
"${SDLSOUND_OUTPUT_DOXYFILE}"
COPYONLY
)
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${SDLSOUND_VERSION}\"\n")
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")

add_custom_target(
SDL2_sound-docs
${DOXYGEN_EXECUTABLE} "${SDLSOUND_OUTPUT_DOXYFILE}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building documentation..."
)
else()
message(STATUS "Doxygen not found. You won't be able to build documentation.")
endif()
endif()

configure_file(
Expand Down Expand Up @@ -412,10 +433,6 @@ message_bool_option("COREAUDIO support" SDLSOUND_DECODER_COREAUDIO)
message_bool_option("Build static library" SDLSOUND_BUILD_STATIC)
message_bool_option("Build shared library" SDLSOUND_BUILD_SHARED)
message_bool_option("Build stdio test program" SDLSOUND_BUILD_TEST)

# Make sure SDL2_sound::SDL2_sound always exists
if(TARGET SDL2_sound::SDL2_sound-static AND NOT TARGET SDL2_sound::SDL2_sound)
add_library(SDL2_sound::SDL2_sound ALIAS SDL2_sound-static)
endif()
message_bool_option("Build documentation" SDLSOUND_BUILD_DOCS)

# end of CMakeLists.txt

0 comments on commit 4b2ef15

Please sign in to comment.