cmake_minimum_required(VERSION 3.21) project(DupFind VERSION 0.1.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) option(USE_NATIVE_OPTIMIZATION "Optimize for the local machine" OFF) # 最適化と popcnt 命令出力のためのフラグ設定 if(MSVC) add_compile_options(/arch:AVX2) set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") add_compile_options(-mpopcnt -msse4.2) if(USE_NATIVE_OPTIMIZATION) add_compile_options(-march=native) endif() endif() # Qt 6 find_package(Qt6 COMPONENTS Widgets Concurrent REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) # OpenCVの前にProtobufを自力で見つけさせる find_package(Protobuf REQUIRED) # OpenCV find_package(OpenCV REQUIRED) # SQLite3 find_package(SQLite3 REQUIRED) include_directories(include) file(GLOB_RECURSE SOURCES src/*.cpp) file(GLOB_RECURSE HEADERS include/*.hpp) add_library(DupFindCore STATIC ${SOURCES} ${HEADERS}) target_link_libraries(DupFindCore PUBLIC Qt6::Widgets Qt6::Concurrent ${OpenCV_LIBS} SQLite::SQLite3 ) # Filter out mains from the core library sources if possible, but CMake GLOB can't filter easily inline. # Better approach: remove them explicitly. get_target_property(CORE_SOURCES DupFindCore SOURCES) list(REMOVE_ITEM CORE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp") list(REMOVE_ITEM CORE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/CmdMain.cpp") set_target_properties(DupFindCore PROPERTIES SOURCES "${CORE_SOURCES}") # GUI target add_executable(${PROJECT_NAME} src/main.cpp) target_link_libraries(${PROJECT_NAME} PRIVATE DupFindCore) set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE ON MACOSX_BUNDLE ON ) # CLI target add_executable(DupFindCmd src/CmdMain.cpp) target_link_libraries(DupFindCmd PRIVATE DupFindCore) # ----------------------------------------------------------------------------- # Deployment Configuration (Windows) # ----------------------------------------------------------------------------- if(WIN32) # UCRTライブラリを自動的に含める set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE) include(InstallRequiredSystemLibraries) # vc_redist.x64.exeを外す if(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS) list(FILTER CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS EXCLUDE REGEX "\\.exe$") endif() # Qt6::qmake 経由で bin ディレクトリを特定し windeployqt を探す get_target_property(_qmake_exe Qt6::qmake IMPORTED_LOCATION) get_filename_component(_qt_bin_dir "${_qmake_exe}" DIRECTORY) find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}") set(DEPLOY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Deploy/DupFind") # `cmake --build build --target deploy` で起動する専用ターゲット add_custom_target(deploy # 1. 展開用ディレクトリの作成 COMMAND ${CMAKE_COMMAND} -E make_directory "${DEPLOY_DIR}" # 2. 実行ファイル本体のコピー COMMAND ${CMAKE_COMMAND} -E copy "$" "${DEPLOY_DIR}/" COMMAND ${CMAKE_COMMAND} -E copy "$" "${DEPLOY_DIR}/" # 3. リソースディレクトリのコピー COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/resources" "${DEPLOY_DIR}/resources" # 4. vcpkgがビルドディレクトリに出力した サードパーティDLL (OpenCV, SQLiteなど) の収集 COMMAND powershell -NoProfile -Command "Copy-Item -Path '$/*.dll' -Destination '${DEPLOY_DIR}/' -Force -ErrorAction SilentlyContinue" # UCRTライブラリのコピー COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} "${DEPLOY_DIR}/" # 5. windeployqt による Qt DLL (--compiler-runtime) の自動収集 COMMAND "${WINDEPLOYQT_EXECUTABLE}" --no-translations --dir "${DEPLOY_DIR}" "${DEPLOY_DIR}/$" DEPENDS ${PROJECT_NAME} DupFindCmd COMMENT "Deploying and bundling all dependencies into ${DEPLOY_DIR}..." ) endif()