CMakeLists.txt 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Minimum required CMake and project declaration
  2. cmake_minimum_required(VERSION 3.5)
  3. # Enable both C and CXX languages so C and C++ toolchains are configured.
  4. project(V-Gears VERSION 0.3.0 LANGUAGES C CXX)
  5. # Provide a central common include for project-wide policies and defaults.
  6. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
  7. include(ProjectCommon)
  8. # Configure CMake options
  9. option(USE_COTIRE "Enable cotire precompiled header support" ON)
  10. option(BUILD_INSTALLER "Build the V-Gears-Installer" TRUE)
  11. option(BUILD_TESTS "Build the unit tests" FALSE)
  12. option(MULTITHREADING "Enable multithreading" TRUE)
  13. # Hint for Qt configuration dirs. Setting this early helps subprojects locate
  14. # Qt via config-mode packages when installs are in distro-specific locations.
  15. # Example: -DQT_DIR_HINT=/usr/lib/x86_64-linux-gnu/cmake
  16. set(QT_DIR_HINT "" CACHE PATH "Optional hint for Qt CMake config directory (parent of Qt5/Qt6)")
  17. if(QT_DIR_HINT)
  18. list(APPEND CMAKE_PREFIX_PATH "${QT_DIR_HINT}")
  19. if(EXISTS "${QT_DIR_HINT}/Qt5")
  20. set(Qt5_DIR "${QT_DIR_HINT}/Qt5" CACHE PATH "Qt5 dir from hint" FORCE)
  21. elseif(EXISTS "${QT_DIR_HINT}/Qt5Core")
  22. set(Qt5_DIR "${QT_DIR_HINT}/Qt5Core" CACHE PATH "Qt5 dir from hint" FORCE)
  23. endif()
  24. if(EXISTS "${QT_DIR_HINT}/Qt6")
  25. set(Qt6_DIR "${QT_DIR_HINT}/Qt6" CACHE PATH "Qt6 dir from hint" FORCE)
  26. endif()
  27. endif()
  28. # Optionally enable cotire (precompiled header/speedup).
  29. if(USE_COTIRE)
  30. include(cotire OPTIONAL RESULT_VARIABLE COTIRE_INCLUDE_RESULT)
  31. if(NOT COTIRE_INCLUDE_RESULT)
  32. message(WARNING "cotire requested but cotire.cmake not found in CMake modules; skipping")
  33. endif()
  34. endif()
  35. set(CMAKE_PACKAGE_ICON v-gears.png)
  36. # Generate version header into the build tree so source tree is not modified.
  37. set(VGEARS_VERSION ${PROJECT_VERSION})
  38. set(VGEARS_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
  39. set(VGEARS_VERSION_MINOR ${PROJECT_VERSION_MINOR})
  40. set(VGEARS_VERSION_PATCH ${PROJECT_VERSION_PATCH})
  41. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/Version.h.in ${CMAKE_BINARY_DIR}/generated/Version.h @ONLY)
  42. include_directories(${CMAKE_BINARY_DIR}/generated)
  43. # Default build type when none is supplied by the caller.
  44. if(NOT CMAKE_BUILD_TYPE)
  45. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
  46. endif()
  47. # LuaJIT is a system dependency; sol2 is header-only.
  48. find_package(PkgConfig QUIET)
  49. if(PKG_CONFIG_FOUND)
  50. pkg_check_modules(LUAJIT QUIET luajit)
  51. endif()
  52. if(LUAJIT_FOUND)
  53. set(VGEARS_LUAJIT_INCLUDE_DIRS ${LUAJIT_INCLUDE_DIRS})
  54. set(VGEARS_LUAJIT_LIBRARIES ${LUAJIT_LINK_LIBRARIES})
  55. else()
  56. find_path(VGEARS_LUAJIT_INCLUDE_DIR
  57. NAMES lua.hpp
  58. PATH_SUFFIXES luajit-2.1 luajit-2.0 luajit-5.1
  59. )
  60. find_library(VGEARS_LUAJIT_LIBRARY
  61. NAMES luajit-5.1 luajit-2.1 luajit
  62. )
  63. if(NOT VGEARS_LUAJIT_INCLUDE_DIR OR NOT VGEARS_LUAJIT_LIBRARY)
  64. message(FATAL_ERROR
  65. "LuaJIT development files were not found. Install libluajit-5.1-dev "
  66. "or set VGEARS_LUAJIT_INCLUDE_DIR and VGEARS_LUAJIT_LIBRARY."
  67. )
  68. endif()
  69. set(VGEARS_LUAJIT_INCLUDE_DIRS ${VGEARS_LUAJIT_INCLUDE_DIR})
  70. set(VGEARS_LUAJIT_LIBRARIES ${VGEARS_LUAJIT_LIBRARY})
  71. endif()
  72. # Where each part is installed. Set before src/, whose install rules use it.
  73. include(InstallDirs)
  74. # Build v-gears (and, if requested, the installer).
  75. add_subdirectory(src)
  76. # If requested, build tests
  77. if(BUILD_TESTS)
  78. enable_testing()
  79. add_subdirectory(test)
  80. endif()
  81. # Install rules for the data, documentation and desktop files, and the packages.
  82. include(Packaging)