From 1204a3be85e55baf2dc0a2f08e8058ac16da607a Mon Sep 17 00:00:00 2001 From: wangqr Date: Tue, 10 Sep 2019 00:15:40 -0400 Subject: [PATCH] Cleanup CMake --- .travis.yml | 2 +- CMakeLists.txt | 344 ++++++++++++++++++++---------- cmake/FindAviSynth.cmake | 7 +- cmake/FindFFMS2.cmake | 8 +- cmake/FindFFTW.cmake | 2 +- cmake/FindHunspell.cmake | 10 +- cmake/FindOSS.cmake | 14 ++ cmake/FindPortAudio.cmake | 19 ++ cmake/FindPulseAudio.cmake | 9 +- cmake/Findass.cmake | 11 +- cmake/Finduchardet.cmake | 9 +- libaegisub/audio/provider_ram.cpp | 2 +- src/audio_player.cpp | 12 ++ src/frame_main.cpp | 2 +- src/main.cpp | 2 +- src/version.cpp | 1 - src/version.h | 2 + 17 files changed, 307 insertions(+), 149 deletions(-) create mode 100644 cmake/FindOSS.cmake create mode 100644 cmake/FindPortAudio.cmake diff --git a/.travis.yml b/.travis.yml index a966960a3..4e25a9224 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,7 +60,7 @@ script: ./build/version.sh .; mkdir build-dir; cd build-dir; - cmake -DCMAKE_CXX_FLAGS='-Wall -Wextra -Wno-unused-parameter -pedantic' ..; + cmake -DCMAKE_CXX_FLAGS='-Wall -Wextra -Wno-unused-parameter -pedantic' -DCMAKE_C_FLAGS='-Wall' -DWITH_STARTUPLOG=ON ..; make -j2; fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 76bdb92e6..cc128cddd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ add_library(libaegisub STATIC libaegisub/common/ycbcr_conv.cpp libaegisub/common/dispatch.cpp ) -if (UNIX) +if(UNIX) target_sources(libaegisub PRIVATE libaegisub/unix/access.cpp libaegisub/unix/fs.cpp @@ -66,6 +66,11 @@ if (UNIX) libaegisub/unix/path.cpp libaegisub/unix/util.cpp ) + set_property( + SOURCE libaegisub/unix/path.cpp + PROPERTY COMPILE_DEFINITIONS + P_DATA="${CMAKE_INSTALL_PREFIX}/share/aegisub/" + ) elseif(WIN32) target_sources(libaegisub PRIVATE libaegisub/windows/access.cpp @@ -76,8 +81,8 @@ elseif(WIN32) libaegisub/windows/path_win.cpp libaegisub/windows/util_win.cpp ) -endif(UNIX) -SET_TARGET_PROPERTIES(libaegisub PROPERTIES PREFIX "") +endif() +set_target_properties(libaegisub PROPERTIES PREFIX "") target_compile_definitions(libaegisub PRIVATE CMAKE_BUILD) add_library(luabins STATIC @@ -91,48 +96,50 @@ add_library(luabins STATIC ) add_executable(luajit-minilua vendor/luajit/src/host/minilua.c) -if (NOT MSVC) -target_link_libraries(luajit-minilua m) -endif(NOT MSVC) -if (WIN32) +if(NOT WIN32) + target_link_libraries(luajit-minilua m) +endif() +if(WIN32) if(CMAKE_SIZEOF_VOID_P EQUAL 8) - add_custom_command(TARGET luajit-minilua POST_BUILD + add_custom_target(buildvm_arch COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/vendor/luajit/src/gen COMMAND luajit-minilua ../dynasm/dynasm.lua -LN -D WIN -D JIT -D FFI -D P64 -o gen/buildvm_arch.h vm_x86.dasc WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vendor/luajit/src ) else() - add_custom_command(TARGET luajit-minilua POST_BUILD + add_custom_target(buildvm_arch COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/vendor/luajit/src/gen COMMAND luajit-minilua ../dynasm/dynasm.lua -LN -D WIN -D JIT -D FFI -o gen/buildvm_arch.h vm_x86.dasc WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vendor/luajit/src ) endif() -else (WIN32) +else() if(CMAKE_SIZEOF_VOID_P EQUAL 8) - add_custom_command(TARGET luajit-minilua POST_BUILD + add_custom_target(buildvm_arch COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/vendor/luajit/src/gen COMMAND luajit-minilua ../dynasm/dynasm.lua -D P64 -D JIT -D FFI -D FPU -D HFABI -D VER= -o gen/buildvm_arch.h vm_x86.dasc WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vendor/luajit/src ) else() - add_custom_command(TARGET luajit-minilua POST_BUILD + add_custom_target(buildvm_arch COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/vendor/luajit/src/gen COMMAND luajit-minilua ../dynasm/dynasm.lua -D JIT -D FFI -D FPU -D HFABI -D VER= -o gen/buildvm_arch.h vm_x86.dasc WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vendor/luajit/src ) endif() -endif (WIN32) -add_custom_command(TARGET luajit-minilua POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/src/libresrc/default_config_win.json ${PROJECT_SOURCE_DIR}/src/libresrc/default_config_platform.json +endif() + +add_custom_command( + OUTPUT ${PROJECT_SOURCE_DIR}/src/libresrc/default_config.cpp ${PROJECT_SOURCE_DIR}/src/libresrc/default_config.h + DEPENDS ${PROJECT_SOURCE_DIR}/src/libresrc/default_config_platform.json COMMAND luajit-minilua ../../tools/respack.lua manifest.respack default_config.cpp default_config.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/libresrc - BYPRODUCTS ${PROJECT_SOURCE_DIR}/src/libresrc/default_config.cpp ${PROJECT_SOURCE_DIR}/src/libresrc/default_config.h ) -add_custom_command(TARGET luajit-minilua POST_BUILD + +add_custom_command( + OUTPUT ${PROJECT_SOURCE_DIR}/src/libresrc/bitmap.cpp ${PROJECT_SOURCE_DIR}/src/libresrc/bitmap.h COMMAND luajit-minilua ../../tools/respack.lua manifest.respack ../libresrc/bitmap.cpp ../libresrc/bitmap.h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/bitmaps - BYPRODUCTS ${PROJECT_SOURCE_DIR}/src/libresrc/bitmap.cpp ${PROJECT_SOURCE_DIR}/src/libresrc/bitmap.h ) add_executable(luajit-buildvm @@ -142,23 +149,23 @@ add_executable(luajit-buildvm vendor/luajit/src/host/buildvm_lib.c vendor/luajit/src/host/buildvm_fold.c ) +add_dependencies(luajit-buildvm buildvm_arch) +target_compile_definitions(luajit-buildvm PRIVATE LUAJIT_ENABLE_LUA52COMPAT) target_include_directories(luajit-buildvm PRIVATE vendor/luajit/src vendor/luajit/src/gen) -add_dependencies(luajit-buildvm luajit-minilua) if(UNIX) - add_custom_command(TARGET luajit-buildvm POST_BUILD + add_custom_command( + OUTPUT ${PROJECT_SOURCE_DIR}/vendor/luajit/src/lj_vm.s COMMAND luajit-buildvm -m elfasm -o lj_vm.s WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vendor/luajit/src - BYPRODUCTS ${PROJECT_SOURCE_DIR}/vendor/luajit/src/lj_vm.s ) - set_property(SOURCE vendor/luajit/src/lj_vm.s PROPERTY LANGUAGE C) elseif(MSVC) - add_custom_command(TARGET luajit-buildvm POST_BUILD + add_custom_command( + OUTPUT ${PROJECT_SOURCE_DIR}/vendor/luajit/src/lj_vm.obj COMMAND luajit-buildvm -m peobj -o lj_vm.obj WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vendor/luajit/src - BYPRODUCTS ${PROJECT_SOURCE_DIR}/vendor/luajit/src/lj_vm.obj ) -endif(UNIX) -add_custom_command(TARGET luajit-buildvm POST_BUILD +endif() +add_custom_target(luajit_buildvm_headers COMMAND luajit-buildvm -m ffdef -o gen/lj_ffdef.h lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c COMMAND luajit-buildvm -m bcdef -o gen/lj_bcdef.h lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c COMMAND luajit-buildvm -m folddef -o gen/lj_folddef.h lj_opt_fold.c @@ -167,8 +174,6 @@ add_custom_command(TARGET luajit-buildvm POST_BUILD COMMAND luajit-buildvm -m vmdef -o jit/vmdef.lua lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vendor/luajit/src ) -target_compile_definitions(luajit-buildvm PRIVATE LUAJIT_ENABLE_LUA52COMPAT) - add_library(luajit STATIC vendor/luajit/src/lj_gc.c @@ -233,23 +238,22 @@ add_library(luajit STATIC vendor/luajit/src/lib_ffi.c vendor/luajit/src/lib_init.c ) +add_dependencies(luajit luajit_buildvm_headers) +target_compile_definitions(luajit PRIVATE LUAJIT_ENABLE_LUA52COMPAT) +target_include_directories(luajit PRIVATE vendor/luajit/src/gen) if(MSVC) target_sources(luajit PRIVATE vendor/luajit/src/lj_vm.obj) -else(MSVC) +else() target_sources(luajit PRIVATE vendor/luajit/src/lj_vm.s) set_property(SOURCE vendor/luajit/src/lj_vm.s PROPERTY LANGUAGE C) target_link_libraries(luajit dl) -endif(MSVC) -target_include_directories(luajit PRIVATE vendor/luajit/src/gen) -add_dependencies(luajit luajit-buildvm) -target_compile_definitions(luajit PRIVATE LUAJIT_ENABLE_LUA52COMPAT) +endif() add_library(resrc STATIC src/libresrc/bitmap.cpp src/libresrc/default_config.cpp src/libresrc/libresrc.cpp ) -add_dependencies(resrc luajit-minilua) add_library(csri STATIC vendor/csri/lib/list.c @@ -257,13 +261,13 @@ add_library(csri STATIC vendor/csri/subhelp/logging.c ) target_include_directories(csri PRIVATE "vendor/csri/include") -IF (WIN32) +if(WIN32) target_include_directories(csri PRIVATE "vendor/csri/lib/win32") target_sources(csri PRIVATE vendor/csri/lib/win32/enumerate.c) -ELSE() +else() target_include_directories(csri PRIVATE "vendor/csri/lib/posix") target_sources(csri PRIVATE vendor/csri/lib/posix/enumerate.c) -ENDIF() +endif() add_executable(Aegisub WIN32 src/command/app.cpp @@ -310,7 +314,6 @@ add_executable(Aegisub WIN32 src/dialog_text_import.cpp src/dialog_timing_processor.cpp src/dialog_translation.cpp - src/dialog_version_check.cpp src/dialog_video_details.cpp src/dialog_video_properties.cpp src/subtitle_format.cpp @@ -434,78 +437,72 @@ 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") + target_compile_definitions(Aegisub PRIVATE "BUILD_CREDIT=${BUILD_CREDIT}") else() unset(BUILD_CREDIT CACHE) endif() -if (MSVC) +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) +else() target_compile_options(libaegisub PRIVATE -include "${PROJECT_SOURCE_DIR}/libaegisub/lagi_pre.h") -endif(MSVC) +endif() -set_property( - SOURCE libaegisub/unix/path.cpp - PROPERTY COMPILE_DEFINITIONS - P_DATA="${CMAKE_INSTALL_PREFIX}/share/aegisub/" -) - -if (MSVC) - add_definitions("-DNOMINMAX -MP -DINITGUID") +if(MSVC) + add_definitions("/DNOMINMAX /MP /DINITGUID") set_target_properties(Aegisub PROPERTIES COMPILE_FLAGS "/Yu${PROJECT_SOURCE_DIR}/src/agi_pre.h" COMPILE_FLAGS "/FI${PROJECT_SOURCE_DIR}/src/agi_pre.h") - target_link_libraries (Aegisub Usp10) + target_link_libraries(Aegisub Usp10) #target_sources(Aegisub PRIVATE src/res/res.rc src/res/strings.rc src/crash_writer_minidump.cpp) target_sources(Aegisub PRIVATE src/res/res.rc src/res/strings.rc src/crash_writer.cpp src/dpi_aware.manifest) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Aegisub) -else(MSVC) +else() target_sources(Aegisub PRIVATE src/crash_writer.cpp) target_compile_options(Aegisub PRIVATE -include "${PROJECT_SOURCE_DIR}/src/agi_pre.h") -endif(MSVC) +endif() -if (WIN32) +if(WIN32) target_sources(Aegisub PRIVATE src/font_file_lister_gdi.cpp) -else (WIN32) +else() find_package(Fontconfig REQUIRED) - target_link_libraries (Aegisub ${Fontconfig_LIBRARIES}) + target_include_directories(Aegisub PRIVATE ${Fontconfig_INCLUDE_DIRS}) + target_link_libraries(Aegisub ${Fontconfig_LIBRARIES}) target_sources(Aegisub PRIVATE src/font_file_lister_fontconfig.cpp) - set_property(SOURCE src/font_file_lister_fontconfig.cpp PROPERTY INCLUDE_DIRECTORIES "${Fontconfig_INCLUDE_DIRS}") -endif (WIN32) +endif() find_package(ass REQUIRED) -include_directories(${ass_INCLUDE_DIRS}) -target_link_libraries (Aegisub ${ass_LIBRARIES}) +target_include_directories(Aegisub PRIVATE ${ass_INCLUDE_DIRS}) +target_link_libraries(Aegisub ${ass_LIBRARIES}) find_package(Boost REQUIRED chrono filesystem locale regex system thread) -include_directories(${Boost_INCLUDE_DIRS}) +target_include_directories(libaegisub PRIVATE ${Boost_INCLUDE_DIRS}) +target_include_directories(Aegisub PRIVATE ${Boost_INCLUDE_DIRS}) target_link_directories(Aegisub PRIVATE ${Boost_LIBRARY_DIRS}) target_link_libraries(Aegisub ${Boost_LIBRARIES}) find_package(OpenGL REQUIRED) -include_directories(${OPENGL_INCLUDE_DIR}) -target_link_libraries (Aegisub ${OPENGL_LIBRARIES}) +target_include_directories(Aegisub PRIVATE ${OPENGL_INCLUDE_DIR}) +target_link_libraries(Aegisub ${OPENGL_LIBRARIES}) find_package(Iconv REQUIRED) -include_directories(${Iconv_INCLUDE_DIRS}) -target_link_libraries (Aegisub ${Iconv_LIBRARIES}) -add_definitions("-DHAVE_ICONV") -if (NOT Iconv_IS_BUILT_IN) -set_property( - SOURCE libaegisub/common/charset_conv.cpp - PROPERTY COMPILE_DEFINITIONS AGI_ICONV_CONST -) -endif (NOT Iconv_IS_BUILT_IN) +target_compile_definitions(libaegisub PRIVATE "HAVE_ICONV") +target_include_directories(libaegisub PRIVATE ${Iconv_INCLUDE_DIRS}) +target_link_libraries(libaegisub ${Iconv_LIBRARIES}) +if(NOT Iconv_IS_BUILT_IN) + target_compile_definitions(libaegisub PRIVATE "AGI_ICONV_CONST") +endif() find_package(ICU REQUIRED uc dt in) -include_directories(${ICU_INCLUDE_DIRS}) -target_link_libraries (Aegisub ${ICU_LIBRARIES}) +target_include_directories(libaegisub PRIVATE ${ICU_INCLUDE_DIRS}) +target_include_directories(Aegisub PRIVATE ${ICU_INCLUDE_DIRS}) +target_link_libraries(Aegisub ${ICU_LIBRARIES}) find_package(wxWidgets REQUIRED adv base core gl stc xml) include(${wxWidgets_USE_FILE}) target_link_libraries(Aegisub ${wxWidgets_LIBRARIES}) find_package(ZLIB REQUIRED) -include_directories(${ZLIB_INCLUDE_DIRS}) -target_link_libraries (Aegisub ${ZLIB_LIBRARIES}) +target_include_directories(Aegisub PRIVATE ${ZLIB_INCLUDE_DIRS}) +target_link_libraries(Aegisub ${ZLIB_LIBRARIES}) set(WITH_ALSA ON CACHE BOOL "Enable ALSA support") if(WITH_ALSA) @@ -515,9 +512,9 @@ if(WITH_ALSA) endif() endif() if(WITH_ALSA) - include_directories(${ALSA_INCLUDE_DIRS}) - target_link_libraries (Aegisub ${ALSA_LIBRARIES}) - add_definitions("-DWITH_ALSA") + target_compile_definitions(Aegisub PRIVATE "WITH_ALSA") + target_include_directories(Aegisub PRIVATE ${ALSA_INCLUDE_DIRS}) + target_link_libraries(Aegisub ${ALSA_LIBRARIES}) target_sources(Aegisub PRIVATE src/audio_player_alsa.cpp) endif() @@ -538,14 +535,17 @@ endif() set(WITH_CSRI ON CACHE BOOL "Enable CSRI support") if(WITH_CSRI) target_compile_definitions(Aegisub PRIVATE "WITH_CSRI") + target_include_directories(Aegisub PRIVATE "${PROJECT_SOURCE_DIR}/vendor/csri/include") 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(WIN32) - target_link_libraries (Aegisub dsound) - add_definitions("-DWITH_DIRECTSOUND") + target_compile_definitions(Aegisub PRIVATE "WITH_DIRECTSOUND") + target_link_libraries(Aegisub dsound) target_sources(Aegisub PRIVATE src/audio_player_dsound.cpp src/audio_player_dsound2.cpp) + set(WITH_DIRECTSOUND ON) +else() + set(WITH_DIRECTSOUND OFF) endif() set(WITH_FFMS2 ON CACHE BOOL "Enable FFMS2 support") @@ -556,10 +556,19 @@ if(WITH_FFMS2) endif() endif() if(WITH_FFMS2) - include_directories(${FFMS2_INCLUDE_DIRS}) - target_link_libraries (Aegisub ${FFMS2_LIBRARIES}) - add_definitions("-DWITH_FFMS2") + target_compile_definitions(Aegisub PRIVATE "WITH_FFMS2") + target_include_directories(Aegisub PRIVATE ${FFMS2_INCLUDE_DIRS}) + target_link_libraries(Aegisub ${FFMS2_LIBRARIES}) target_sources(Aegisub PRIVATE src/audio_provider_ffmpegsource.cpp src/ffmpegsource_common.cpp src/video_provider_ffmpegsource.cpp) +else() + message(SEND_ERROR + "No supported video/audio reader interface was enabled.\n" + "You will not be able to open any video or audio files in Aegisub unless you install a supported video/audio provider.\n" + "You will however still be able to open \"dummy\" video, ie. a blank, virtual video clip with subtitles overlaid.\n" + "Currently we only support one video/audio provider on non-Windows systems:\n" + " - FFMS2\n" + " * http://github.com/FFMS/ffms2\n" + ) endif() set(WITH_FFTW3 ON CACHE BOOL "Enable fftw support") @@ -570,9 +579,9 @@ if(WITH_FFTW3) endif() endif() if(WITH_FFTW3) - include_directories(${FFTW_INCLUDES}) - target_link_libraries (Aegisub ${FFTW_LIBRARIES}) - add_definitions("-DWITH_FFTW3") + target_compile_definitions(Aegisub PRIVATE "WITH_FFTW3") + target_include_directories(Aegisub PRIVATE ${FFTW_INCLUDES}) + target_link_libraries(Aegisub ${FFTW_LIBRARIES}) endif() set(WITH_HUNSPELL ON CACHE BOOL "Enable Hunspell support") @@ -583,11 +592,11 @@ if(WITH_HUNSPELL) endif() endif() if(WITH_HUNSPELL) - include_directories(${HUNSPELL_INCLUDE_DIR}) - target_link_libraries (Aegisub ${HUNSPELL_LIBRARIES}) - add_definitions("-DWITH_HUNSPELL") + target_compile_definitions(Aegisub PRIVATE "WITH_HUNSPELL") + target_include_directories(Aegisub PRIVATE ${HUNSPELL_INCLUDE_DIR}) + target_link_libraries(Aegisub ${HUNSPELL_LIBRARIES}) target_sources(Aegisub PRIVATE src/spellchecker_hunspell.cpp) - if (HUNSPELL_HAS_STRING_API) + if(HUNSPELL_HAS_STRING_API) target_compile_definitions(Aegisub PRIVATE "HUNSPELL_HAS_STRING_API") endif(HUNSPELL_HAS_STRING_API) endif() @@ -602,7 +611,7 @@ 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_link_libraries(Aegisub ${PULSEAUDIO_LIBRARY}) target_sources(Aegisub PRIVATE src/audio_player_pulse.cpp) endif() @@ -614,15 +623,43 @@ if(WITH_OPENAL) endif() endif() if(WITH_OPENAL) - include_directories(${OPENAL_INCLUDE_DIR}) - target_link_libraries (Aegisub ${OPENAL_LIBRARY}) - add_definitions("-DWITH_OPENAL") + target_compile_definitions(Aegisub PRIVATE "WITH_OPENAL") + target_include_directories(Aegisub PRIVATE ${OPENAL_INCLUDE_DIR}) + target_link_libraries(Aegisub ${OPENAL_LIBRARY}) target_sources(Aegisub PRIVATE src/audio_player_openal.cpp) endif() -#ifdef WITH_OSS -#ifdef WITH_PORTAUDIO -#ifdef WITH_STARTUPLOG +set(WITH_OSS OFF CACHE BOOL "Enable OSS support") +if(WITH_OSS) + find_package(OSS) + if(NOT OSS_FOUND) + set(WITH_OSS OFF CACHE BOOL "Enable OSS support" FORCE) + endif() +endif() +if(WITH_OSS) + target_compile_definitions(Aegisub PRIVATE "WITH_OSS") + target_include_directories(Aegisub PRIVATE ${OSS_INCLUDE_DIRS}) + target_sources(Aegisub PRIVATE src/audio_player_oss.cpp) +endif() + +set(WITH_PORTAUDIO ON CACHE BOOL "Enable PortAudio support") +if(WITH_PORTAUDIO) + find_package(PortAudio) + if(NOT PortAudio_FOUND) + set(WITH_PORTAUDIO OFF CACHE BOOL "Enable PortAudio support" FORCE) + endif() +endif() +if(WITH_PORTAUDIO) + target_compile_definitions(Aegisub PRIVATE "WITH_PORTAUDIO") + target_include_directories(Aegisub PRIVATE ${PortAudio_INCLUDE_DIRS}) + target_link_libraries(Aegisub ${PortAudio_LIBRARIES}) + target_sources(Aegisub PRIVATE src/audio_player_portaudio.cpp) +endif() + +set(WITH_STARTUPLOG OFF CACHE BOOL "Enable startup log") +if(WITH_STARTUPLOG) + target_compile_definitions(Aegisub PRIVATE "WITH_STARTUPLOG") +endif() set(WITH_UCHARDET ON CACHE BOOL "Enable uchardet support") if(WITH_UCHARDET) @@ -632,24 +669,99 @@ if(WITH_UCHARDET) endif() endif() if(WITH_UCHARDET) - include_directories(${uchardet_INCLUDE_DIRS}) - target_link_libraries (Aegisub ${uchardet_LIBRARIES}) - add_definitions("-DWITH_UCHARDET") + target_compile_definitions(Aegisub PRIVATE "WITH_UCHARDET") + target_include_directories(Aegisub PRIVATE ${uchardet_INCLUDE_DIRS}) + target_link_libraries(Aegisub ${uchardet_LIBRARIES}) endif() -#ifdef WITH_UPDATE_CHECKER +set(WITH_UPDATE_CHECKER OFF) +if(WITH_UPDATE_CHECKER) + set(UPDATE_CHECKER_SERVER "\"updates.aegisub.org\"" CACHE STRING "Server for the update checker") + set(UPDATE_CHECKER_BASE_URL "\"/trunk\"" CACHE STRING "Base path for the update checker") + target_compile_definitions(Aegisub PRIVATE "WITH_UPDATE_CHECKER" "UPDATE_CHECKER_SERVER=${UPDATE_CHECKER_SERVER}" "UPDATE_CHECKER_BASE_URL=${UPDATE_CHECKER_BASE_URL}") + target_link_libraries(Aegisub ${Boost_asio_LIBRARY}) + target_sources(Aegisub PRIVATE src/dialog_version_check.cpp) +endif() -if (NOT WIN32) -set(AEGISUB_COMMAND "aegisub" CACHE STRING "The executable name of 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) -install(FILES "packages/desktop/22x22.png" DESTINATION "share/icons/hicolor/22x22/apps" RENAME aegisub.png) -install(FILES "packages/desktop/24x24.png" DESTINATION "share/icons/hicolor/24x24/apps" RENAME aegisub.png) -install(FILES "packages/desktop/32x32.png" DESTINATION "share/icons/hicolor/32x32/apps" RENAME aegisub.png) -install(FILES "packages/desktop/48x48.png" DESTINATION "share/icons/hicolor/48x48/apps" RENAME aegisub.png) -install(FILES "packages/desktop/64x64.png" DESTINATION "share/icons/hicolor/64x64/apps" RENAME aegisub.png) -install(FILES "packages/desktop/scalable.svg" DESTINATION "share/icons/hicolor/scalable/apps" RENAME aegisub.svg) -endif (NOT WIN32) -install (TARGETS Aegisub DESTINATION bin) +if(WIN32) + set(DEFAULT_PLAYER_AUDIO DirectSound) + configure_file("src/libresrc/default_config_win.json" "${PROJECT_SOURCE_DIR}/src/libresrc/default_config_platform.json" COPYONLY) +else() + if(WITH_LIBPULSE) + set(DEFAULT_PLAYER_AUDIO "PulseAudio" CACHE STRING "Default audio player") + elseif(WITH_ALSA) + set(DEFAULT_PLAYER_AUDIO "ALSA" CACHE STRING "Default audio player") + elseif(WITH_OPENAL) + set(DEFAULT_PLAYER_AUDIO "OpenAL" CACHE STRING "Default audio player") + elseif(WITH_PORTAUDIO) + set(DEFAULT_PLAYER_AUDIO "PortAudio" CACHE STRING "Default audio player") + elseif(WITH_OSS) + set(DEFAULT_PLAYER_AUDIO "OSS" CACHE STRING "Default audio player") + else() + message(SEND_ERROR + "No supported audio player interface was enabled.\n" + "If you want audio support in Aegisub you need to install one of these libraries:\n" + " - PulseAudio\n" + " * http://pulseaudio.org/\n" + " - ALSA (Linux only)\n" + " * http://www.alsa-project.org/\n" + " - PortAudio (version 19 only)\n" + " * http://www.portaudio.com/\n" + "\n" + ) + set(DEFAULT_PLAYER_AUDIO "NONE" CACHE STRING "Default audio player") + endif() + add_custom_command( + OUTPUT ${PROJECT_SOURCE_DIR}/src/libresrc/default_config_platform.json + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/src/libresrc/default_config_win.json ${PROJECT_SOURCE_DIR}/src/libresrc/default_config_platform.json + ) + configure_file("src/libresrc/default_config_platform.json.in" "${PROJECT_SOURCE_DIR}/src/libresrc/default_config_platform.json" @ONLY) +endif() + +if(NOT WIN32) + set(AEGISUB_COMMAND "aegisub" CACHE STRING "The executable name of 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) + install(FILES "packages/desktop/22x22.png" DESTINATION "share/icons/hicolor/22x22/apps" RENAME aegisub.png) + install(FILES "packages/desktop/24x24.png" DESTINATION "share/icons/hicolor/24x24/apps" RENAME aegisub.png) + install(FILES "packages/desktop/32x32.png" DESTINATION "share/icons/hicolor/32x32/apps" RENAME aegisub.png) + install(FILES "packages/desktop/48x48.png" DESTINATION "share/icons/hicolor/48x48/apps" RENAME aegisub.png) + install(FILES "packages/desktop/64x64.png" DESTINATION "share/icons/hicolor/64x64/apps" RENAME aegisub.png) + install(FILES "packages/desktop/scalable.svg" DESTINATION "share/icons/hicolor/scalable/apps" RENAME aegisub.svg) +endif() +install(TARGETS Aegisub DESTINATION bin) + +message(STATUS "\n" + "Configure settings\n" + " Install prefix: ${CMAKE_INSTALL_PREFIX}\n" + " CFLAGS ${CMAKE_C_FLAGS}\n" + " CXXFLAGS ${CMAKE_CXX_FLAGS}\n" + "\n" + "Default Settings\n" + " Audio Player: ${DEFAULT_PLAYER_AUDIO}\n" + "\n" + "Audio Players\n" + " ALSA: ${WITH_ALSA}\n" + " DirectSound: ${WITH_DIRECTSOUND}\n" + " DirectSound-old: ${WITH_DIRECTSOUND}\n" + " OpenAL: ${WITH_OPENAL}\n" + " OSS: ${WITH_OSS}\n" + " PortAudio: ${WITH_PORTAUDIO}\n" + " PulseAudio: ${WITH_LIBPULSE}\n" + "\n" + "Misc Packages\n" + " AviSynth: ${WITH_AVISYNTH}\n" + " CSRI: ${WITH_CSRI}\n" + " FFMS2: ${WITH_FFMS2}\n" + " FFTW3: ${WITH_FFTW3}\n" + " Hunspell: ${WITH_HUNSPELL}\n" + " uchardet: ${WITH_UCHARDET}\n" + " LuaJIT: bundled\n" + "\n" + "Options\n" + " Startup log: ${WITH_STARTUPLOG}\n" + " Update checker: ${WITH_UPDATE_CHECKER}\n" + "\n" +) diff --git a/cmake/FindAviSynth.cmake b/cmake/FindAviSynth.cmake index c7232701e..248db87b3 100644 --- a/cmake/FindAviSynth.cmake +++ b/cmake/FindAviSynth.cmake @@ -1,12 +1,13 @@ -find_package(PkgConfig) +find_package(PkgConfig QUIET) pkg_check_modules(PC_AviSynth QUIET AviSynth) find_path(AviSynth_INCLUDE_DIRS NAMES avisynth.h - PATHS ${PC_AviSynth_INCLUDE_DIRS} + HINTS ${PC_AviSynth_INCLUDE_DIRS} ) find_library(AviSynth_LIBRARIES NAMES avisynth - PATHS ${PC_AviSynth_LIBRARY_DIRS} + PATH_SUFFIXES c_api + HINTS ${PC_AviSynth_LIBRARY_DIRS} ) set(AviSynth_VERSION ${PC_AviSynth_VERSION}) include(FindPackageHandleStandardArgs) diff --git a/cmake/FindFFMS2.cmake b/cmake/FindFFMS2.cmake index 9128b2864..1ef5063cd 100644 --- a/cmake/FindFFMS2.cmake +++ b/cmake/FindFFMS2.cmake @@ -1,12 +1,12 @@ -find_package(PkgConfig) +find_package(PkgConfig QUIET) pkg_check_modules(PC_FFMS2 QUIET ffms2) find_path(FFMS2_INCLUDE_DIRS NAMES ffms.h ffmscompat.h - PATHS ${PC_FFMS2_INCLUDE_DIRS} + HINTS ${PC_FFMS2_INCLUDE_DIRS} ) find_library(FFMS2_LIBRARIES NAMES ffms2 - PATHS ${PC_FFMS2_LIBRARY_DIRS} + HINTS ${PC_FFMS2_LIBRARY_DIRS} ) set(FFMS2_VERSION ${PC_FFMS2_VERSION}) include(FindPackageHandleStandardArgs) @@ -16,4 +16,4 @@ find_package_handle_standard_args(FFMS2 FFMS2_LIBRARIES FFMS2_INCLUDE_DIRS VERSION_VAR FFMS2_VERSION -) \ No newline at end of file +) diff --git a/cmake/FindFFTW.cmake b/cmake/FindFFTW.cmake index 8a74443c2..f294931d2 100644 --- a/cmake/FindFFTW.cmake +++ b/cmake/FindFFTW.cmake @@ -22,7 +22,7 @@ if( NOT FFTW_ROOT AND ENV{FFTWDIR} ) endif() # Check if we can use PkgConfig -find_package(PkgConfig) +find_package(PkgConfig QUIET) #Determine from PKG if( PKG_CONFIG_FOUND AND NOT FFTW_ROOT ) diff --git a/cmake/FindHunspell.cmake b/cmake/FindHunspell.cmake index c6fe197c7..1c0190bd8 100644 --- a/cmake/FindHunspell.cmake +++ b/cmake/FindHunspell.cmake @@ -12,11 +12,10 @@ # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls -if( NOT WIN32 ) - find_package(PkgConfig) - pkg_check_modules(HUNSPELL_PKG QUIET hunspell) -endif( NOT WIN32 ) +find_package(PkgConfig QUIET) + +pkg_check_modules(HUNSPELL_PKG QUIET hunspell) FIND_PATH(HUNSPELL_INCLUDE_DIR NAMES hunspell.h PATHS @@ -53,8 +52,7 @@ if (HUNSPELL_FOUND) try_compile(HUNSPELL_HAS_STRING_API "${CMAKE_BINARY_DIR}/hunspell_string_api" "${CMAKE_CURRENT_LIST_DIR}/hunspell_string_api.cpp" LINK_LIBRARIES ${HUNSPELL_LIBRARIES} - CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${HUNSPELL_INCLUDE_DIR}" "-DLINK_LIBRARIES=${HUNSPELL_LIBRARIES}" - OUTPUT_VARIABLE debuggggg) + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${HUNSPELL_INCLUDE_DIR}") if (HUNSPELL_HAS_STRING_API) message(STATUS "Hunspell has string API") else(HUNSPELL_HAS_STRING_API) diff --git a/cmake/FindOSS.cmake b/cmake/FindOSS.cmake new file mode 100644 index 000000000..d80fbaaae --- /dev/null +++ b/cmake/FindOSS.cmake @@ -0,0 +1,14 @@ +find_package(PkgConfig QUIET) +pkg_check_modules(PC_oss QUIET oss) +find_path(OSS_INCLUDE_DIRS + NAMES sys/soundcard.h + HINTS ${PC_oss_INCLUDE_DIRS} +) +set(OSS_VERSION ${PC_ass_VERSION}) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OSS + FOUND_VAR OSS_FOUND + REQUIRED_VARS + OSS_INCLUDE_DIRS + VERSION_VAR OSS_VERSION +) diff --git a/cmake/FindPortAudio.cmake b/cmake/FindPortAudio.cmake new file mode 100644 index 000000000..96740eded --- /dev/null +++ b/cmake/FindPortAudio.cmake @@ -0,0 +1,19 @@ +find_package(PkgConfig QUIET) +pkg_check_modules(PC_portaudio QUIET portaudio-2.0) +find_path(PortAudio_INCLUDE_DIRS + NAMES portaudio.h + HINTS ${PC_portaudio_INCLUDE_DIRS} +) +find_library(PortAudio_LIBRARIES + NAMES portaudio + HINTS ${PC_portaudio_LIBRARY_DIRS} +) +set(PortAudio_VERSION ${PC_portaudio_VERSION}) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PortAudio + FOUND_VAR PortAudio_FOUND + REQUIRED_VARS + PortAudio_LIBRARIES + PortAudio_INCLUDE_DIRS + VERSION_VAR PortAudio_VERSION +) diff --git a/cmake/FindPulseAudio.cmake b/cmake/FindPulseAudio.cmake index 35bcbc2fe..3347b98f3 100644 --- a/cmake/FindPulseAudio.cmake +++ b/cmake/FindPulseAudio.cmake @@ -26,11 +26,10 @@ if(NOT PulseAudio_FIND_VERSION) set(PulseAudio_FIND_VERSION "0.9.9") endif(NOT PulseAudio_FIND_VERSION) -if (NOT WIN32) - include(FindPkgConfig) - pkg_check_modules(PC_PULSEAUDIO QUIET libpulse>=${PulseAudio_FIND_VERSION}) - pkg_check_modules(PC_PULSEAUDIO_MAINLOOP QUIET libpulse-mainloop-glib) -endif (NOT WIN32) + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_PULSEAUDIO QUIET libpulse>=${PulseAudio_FIND_VERSION}) +pkg_check_modules(PC_PULSEAUDIO_MAINLOOP QUIET libpulse-mainloop-glib) find_path(PULSEAUDIO_INCLUDE_DIR pulse/pulseaudio.h HINTS diff --git a/cmake/Findass.cmake b/cmake/Findass.cmake index dc7ca58d3..d901ef887 100644 --- a/cmake/Findass.cmake +++ b/cmake/Findass.cmake @@ -1,12 +1,13 @@ -find_package(PkgConfig) -pkg_check_modules(PC_ass QUIET ass) +find_package(PkgConfig QUIET) +pkg_check_modules(PC_ass QUIET libass) find_path(ass_INCLUDE_DIRS NAMES ass/ass.h ass/ass_types.h - PATHS ${PC_ass_INCLUDE_DIRS} + PATH_SUFFIXES libass + HINTS ${PC_ass_INCLUDE_DIRS} ) find_library(ass_LIBRARIES NAMES ass - PATHS ${PC_ass_LIBRARY_DIRS} + HINTS ${PC_ass_LIBRARY_DIRS} ) set(ass_VERSION ${PC_ass_VERSION}) include(FindPackageHandleStandardArgs) @@ -16,4 +17,4 @@ find_package_handle_standard_args(ass ass_LIBRARIES ass_INCLUDE_DIRS VERSION_VAR ass_VERSION -) \ No newline at end of file +) diff --git a/cmake/Finduchardet.cmake b/cmake/Finduchardet.cmake index c225d90f2..0fc8660ca 100644 --- a/cmake/Finduchardet.cmake +++ b/cmake/Finduchardet.cmake @@ -1,12 +1,13 @@ -find_package(PkgConfig) +find_package(PkgConfig QUIET) pkg_check_modules(PC_uchardet QUIET uchardet) find_path(uchardet_INCLUDE_DIRS NAMES uchardet/uchardet.h - PATHS ${PC_uchardet_INCLUDE_DIRS} + HINTS ${PC_uchardet_INCLUDE_DIRS} ) find_library(uchardet_LIBRARIES NAMES uchardet - PATHS ${PC_uchardet_LIBRARY_DIRS} + PATH_SUFFIXES build/src + HINTS ${PC_uchardet_LIBRARY_DIRS} ) set(uchardet_VERSION ${PC_uchardet_VERSION}) include(FindPackageHandleStandardArgs) @@ -16,4 +17,4 @@ find_package_handle_standard_args(uchardet uchardet_LIBRARIES uchardet_INCLUDE_DIRS VERSION_VAR uchardet_VERSION -) \ No newline at end of file +) diff --git a/libaegisub/audio/provider_ram.cpp b/libaegisub/audio/provider_ram.cpp index 0c1da546c..3dff46bbd 100644 --- a/libaegisub/audio/provider_ram.cpp +++ b/libaegisub/audio/provider_ram.cpp @@ -77,7 +77,7 @@ void RAMAudioProvider::FillBuffer(void *buf, int64_t start, int64_t count) const break; } - const int i = (start * bytes_per_sample) >> CacheBits; + const size_t i = (start * bytes_per_sample) >> CacheBits; const int start_offset = (start * bytes_per_sample) & (CacheBlockSize-1); const int read_size = std::min(bytes_remaining, CacheBlockSize - start_offset); diff --git a/src/audio_player.cpp b/src/audio_player.cpp index f5a8327ca..0ab9a4689 100644 --- a/src/audio_player.cpp +++ b/src/audio_player.cpp @@ -40,13 +40,25 @@ #include +#ifdef WITH_ALSA std::unique_ptr CreateAlsaPlayer(agi::AudioProvider *providers, wxWindow *window); +#endif +#ifdef WITH_DIRECTSOUND std::unique_ptr CreateDirectSoundPlayer(agi::AudioProvider *providers, wxWindow *window); std::unique_ptr CreateDirectSound2Player(agi::AudioProvider *providers, wxWindow *window); +#endif +#ifdef WITH_OPENAL std::unique_ptr CreateOpenALPlayer(agi::AudioProvider *providers, wxWindow *window); +#endif +#ifdef WITH_PORTAUDIO std::unique_ptr CreatePortAudioPlayer(agi::AudioProvider *providers, wxWindow *window); +#endif +#ifdef WITH_LIBPULSE std::unique_ptr CreatePulseAudioPlayer(agi::AudioProvider *providers, wxWindow *window); +#endif +#ifdef WITH_OSS std::unique_ptr CreateOSSPlayer(agi::AudioProvider *providers, wxWindow *window); +#endif namespace { struct factory { diff --git a/src/frame_main.cpp b/src/frame_main.cpp index df115b27c..9f4c53954 100644 --- a/src/frame_main.cpp +++ b/src/frame_main.cpp @@ -74,7 +74,7 @@ enum { }; #ifdef WITH_STARTUPLOG -#define StartupLog(a) MessageBox(0, a, "Aegisub startup log", 0) +#define StartupLog(a) wxMessageBox(a, "Aegisub startup log") #else #define StartupLog(a) LOG_I("frame_main/init") << a #endif diff --git a/src/main.cpp b/src/main.cpp index 7f6d9162c..92f53fe8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,7 +85,7 @@ wxIMPLEMENT_APP(AegisubApp); static const char *LastStartupState = nullptr; #ifdef WITH_STARTUPLOG -#define StartupLog(a) MessageBox(0, L ## a, L"Aegisub startup log", 0) +#define StartupLog(a) wxMessageBox(wxT(a), wxT("Aegisub startup log")) #else #define StartupLog(a) LastStartupState = a #endif diff --git a/src/version.cpp b/src/version.cpp index a612b439c..c8ab15c4c 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -62,7 +62,6 @@ const char *GetAegisubBuildTime() { const char *GetAegisubBuildCredit() { return BUILD_CREDIT; - return ""; } #endif diff --git a/src/version.h b/src/version.h index d413d634f..833c41d71 100644 --- a/src/version.h +++ b/src/version.h @@ -36,10 +36,12 @@ const char *GetAegisubLongVersionString(); /// Version string used in About box, looks nicer const char *GetAegisubShortVersionString(); +#ifdef BUILD_CREDIT /// Timestamp of build, only shown in About box const char *GetAegisubBuildTime(); /// Name of who built the binary const char *GetAegisubBuildCredit(); +#endif /// Is release? bool GetIsOfficialRelease(); /// Version number