Add WITH_* switchs to CMake to optional features

This commit is contained in:
wangqr 2019-09-08 07:12:19 -04:00
parent 4a874de442
commit 97792e15a8

View file

@ -431,6 +431,13 @@ add_executable(Aegisub WIN32
target_link_libraries(Aegisub ${CMAKE_DL_LIBS} libaegisub luabins luajit resrc csri)
target_compile_definitions(Aegisub PRIVATE CMAKE_BUILD)
set(WITH_BUILD_CREDIT OFF CACHE BOOL "Whether show build credit in about dialog")
if(WITH_BUILD_CREDIT)
set(BUILD_CREDIT "" CACHE STRING "Build credit shown in about dialog")
else()
unset(BUILD_CREDIT CACHE)
endif()
if (MSVC)
set_target_properties(libaegisub PROPERTIES COMPILE_FLAGS "/Yu${PROJECT_SOURCE_DIR}/libaegisub/lagi_pre.h" COMPILE_FLAGS "/FI${PROJECT_SOURCE_DIR}/libaegisub/lagi_pre.h")
else(MSVC)
@ -500,49 +507,82 @@ find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
target_link_libraries (Aegisub ${ZLIB_LIBRARIES})
find_package(ALSA)
if (ALSA_FOUND)
set(WITH_ALSA ON CACHE BOOL "Enable ALSA support")
if(WITH_ALSA)
find_package(ALSA)
if(NOT ALSA_FOUND)
set(WITH_ALSA OFF CACHE BOOL "Enable ALSA support" FORCE)
endif()
endif()
if(WITH_ALSA)
include_directories(${ALSA_INCLUDE_DIRS})
target_link_libraries (Aegisub ${ALSA_LIBRARIES})
add_definitions("-DWITH_ALSA")
target_sources(Aegisub PRIVATE src/audio_player_alsa.cpp)
endif(ALSA_FOUND)
endif()
find_package(AviSynth)
if (AviSynth_FOUND)
set(WITH_AVISYNTH ON CACHE BOOL "Enable AviSynth support")
if(WITH_AVISYNTH)
find_package(AviSynth)
if(NOT AviSynth_FOUND)
set(WITH_AVISYNTH OFF CACHE BOOL "Enable AviSynth support" FORCE)
endif()
endif()
if(WITH_AVISYNTH)
target_compile_definitions(Aegisub PRIVATE "WITH_AVISYNTH" "AVS_LINKAGE_DLLIMPORT")
target_include_directories(Aegisub PRIVATE ${AviSynth_INCLUDE_DIRS})
target_link_libraries(Aegisub Vfw32 ${AviSynth_LIBRARIES})
target_sources(Aegisub PRIVATE src/audio_provider_avs.cpp src/avisynth_wrap.cpp src/video_provider_avs.cpp)
endif (AviSynth_FOUND)
endif()
target_compile_definitions(Aegisub PRIVATE "WITH_CSRI")
target_sources(Aegisub PRIVATE src/subtitles_provider_csri.cpp)
set_property(SOURCE src/subtitles_provider_csri.cpp PROPERTY INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/vendor/csri/include")
set(WITH_CSRI ON CACHE BOOL "Enable CSRI support")
if(WITH_CSRI)
target_compile_definitions(Aegisub PRIVATE "WITH_CSRI")
target_sources(Aegisub PRIVATE src/subtitles_provider_csri.cpp)
set_property(SOURCE src/subtitles_provider_csri.cpp PROPERTY INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/vendor/csri/include")
endif()
if(MSVC)
if(WIN32)
target_link_libraries (Aegisub dsound)
add_definitions("-DWITH_DIRECTSOUND")
target_sources(Aegisub PRIVATE src/audio_player_dsound.cpp src/audio_player_dsound2.cpp)
endif(MSVC)
endif()
find_package(FFMS2)
if (FFMS2_FOUND)
set(WITH_FFMS2 ON CACHE BOOL "Enable FFMS2 support")
if(WITH_FFMS2)
find_package(FFMS2)
if(NOT FFMS2_FOUND)
set(WITH_FFMS2 OFF CACHE BOOL "Enable FFMS2 support" FORCE)
endif()
endif()
if(WITH_FFMS2)
include_directories(${FFMS2_INCLUDE_DIRS})
target_link_libraries (Aegisub ${FFMS2_LIBRARIES})
add_definitions("-DWITH_FFMS2")
target_sources(Aegisub PRIVATE src/audio_provider_ffmpegsource.cpp src/ffmpegsource_common.cpp src/video_provider_ffmpegsource.cpp)
endif(FFMS2_FOUND)
endif()
find_package(FFTW)
if (FFTW_FOUND)
set(WITH_FFTW3 ON CACHE BOOL "Enable fftw support")
if(WITH_FFTW3)
find_package(FFTW)
if(NOT FFTW_FOUND)
set(WITH_FFTW3 OFF CACHE BOOL "Enable fftw support" FORCE)
endif()
endif()
if(WITH_FFTW3)
include_directories(${FFTW_INCLUDES})
target_link_libraries (Aegisub ${FFTW_LIBRARIES})
add_definitions("-DWITH_FFTW3")
endif(FFTW_FOUND)
endif()
find_package(Hunspell)
if (HUNSPELL_FOUND)
set(WITH_HUNSPELL ON CACHE BOOL "Enable Hunspell support")
if(WITH_HUNSPELL)
find_package(Hunspell)
if(NOT HUNSPELL_FOUND)
set(WITH_HUNSPELL OFF CACHE BOOL "Enable Hunspell support" FORCE)
endif()
endif()
if(WITH_HUNSPELL)
include_directories(${HUNSPELL_INCLUDE_DIR})
target_link_libraries (Aegisub ${HUNSPELL_LIBRARIES})
add_definitions("-DWITH_HUNSPELL")
@ -550,40 +590,58 @@ if (HUNSPELL_FOUND)
if (HUNSPELL_HAS_STRING_API)
target_compile_definitions(Aegisub PRIVATE "HUNSPELL_HAS_STRING_API")
endif(HUNSPELL_HAS_STRING_API)
endif (HUNSPELL_FOUND)
endif()
find_package(PulseAudio)
if (PULSEAUDIO_FOUND)
set(WITH_LIBPULSE ON CACHE BOOL "Enable PulseAudio support")
if(WITH_LIBPULSE)
find_package(PulseAudio)
if(NOT PULSEAUDIO_FOUND)
set(WITH_LIBPULSE OFF CACHE BOOL "Enable PulseAudio support" FORCE)
endif()
endif()
if(WITH_LIBPULSE)
target_compile_definitions(Aegisub PRIVATE "WITH_LIBPULSE")
target_include_directories(Aegisub PRIVATE ${PULSEAUDIO_INCLUDE_DIR})
target_link_libraries (Aegisub ${PULSEAUDIO_LIBRARY})
target_sources(Aegisub PRIVATE src/audio_player_pulse.cpp)
endif(PULSEAUDIO_FOUND)
endif()
find_package(OpenAL)
if (OPENAL_FOUND)
set(WITH_OPENAL ON CACHE BOOL "Enable OpenAL support")
if(WITH_OPENAL)
find_package(OpenAL)
if(NOT OPENAL_FOUND)
set(WITH_OPENAL OFF CACHE BOOL "Enable OpenAL support" FORCE)
endif()
endif()
if(WITH_OPENAL)
include_directories(${OPENAL_INCLUDE_DIR})
target_link_libraries (Aegisub ${OPENAL_LIBRARY})
add_definitions("-DWITH_OPENAL")
target_sources(Aegisub PRIVATE src/audio_player_openal.cpp)
endif(OPENAL_FOUND)
endif()
#ifdef WITH_OSS
#ifdef WITH_PORTAUDIO
#ifdef WITH_STARTUPLOG
find_package(uchardet)
if (uchardet_FOUND)
set(WITH_UCHARDET ON CACHE BOOL "Enable uchardet support")
if(WITH_UCHARDET)
find_package(uchardet)
if(NOT uchardet_FOUND)
set(WITH_UCHARDET OFF CACHE BOOL "Enable uchardet support" FORCE)
endif()
endif()
if(WITH_UCHARDET)
include_directories(${uchardet_INCLUDE_DIRS})
target_link_libraries (Aegisub ${uchardet_LIBRARIES})
add_definitions("-DWITH_UCHARDET")
endif(uchardet_FOUND)
endif()
#ifdef WITH_UPDATE_CHECKER
if (NOT WIN32)
set(AEGISUB_COMMAND "aegisub" CACHE STRING "The executable name of Aegisub")
set_target_properties(Aegisub PROPERTIES OUTPUT_NAME aegisub)
set_target_properties(Aegisub PROPERTIES OUTPUT_NAME "${AEGISUB_COMMAND}")
configure_file("packages/desktop/aegisub.desktop.template.cmake.in" "aegisub.desktop" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/aegisub.desktop" DESTINATION "share/applications")
install(FILES "packages/desktop/16x16.png" DESTINATION "share/icons/hicolor/16x16/apps" RENAME aegisub.png)