CMakeLists.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. cmake_minimum_required (VERSION 3.12)
  2. project(VNote
  3. VERSION 2.2.0
  4. DESCRIPTION "VNote is a markdown note taking application"
  5. HOMEPAGE_URL "https://tamlok.github.io/vnote"
  6. LANGUAGES C CXX)
  7. set(CMAKE_CXX_STANDARD 14)
  8. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  9. ## Qt5 configurations
  10. set(CMAKE_AUTOMOC ON)
  11. set(CMAKE_AUTOUIC ON)
  12. set(CMAKE_AUTORCC ON)
  13. ## Default Qt5 path
  14. if(WIN32)
  15. set(Qt5_DIR "c:/Qt/Qt5.9.7/5.9.7/msvc2017_64/lib/cmake/Qt5/" CACHE PATH "directory where Qt5Config.cmake exists.")
  16. elseif(APPLE)
  17. set(Qt5_DIR "/usr/local/Cellar/qt/5.9.7/clang_64/lib/cmake/Qt5/" CACHE PATH "directory where Qt5Config.cmake exists.")
  18. else()
  19. set(Qt5_DIR "" CACHE PATH "directory where Qt5Config.cmake exists.")
  20. endif()
  21. find_package(Qt5 COMPONENTS Core Gui Network PrintSupport WebChannel WebEngine
  22. WebEngineWidgets Positioning Svg Widgets LinguistTools
  23. REQUIRED NO_DEFAULT_PATH)
  24. ## hoedown library
  25. add_library(hoedown STATIC
  26. hoedown/src/autolink.c hoedown/src/document.c hoedown/src/html.c hoedown/src/html_smartypants.c
  27. hoedown/src/version.c hoedown/src/buffer.c hoedown/src/escape.c hoedown/src/html_blocks.c
  28. hoedown/src/stack.c )
  29. target_link_libraries(hoedown PRIVATE Qt5::Core Qt5::Gui)
  30. ## peg-highlight library
  31. add_library(peg-highlight STATIC peg-highlight/pmh_parser.c peg-highlight/pmh_styleparser.c)
  32. target_link_libraries(peg-highlight PRIVATE Qt5::Core Qt5::Gui)
  33. ## project sources
  34. add_subdirectory(src)
  35. option(CMake_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
  36. if(CMake_RUN_CLANG_TIDY)
  37. if(CMake_SOURCE_DIR STREQUAL CMake_BINARY_DIR)
  38. message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
  39. endif()
  40. find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
  41. if(NOT CLANG_TIDY_COMMAND)
  42. message(WARNING "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
  43. set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE)
  44. else()
  45. set(CLANG_TIDY_CHECKS "-*,modernize-*")
  46. set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND};-checks=${CLANG_TIDY_CHECKS};-header-filter='${CMAKE_SOURCE_DIR}/src/*'")
  47. endif()
  48. # Create a preprocessor definition that depends on .clang-tidy content so
  49. # the compile command will change when .clang-tidy changes. This ensures
  50. # that a subsequent build re-runs clang-tidy on all sources even if they
  51. # do not otherwise need to be recompiled. Nothing actually uses this
  52. # definition. We add it to targets on which we run clang-tidy just to
  53. # get the build dependency on the .clang-tidy file.
  54. file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
  55. set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
  56. unset(clang_tidy_sha1)
  57. endif()
  58. option(CMake_RUN_IWYU "Run include-what-you-use with the compiler." OFF)
  59. if(CMake_RUN_IWYU)
  60. find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
  61. if(NOT IWYU_COMMAND)
  62. message(WARNING "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
  63. else()
  64. set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
  65. "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
  66. list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
  67. endif()
  68. endif()
  69. # Clazy is a Qt oriented code checker based on clang framework. Krazy's little brother.
  70. set(CMake_RUN_CLAZY OFF CACHE BOOL "Add clazy check for builds")
  71. if(ENABLE_CLAZY)
  72. find_program(CLAZY_EXECUTABLE NAMES clazy PATHS /usr/local/llvm/bin /usr/local/bin /opt/clazy/bin)
  73. if(CLAZY_EXECUTABLE)
  74. message(STATUS "clazy found: ${CLAZY_EXECUTABLE}")
  75. else()
  76. message(AUTHOR_WARNING "clazy not found.")
  77. endif()
  78. endif()
  79. # vim: ts=2 sw=2 sts=2 et