Warning, /sdk/codevis/CMakeLists.txt is written in an unsupported language. File is not indexed.

0001 cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
0002 
0003 # KDE Applications version, managed by release script.
0004 set(RELEASE_SERVICE_VERSION_MAJOR "23")
0005 set(RELEASE_SERVICE_VERSION_MINOR "11")
0006 set(RELEASE_SERVICE_VERSION_MICRO "70")
0007 set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}")
0008 
0009 project(CodeVis LANGUAGES CXX C VERSION ${RELEASE_SERVICE_VERSION})
0010 
0011 option(USE_LLVM_STATIC_LIBS "Prefer the static llvm libs instead of the shared ones" OFF)
0012 option(COMPILE_TESTS "Compile tests (Needs Catch2 dependency installed)" ON)
0013 option(ENABLE_CODE_COVERAGE "Compile the app with code coverage support" OFF)
0014 option(BUILD_DESKTOP_APP "Compile the desktop app, and not just command line" ON)
0015 option(USE_QT_WEBENGINE "If set, will compile using Qt Webengine (preferred) to render HTML reports" ON)
0016 option(IGNORE_BROKEN_TESTS_KDE_CI "If set, ignores some broken tests on LLVM 16 / KDE CI." ON)
0017 option(WARNINGS_AS_ERRORS "If set, will force warnings as errors" OFF)
0018 option(ENABLE_FORTRAN_SCANNER "If set, will compile lvtclp_fortran module" OFF)
0019 option(ENABLE_PLUGINS "Compile with plugins support" ON)
0020 option(BUILD_PLUGINS "Compile all application plugins in the plugins/ directory" ON)
0021 option(ENABLE_PYTHON_PLUGINS "If set, will consider plugins implemented in Python" ON)
0022 
0023 if (NOT ENABLE_PLUGINS)
0024     set(BUILD_PLUGINS OFF)
0025     set(ENABLE_PYTHON_PLUGINS OFF)
0026 endif()
0027 
0028 set(QT_MIN_VERSION "5.12.0")
0029 set(KF5_MIN_VERSION "5.68.0")
0030 
0031 set(CMAKE_CXX_STANDARD 20)
0032 set(CMAKE_CXX_STANDARD_REQUIRED ON)
0033 set(CMAKE_CXX_EXTENSIONS OFF)
0034 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
0035 
0036 if (ENABLE_FORTRAN_SCANNER)
0037     add_compile_definitions(CT_ENABLE_FORTRAN_SCANNER=1)
0038 endif()
0039 
0040 LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
0041 LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/submodules/configuration-parser/cmake)
0042 
0043 find_package(ECM ${KF5_MIN_VERSION} QUIET REQUIRED NO_MODULE)
0044 list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
0045 if (ECM_VERSION_MAJOR LESS 5 OR (ECM_VERSION_MAJOR EQUAL 5 AND ECM_VERSION_MINOR LESS 90))
0046     set(ECM_IS_OLD TRUE)
0047 endif()
0048 
0049 # This Breaks Soci.
0050 # For the future we should migrate to QtSql or something.
0051 # Soci does *not* have a good policy regarding releases,
0052 # and the current codebase is full of smaller c++ antipatterns
0053 # include(KDECompilerSettings NO_POLICY_SCOPE)
0054 
0055 # This Breaks Catch2
0056 # Catch2 Broke it's API on a minor release, and this made
0057 # me quite sad. It's also sad to see that it doesn't
0058 # use export headers, too, so it's hard to use it on a
0059 # shared library.
0060 #include(KDECMakeSettings)
0061 
0062 include(KDEInstallDirs)
0063 include(KDEClangFormat)
0064 if (NOT ECM_IS_OLD)
0065     include(KDEGitCommitHooks)
0066     kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT)
0067 endif()
0068 
0069 include(ECMOptionalAddSubdirectory)
0070 include(ECMAddAppIcon)
0071 include(ECMInstallIcons)
0072 if (NOT ECM_IS_OLD)
0073     include(ECMDeprecationSettings)
0074 endif()
0075 include(ECMEnableSanitizers) 
0076 
0077 include(AddTargetLibrary)
0078 include(GenerateExportHeader)
0079 include(GetGitVersion)
0080 include(GetDate)
0081 include(CodevisDeployPlugin)
0082 
0083 include(FeatureSummary)
0084 find_package(Doxygen)
0085 find_package(SQLite3 REQUIRED)
0086 
0087 foreach(LLVM_VER 18 17 16 15 14)
0088     find_package(LLVM ${LLVM_VER})
0089     if (LLVM_FOUND)
0090         break()
0091     endif()
0092 endforeach()
0093 
0094 if (NOT LLVM_FOUND)
0095     MESSAGE(FATAL "LLVM Not Found")
0096 endif()
0097 
0098 find_package(Clang REQUIRED PATHS "${LLVM_LIBRARY_DIR}/cmake/clang/" NO_DEFAULT_PATH)
0099 
0100 set(CMAKE_AUTOMOC FALSE)
0101 set(CMAKE_AUTOUIC FALSE)
0102 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
0103 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
0104 
0105 if (QT_MAJOR_VERSION STREQUAL "6")
0106     set(QT_REQUIRED_VERSION "6.4.0")
0107     set(KF_MIN_VERSION "5.240.0")
0108     set(KF_MAJOR_VERSION "6")
0109 else()
0110     set(KF_MAJOR_VERSION "5")
0111 endif()
0112 
0113 # Set a default build type if none was specified
0114 set(default_build_type "Release")
0115 
0116 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
0117   message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
0118   set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
0119       STRING "Choose the type of build." FORCE)
0120   # Set the possible values of build type for cmake-gui
0121   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
0122     "MinSizeRel" "RelWithDebInfo")
0123 endif()
0124 
0125 if (UNIX)
0126     if (APPLE)
0127         set(CMAKE_MACOSX_RPATH 1)
0128     endif()
0129     set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
0130 endif()
0131 
0132 set(SOCI_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/soci)
0133 
0134 # Required here so that the version comparison below works
0135 find_package(Qt${QT_MAJOR_VERSION}Core ${QT_MIN_VERSION} CONFIG REQUIRED)
0136 if (QT_MAJOR_VERSION STREQUAL "6")
0137     find_package(Qt6Core5Compat)
0138 endif()
0139 message("-- Qt Version: ${QT_MAJOR_VERSION}")
0140 message("-- LLVM Version: ${LLVM_VERSION}")
0141 
0142 if (BUILD_DESKTOP_APP)
0143     find_package(Qt${QT_MAJOR_VERSION} CONFIG REQUIRED COMPONENTS Gui Widgets Svg)
0144     find_package(KF${KF_MAJOR_VERSION} ${KF5_MIN_VERSION} REQUIRED COMPONENTS
0145         Archive
0146         Config
0147         Crash
0148         CoreAddons
0149         WidgetsAddons
0150         TextEditor
0151         XmlGui
0152         NewStuffCore
0153         NewStuff
0154         Notifications
0155         KCMUtils
0156         I18n
0157         OPTIONAL_COMPONENTS
0158         DocTools
0159     )
0160     # KF5 doesn't have split version, so we build it here
0161     string(REPLACE "." ";" VERSION_LIST "${KF${KF_MAJOR_VERSION}_VERSION}")
0162     list(GET VERSION_LIST 0 KF_VERSION_MAJOR)
0163     list(GET VERSION_LIST 1 KF_VERSION_MINOR)
0164     list(GET VERSION_LIST 2 KF_VERSION_PATCH)
0165     if (KF_VERSION_MAJOR LESS 5 OR (KF_VERSION_MAJOR EQUAL 5 AND KF_VERSION_MINOR LESS 90))
0166         set(KDE_FRAMEWORKS_IS_OLD TRUE)
0167         add_compile_definitions(KDE_FRAMEWORKS_IS_OLD=1)
0168     else()
0169         set(KDE_FRAMEWORKS_IS_OLD FALSE)
0170     endif()
0171 
0172     if (USE_QT_WEBENGINE)
0173         find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS WebEngineWidgets)
0174         add_compile_definitions(USE_WEB_ENGINE=1)
0175     endif()
0176     if (UNIX AND NOT APPLE)
0177         find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS DBus)
0178     endif()
0179 else()
0180     find_package(Qt${QT_MAJOR_VERSION} CONFIG REQUIRED COMPONENTS Core)
0181     find_package(KF${KF_MAJOR_VERSION} ${KF5_MIN_VERSION} REQUIRED COMPONENTS Archive)
0182 endif()
0183 
0184 find_package(Catch2)
0185 if (NOT Catch2_FOUND)
0186     set(COMPILE_TESTS OFF)
0187 endif()
0188 
0189 if (COMPILE_TESTS)
0190     enable_testing()
0191     find_package(Qt${QT_MAJOR_VERSION} CONFIG REQUIRED COMPONENTS Test)
0192 
0193     set(TEST_PRJ_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lvtclp/systemtests)
0194     set(TEST_PLG_PATH ${CMAKE_BINARY_DIR}/lvtplg/testplugins)
0195     set(LAKOSDIAGRAM_PYSCRIPTS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/python/codegeneration)
0196 
0197     configure_file(
0198         "test-project-paths.h.in"
0199         "test-project-paths.h"
0200     )
0201 
0202     if (Catch2_VERSION_MAJOR EQUAL 2)
0203         SET(CATCH2_INTERNAL_INCLUDE_FILE "catch2/catch.hpp")
0204         configure_file(
0205             "${PROJECT_SOURCE_DIR}/catch2-local-includes.h.in"
0206             "${PROJECT_BINARY_DIR}/catch2-local-includes.h"
0207         )
0208     else()
0209         SET(CATCH2_INTERNAL_INCLUDE_FILE "catch2/catch_all.hpp")
0210         configure_file(
0211             "${PROJECT_SOURCE_DIR}/catch2-local-includes.h.in"
0212             "${PROJECT_BINARY_DIR}/catch2-local-includes.h"
0213         )
0214     endif()
0215     INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
0216 endif()
0217 
0218 # find header files for clang tools to use for system includes
0219 if (NOT CT_CLANG_HEADERS_DIR)
0220     set(CT_CLANG_HEADERS_DIR "${LLVM_LIBRARY_DIR}/clang/${LLVM_PACKAGE_VERSION}/include")
0221 endif()
0222 message("Looking for clang tool headers at ${CT_CLANG_HEADERS_DIR}. You can change this by defining CT_CLANG_HEADERS_DIR")
0223 if (NOT EXISTS "${CT_CLANG_HEADERS_DIR}/stddef.h")
0224     message("Cannot find clang tool headers at ${CT_CLANG_HEADERS_DIR}, Errors might happen in runtime.")
0225 endif()
0226 
0227 if (MSVC)
0228     # On c++17 msvc deprecated the use of inheriting from std::iterator for
0229     # implementing iterators. and it spams your build with *too many* warnings
0230     # that are mostly not userfull, specially if this happens inside of libraries,
0231     # such as boost.
0232     add_definitions(/D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
0233 
0234     # Silence most warnings. We have *so many* warnings from clang that's
0235     # impossible to filter anything.
0236     add_definitions(/W0)
0237 endif()
0238 
0239 
0240 option(SCANBUILD "Trimmed build for scan-build analysis" OFF)
0241 if (SCANBUILD)
0242   add_compile_definitions(CT_SCANBUILD)
0243 endif()
0244 
0245 if (DOXYGEN_FOUND)
0246   add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/doc/reference
0247     COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/doc/reference
0248     COMMENT "Creating output directory ... "
0249   )
0250   add_custom_target(doxygen
0251     ${DOXYGEN_EXECUTABLE}
0252     WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
0253     DEPENDS ${PROJECT_SOURCE_DIR}/doc/reference
0254     COMMENT "Doxygen ...")
0255 endif (DOXYGEN_FOUND)
0256 
0257 if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
0258     # warnings encountered in llvm/clang headers
0259     set(SKIP_CLANG_WARNINGS "-Wno-unused-parameter -Wno-comment -Wno-strict-aliasing -Wno-nonnull -Wno-deprecated-declarations")
0260     if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
0261         SET(SKIP_CLANG_WARNINGS "${SKIP_CLANG_WARNINGS}  -Wno-error=maybe-uninitialized")
0262     endif()
0263     set(CMAKE_CXX_FLAGS
0264         "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wno-gnu-zero-variadic-macro-arguments ${SKIP_CLANG_WARNINGS}")
0265     if (WARNINGS_AS_ERRORS)
0266         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
0267     endif()
0268 endif()
0269 
0270 if (APPLE)
0271     SET(MACOSX_BUNDLE_ICON_FILE iconset.icns)
0272 endif()
0273 
0274 cmake_language(CALL
0275     qt${QT_MAJOR_VERSION}_add_resources
0276     resources_SRCS
0277     resources.qrc
0278 )
0279 
0280 add_library(resources STATIC ${resources_SRCS})
0281 
0282 get_git_version(GIT_VERSION)
0283 get_git_authors(GIT_AUTHORS)
0284 get_date(CURRENT_DATE)
0285 
0286 configure_file (
0287     "${PROJECT_SOURCE_DIR}/version.h.in"
0288     "${PROJECT_BINARY_DIR}/version.h"
0289 )
0290 
0291 set(SYSTEM_EXTRA_LIBRARIES ${SYSTEM_EXTRA_LIBRARIES} ${SQLite3_LIBRARIES})
0292 
0293 add_subdirectory(thirdparty)
0294 
0295 if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
0296     if (ENABLE_CODE_COVERAGE)
0297         # For code coverage, must be in Debug mode with no optimizations
0298         include(CodeCoverage)
0299         append_coverage_compiler_flags()
0300         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
0301     else()
0302         if (CMAKE_BUILD_TYPE MATCHES DEBUG)
0303             set(DEFAULT_BUILD_OPTIMIZATION OFF)
0304         else()
0305             set(DEFAULT_BUILD_OPTIMIZATION ON)
0306         endif()
0307         option(ENABLE_OPTIMIZATIONS "Enable optimizations" ${DEFAULT_BUILD_OPTIMIZATION})
0308 
0309         if (ENABLE_OPTIMIZATIONS)
0310             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
0311         else()
0312             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
0313         endif()
0314     endif()
0315 endif()
0316 
0317 if (ENABLE_PYTHON_PLUGINS)
0318     add_compile_definitions(ENABLE_PYTHON_PLUGINS=1)
0319 endif()
0320 
0321 add_subdirectory(lvtcgn)
0322 add_subdirectory(lvtclp)
0323 add_subdirectory(lvtldr)
0324 add_subdirectory(lvtmdb)
0325 add_subdirectory(lvtprj)
0326 add_subdirectory(lvtshr)
0327 add_subdirectory(lvttst)
0328 
0329 if (BUILD_DESKTOP_APP)
0330     kconfig_add_kcfg_files(CONFIGURATION_SRCS GENERATE_MOC preferences.kcfgc)
0331     add_library(lakospreferences SHARED ${CONFIGURATION_SRCS})
0332     add_library(Codethink::lakospreferences ALIAS lakospreferences)
0333     generate_export_header(lakospreferences)
0334 
0335     target_link_libraries(lakospreferences
0336         Qt${QT_MAJOR_VERSION}::Widgets
0337         KF${KF_MAJOR_VERSION}::ConfigCore
0338         KF${KF_MAJOR_VERSION}::ConfigGui
0339     )
0340 
0341     target_include_directories(lakospreferences
0342     PUBLIC
0343         $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
0344         $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
0345         $<INSTALL_INTERFACE:include/lakos/preferences>
0346     )
0347 
0348     if (NOT ${KDE_FRAMEWORKS_IS_OLD})
0349         install(TARGETS
0350             lakospreferences
0351             DESTINATION ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}
0352         )
0353     endif()
0354 
0355     add_subdirectory(doc)
0356 
0357     if (ENABLE_PLUGINS)
0358         add_subdirectory(lvtplg)
0359         add_subdirectory(plugins)
0360     endif()
0361 
0362     add_subdirectory(lvtmdl)
0363     add_subdirectory(lvtclr)
0364     add_subdirectory(lvtqtc)
0365     add_subdirectory(lvtqtd)
0366     add_subdirectory(lvtqtw)
0367 
0368     add_subdirectory(desktopapp)
0369 endif()
0370 
0371 
0372 if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND ENABLE_CODE_COVERAGE)
0373     # Warning: Not setting up any TARGET below. Assume ctest will be run before running `make coverage` so that we dont
0374     # need to keep track of which tests are dependencies for the coverage (all of them are).
0375     setup_target_for_coverage_gcovr_html(
0376         NAME coverage
0377         BASE_DIRECTORY "${PROJECT_SOURCE_DIR}"
0378     )
0379 endif()
0380 
0381 feature_summary(INCLUDE_QUIET_PACKAGES WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
0382 
0383 install(
0384   FILES
0385     ${CMAKE_CURRENT_SOURCE_DIR}/database-spec/cad_db.sql
0386     ${CMAKE_CURRENT_SOURCE_DIR}/database-spec/codebase_db.sql
0387   DESTINATION
0388     ${KDE_INSTALL_DATAROOTDIR}/codevis/database-spec
0389 )
0390