build(cmake): fix build errors on Windows
Some checks are pending
Build / ubuntu (push) Waiting to run
Build / windows (push) Waiting to run
Build / container (push) Waiting to run

Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
k4yt3x 2025-01-08 00:00:00 +00:00
parent 8687d7d175
commit 6b0ad2df03
No known key found for this signature in database

View File

@ -117,14 +117,16 @@ target_compile_definitions(libvideo2x PRIVATE LIBVIDEO2X_EXPORTS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(libvideo2x PRIVATE $<$<CONFIG:Debug>:/Zi /Od /MDd>) target_compile_options(libvideo2x PRIVATE $<$<CONFIG:Debug>:/Zi /Od /MDd>)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(libvideo2x PRIVATE -fPIC $<$<CONFIG:Debug>:-g -O0>) target_compile_options(libvideo2x PRIVATE
$<$<NOT:$<PLATFORM_ID:Windows>>:-fPIC>
$<$<CONFIG:Debug>:-g -O0>
)
endif() endif()
# FFmpeg # FFmpeg
if(WIN32) if(WIN32)
target_include_directories(libvideo2x SYSTEM PRIVATE set(ffmpeg_base_path "${PROJECT_SOURCE_DIR}/third_party/ffmpeg-shared")
"${PROJECT_SOURCE_DIR}/third_party/ffmpeg-shared/include" target_include_directories(libvideo2x SYSTEM PRIVATE "${ffmpeg_base_path}/include")
)
target_link_libraries(libvideo2x PRIVATE target_link_libraries(libvideo2x PRIVATE
"${ffmpeg_base_path}/lib/avcodec.lib" "${ffmpeg_base_path}/lib/avcodec.lib"
"${ffmpeg_base_path}/lib/avfilter.lib" "${ffmpeg_base_path}/lib/avfilter.lib"
@ -163,25 +165,16 @@ endif()
# ncnn # ncnn
if(VIDEO2X_USE_EXTERNAL_NCNN) if(VIDEO2X_USE_EXTERNAL_NCNN)
find_package(ncnn REQUIRED) find_package(ncnn REQUIRED)
target_link_libraries(libvideo2x PRIVATE ncnn)
else() else()
if(WIN32) if(WIN32)
# On Windows, use the pre-built shared ncnn library # Use the pre-built shared ncnn library on Windows
set(ncnn_base_path "${PROJECT_SOURCE_DIR}/third_party/ncnn-shared/x64") set(ncnn_base_path "${PROJECT_SOURCE_DIR}/third_party/ncnn-shared/x64")
set(spirv_build_path add_library(ncnn SHARED IMPORTED)
"${CMAKE_BINARY_DIR}/realesrgan-prefix/src/realesrgan-build/ncnn/glslang/SPIRV" set_target_properties(ncnn PROPERTIES
IMPORTED_LOCATION "${ncnn_base_path}/bin/ncnn.dll"
IMPORTED_IMPLIB "${ncnn_base_path}/lib/ncnn.lib"
INTERFACE_INCLUDE_DIRECTORIES "${ncnn_base_path}/include/ncnn"
) )
# Link ncnn and SPIRV libraries
target_include_directories(libvideo2x SYSTEM PRIVATE "${ncnn_base_path}/include/ncnn")
target_link_libraries(libvideo2x PRIVATE "${ncnn_base_path}/lib/ncnn.lib")
# SPIRV needs to be linked explicitly
if(CMAKE_BUILD_TYPE STREQUAL Release)
target_link_libraries(libvideo2x PRIVATE "${spirv_build_path}/Release/SPIRV.lib")
else()
target_link_libraries(libvideo2x PRIVATE "${spirv_build_path}/Debug/SPIRVd.lib")
endif()
else() else()
option(NCNN_INSTALL_SDK "" ON) option(NCNN_INSTALL_SDK "" ON)
option(SKIP_GLSLANG_INSTALL "" OFF) option(SKIP_GLSLANG_INSTALL "" OFF)
@ -277,9 +270,9 @@ else()
option(WITH_LAYER_softplus "" OFF) option(WITH_LAYER_softplus "" OFF)
add_subdirectory(third_party/ncnn) add_subdirectory(third_party/ncnn)
target_link_libraries(libvideo2x PRIVATE ncnn)
endif() endif()
endif() endif()
target_link_libraries(libvideo2x PRIVATE ncnn)
# spdlog # spdlog
if(VIDEO2X_USE_EXTERNAL_SPDLOG) if(VIDEO2X_USE_EXTERNAL_SPDLOG)
@ -294,27 +287,25 @@ else()
target_link_libraries(libvideo2x PRIVATE spdlog::spdlog_header_only) target_link_libraries(libvideo2x PRIVATE spdlog::spdlog_header_only)
endif() endif()
# Real-ESRGAN, Real-CUGAN, and RIFE # Add Real-ESRGAN, Real-CUGAN, and RIFE
option(USE_SYSTEM_NCNN "" ${VIDEO2X_USE_EXTERNAL_NCNN}) option(USE_SYSTEM_NCNN "" ${VIDEO2X_USE_EXTERNAL_NCNN})
add_subdirectory(third_party/librealesrgan_ncnn_vulkan/src) add_subdirectory(third_party/librealesrgan_ncnn_vulkan/src)
add_subdirectory(third_party/librealcugan_ncnn_vulkan/src) add_subdirectory(third_party/librealcugan_ncnn_vulkan/src)
add_subdirectory(third_party/librife_ncnn_vulkan/src) add_subdirectory(third_party/librife_ncnn_vulkan/src)
# Determine the library suffix based on the platform # Prevent the min and max macros from causing error C2589 on Windows
if(WIN32) if(WIN32)
set(suffix ${CMAKE_STATIC_LIBRARY_SUFFIX}) target_compile_definitions(librealesrgan-ncnn-vulkan PRIVATE -DNOMINMAX)
else() target_compile_definitions(librealcugan-ncnn-vulkan PRIVATE -DNOMINMAX)
set(suffix ${CMAKE_SHARED_LIBRARY_SUFFIX}) target_compile_definitions(librife-ncnn-vulkan PRIVATE -DNOMINMAX)
endif() endif()
# Link the shared library with the ncnn-Vulkan-based libraries # Link the shared library to the ncnn-Vulkan libraries
set(ncnn_vulkan_libs) target_link_libraries(libvideo2x PRIVATE
foreach(lib IN ITEMS realesrgan realcugan rife) librealesrgan-ncnn-vulkan
list(APPEND ncnn_vulkan_libs librealcugan-ncnn-vulkan
"${CMAKE_BINARY_DIR}/third_party/lib${lib}_ncnn_vulkan/src/lib${lib}-ncnn-vulkan${suffix}" librife-ncnn-vulkan
) )
endforeach()
target_link_libraries(libvideo2x PRIVATE ${ncnn_vulkan_libs})
# Determine the installation directories # Determine the installation directories
if(WIN32) if(WIN32)
@ -425,7 +416,7 @@ if(VIDEO2X_BUILD_CLI)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(video2x PRIVATE $<$<CONFIG:Debug>:/Zi /Od /MDd>) target_compile_options(video2x PRIVATE $<$<CONFIG:Debug>:/Zi /Od /MDd>)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(video2x PRIVATE -fPIC $<$<CONFIG:Debug>:-g -O0>) target_compile_options(video2x PRIVATE $<$<CONFIG:Debug>:-g -O0>)
endif() endif()
# FFmpeg # FFmpeg
@ -474,10 +465,8 @@ if(VIDEO2X_BUILD_CLI)
) )
# Suppress the -Wsign-conversion warnings for Boost.Nowide # Suppress the -Wsign-conversion warnings for Boost.Nowide
if (TARGET boost_nowide) if (TARGET boost_nowide AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(boost_nowide PRIVATE -Wno-error=sign-conversion)
target_compile_options(boost_nowide PRIVATE -Wno-error=sign-conversion)
endif()
endif() endif()
endif() endif()
target_link_libraries(video2x PRIVATE Boost::program_options) target_link_libraries(video2x PRIVATE Boost::program_options)