CMakeLists.txt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. cmake_minimum_required(VERSION 3.21)
  2. project(DupFind VERSION 0.1.0 LANGUAGES CXX)
  3. set(CMAKE_CXX_STANDARD 20)
  4. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  5. option(USE_NATIVE_OPTIMIZATION "Optimize for the local machine" OFF)
  6. # 最適化と popcnt 命令出力のためのフラグ設定
  7. if(MSVC)
  8. add_compile_options(/arch:AVX2)
  9. set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON)
  10. elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
  11. add_compile_options(-mpopcnt -msse4.2)
  12. if(USE_NATIVE_OPTIMIZATION)
  13. add_compile_options(-march=native)
  14. endif()
  15. endif()
  16. # Qt 6
  17. find_package(Qt6 COMPONENTS Widgets Concurrent REQUIRED)
  18. set(CMAKE_AUTOMOC ON)
  19. set(CMAKE_AUTOUIC ON)
  20. set(CMAKE_AUTORCC ON)
  21. # OpenCVの前にProtobufを自力で見つけさせる
  22. find_package(Protobuf REQUIRED)
  23. # OpenCV
  24. find_package(OpenCV REQUIRED)
  25. # SQLite3
  26. find_package(SQLite3 REQUIRED)
  27. include_directories(include)
  28. file(GLOB_RECURSE SOURCES src/*.cpp)
  29. file(GLOB_RECURSE HEADERS include/*.hpp)
  30. add_library(DupFindCore STATIC ${SOURCES} ${HEADERS})
  31. target_link_libraries(DupFindCore
  32. PUBLIC
  33. Qt6::Widgets
  34. Qt6::Concurrent
  35. ${OpenCV_LIBS}
  36. SQLite::SQLite3
  37. )
  38. # Filter out mains from the core library sources if possible, but CMake GLOB can't filter easily inline.
  39. # Better approach: remove them explicitly.
  40. get_target_property(CORE_SOURCES DupFindCore SOURCES)
  41. list(REMOVE_ITEM CORE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
  42. list(REMOVE_ITEM CORE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/CmdMain.cpp")
  43. set_target_properties(DupFindCore PROPERTIES SOURCES "${CORE_SOURCES}")
  44. # GUI target
  45. add_executable(${PROJECT_NAME} src/main.cpp)
  46. target_link_libraries(${PROJECT_NAME} PRIVATE DupFindCore)
  47. set_target_properties(${PROJECT_NAME} PROPERTIES
  48. WIN32_EXECUTABLE ON
  49. MACOSX_BUNDLE ON
  50. )
  51. # CLI target
  52. add_executable(DupFindCmd src/CmdMain.cpp)
  53. target_link_libraries(DupFindCmd PRIVATE DupFindCore)