Просмотр исходного кода

build: add initial CMake support for core and modules

- add initial CMake support for core and modules (GH #4043)
- core/resolve: fix compilation if DNS_USE_CACHE not defined
- core/forward: define return even if USE_TCP is not defined
- includes documentation building, initial support for other architectures (arm64) and cross-compilation
- support for gcc and clang compiler
- initial support for CPack packaging
- most modules were already integrated, a few remaining with special dependencies are missing
- usage and extensions documentation can be found in the kamailio wiki
Xenofon Karamanos 9 месяцев назад
Родитель
Сommit
06a6e4a54b
100 измененных файлов с 4729 добавлено и 2 удалено
  1. 84 0
      .github/workflows/cmake_build.yml
  2. 2 0
      .gitignore
  3. 61 0
      CMakeLists.txt
  4. 54 0
      CMakelists.notes
  5. 28 0
      cmake/aarch64-toolchain.cmake
  6. 240 0
      cmake/cmake-format.py
  7. 32 0
      cmake/cmake_uninstall.cmake.in
  8. 55 0
      cmake/compiler-specific.cmake
  9. 318 0
      cmake/defs.cmake
  10. 686 0
      cmake/groups.cmake
  11. 182 0
      cmake/modules/FindBerkeleyDB.cmake
  12. 151 0
      cmake/modules/FindErlang.cmake
  13. 119 0
      cmake/modules/FindLdap.cmake
  14. 60 0
      cmake/modules/FindLibev.cmake
  15. 68 0
      cmake/modules/FindMariaDBClient.cmake
  16. 964 0
      cmake/modules/FindMySQL.cmake
  17. 82 0
      cmake/modules/FindNETSNMP.cmake
  18. 115 0
      cmake/modules/FindOracle.cmake
  19. 51 0
      cmake/modules/FindRadius.cmake
  20. 74 0
      cmake/modules_docs.cmake
  21. 97 0
      cmake/os-specific.cmake
  22. 141 0
      src/CMakeLists.txt
  23. 57 0
      src/core/CMakeLists.txt
  24. 6 0
      src/core/autover.h.in
  25. 2 2
      src/core/forward.h
  26. 8 0
      src/core/resolve.c
  27. 30 0
      src/lib/CMakeLists.txt
  28. 22 0
      src/lib/ims/CMakeLists.txt
  29. 18 0
      src/lib/print/CMakeLists.txt
  30. 17 0
      src/lib/srdb1/CMakeLists.txt
  31. 15 0
      src/lib/srdb2/CMakeLists.txt
  32. 16 0
      src/lib/trie/CMakeLists.txt
  33. 143 0
      src/modules/CMakeLists.txt
  34. 10 0
      src/modules/acc/CMakeLists.txt
  35. 8 0
      src/modules/acc_diameter/CMakeLists.txt
  36. 12 0
      src/modules/acc_json/CMakeLists.txt
  37. 11 0
      src/modules/acc_radius/CMakeLists.txt
  38. 10 0
      src/modules/alias_db/CMakeLists.txt
  39. 14 0
      src/modules/app_java/CMakeLists.txt
  40. 8 0
      src/modules/app_jsdt/CMakeLists.txt
  41. 22 0
      src/modules/app_lua/CMakeLists.txt
  42. 14 0
      src/modules/app_perl/CMakeLists.txt
  43. 11 0
      src/modules/app_python/CMakeLists.txt
  44. 10 0
      src/modules/app_python3/CMakeLists.txt
  45. 10 0
      src/modules/app_python3s/CMakeLists.txt
  46. 10 0
      src/modules/app_ruby/CMakeLists.txt
  47. 12 0
      src/modules/app_ruby_proc/CMakeLists.txt
  48. 8 0
      src/modules/async/CMakeLists.txt
  49. 9 0
      src/modules/auth/CMakeLists.txt
  50. 10 0
      src/modules/auth_db/CMakeLists.txt
  51. 8 0
      src/modules/auth_diameter/CMakeLists.txt
  52. 8 0
      src/modules/auth_ephemeral/CMakeLists.txt
  53. 11 0
      src/modules/auth_radius/CMakeLists.txt
  54. 8 0
      src/modules/auth_xkeys/CMakeLists.txt
  55. 8 0
      src/modules/avp/CMakeLists.txt
  56. 10 0
      src/modules/avpops/CMakeLists.txt
  57. 8 0
      src/modules/benchmark/CMakeLists.txt
  58. 8 0
      src/modules/blst/CMakeLists.txt
  59. 8 0
      src/modules/call_control/CMakeLists.txt
  60. 8 0
      src/modules/call_obj/CMakeLists.txt
  61. 10 0
      src/modules/carrierroute/CMakeLists.txt
  62. 10 0
      src/modules/cdp/CMakeLists.txt
  63. 8 0
      src/modules/cdp_avp/CMakeLists.txt
  64. 10 0
      src/modules/cfg_db/CMakeLists.txt
  65. 10 0
      src/modules/cfg_rpc/CMakeLists.txt
  66. 8 0
      src/modules/cfgt/CMakeLists.txt
  67. 8 0
      src/modules/cfgutils/CMakeLists.txt
  68. 18 0
      src/modules/cnxcc/CMakeLists.txt
  69. 8 0
      src/modules/corex/CMakeLists.txt
  70. 10 0
      src/modules/counters/CMakeLists.txt
  71. 12 0
      src/modules/cplc/CMakeLists.txt
  72. 10 0
      src/modules/crypto/CMakeLists.txt
  73. 12 0
      src/modules/ctl/CMakeLists.txt
  74. 22 0
      src/modules/db2_ldap/CMakeLists.txt
  75. 10 0
      src/modules/db2_ops/CMakeLists.txt
  76. 12 0
      src/modules/db_berkeley/CMakeLists.txt
  77. 10 0
      src/modules/db_cluster/CMakeLists.txt
  78. 10 0
      src/modules/db_flatstore/CMakeLists.txt
  79. 17 0
      src/modules/db_mongodb/CMakeLists.txt
  80. 19 0
      src/modules/db_mysql/CMakeLists.txt
  81. 16 0
      src/modules/db_oracle/CMakeLists.txt
  82. 13 0
      src/modules/db_perlvdb/CMakeLists.txt
  83. 14 0
      src/modules/db_postgres/CMakeLists.txt
  84. 16 0
      src/modules/db_redis/CMakeLists.txt
  85. 12 0
      src/modules/db_sqlite/CMakeLists.txt
  86. 10 0
      src/modules/db_text/CMakeLists.txt
  87. 13 0
      src/modules/db_unixodbc/CMakeLists.txt
  88. 8 0
      src/modules/debugger/CMakeLists.txt
  89. 10 0
      src/modules/dialog/CMakeLists.txt
  90. 10 0
      src/modules/dialplan/CMakeLists.txt
  91. 10 0
      src/modules/dispatcher/CMakeLists.txt
  92. 8 0
      src/modules/diversion/CMakeLists.txt
  93. 8 0
      src/modules/dlgs/CMakeLists.txt
  94. 10 0
      src/modules/dmq/CMakeLists.txt
  95. 8 0
      src/modules/dmq_usrloc/CMakeLists.txt
  96. 19 0
      src/modules/dnssec/CMakeLists.txt
  97. 10 0
      src/modules/domain/CMakeLists.txt
  98. 10 0
      src/modules/domainpolicy/CMakeLists.txt
  99. 10 0
      src/modules/drouting/CMakeLists.txt
  100. 8 0
      src/modules/enum/CMakeLists.txt

+ 84 - 0
.github/workflows/cmake_build.yml

@@ -0,0 +1,84 @@
+# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
+# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
+name: CMake on multiple platforms
+
+on:
+  # Allows you to run this workflow manually from the Actions tab
+  workflow_dispatch:
+  # push:
+  #   branches: [ cmake ]
+  pull_request:
+    branches: [ cmake ]
+
+jobs:
+  build:
+    runs-on: ${{ matrix.os }}
+
+    strategy:
+      # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
+      fail-fast: false
+
+      # Set up a matrix to run the following 3 configurations:
+      # 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
+      # 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
+      # 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
+      #
+      # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
+      matrix:
+        os: [ubuntu-latest]
+        build_type: [Release]
+        c_compiler: [gcc, clang] #, cl]
+        include:
+          - os: ubuntu-latest
+            c_compiler: gcc
+            cpp_compiler: g++
+          - os: ubuntu-latest
+            c_compiler: clang
+            cpp_compiler: clang++
+          - os: ubuntu-latest
+            c_compiler: aarch64-linux-gnu-gcc
+            cpp_compiler: aarch64-linux-gnu-g++
+            target_arch: aarch64
+            build_type: Release
+
+    steps:
+    - uses: actions/checkout@v4
+
+    - name: Set reusable strings
+      # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
+      id: strings
+      shell: bash
+      run: |
+        echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
+        if [ "${{ matrix.target_arch }}" == "aarch64" ]; then
+          echo "cmake-toolchain-file=${{ github.workspace }}/cmake/aarch64-toolchain.cmake" >> "$GITHUB_OUTPUT"
+        else
+          echo "cmake-toolchain-file=" >> "$GITHUB_OUTPUT"
+        fi
+
+    - name: Install cross-compiler
+      if: matrix.target_arch == 'aarch64'
+      run: |
+        sudo apt update
+        sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
+
+    - name: Configure CMake
+      # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
+      # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
+      run: >
+        cmake -B ${{ steps.strings.outputs.build-output-dir }}
+        ${{ steps.strings.outputs.cmake-toolchain-file != '' && format('-DCMAKE_TOOLCHAIN_FILE={0}', steps.strings.outputs.cmake-toolchain-file) }}
+        ${{ steps.strings.outputs.cmake-toolchain-file == '' && format('-DCMAKE_CXX_COMPILER={0}', matrix.cpp_compiler) || '' }}
+        ${{ steps.strings.outputs.cmake-toolchain-file == '' && format('-DCMAKE_C_COMPILER={0}', matrix.c_compiler) || '' }}
+        -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
+        -S ${{ github.workspace }}
+
+    - name: Build
+      # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
+      run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
+
+    - name: Test
+      working-directory: ${{ steps.strings.outputs.build-output-dir }}
+      # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
+      # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
+      run: ctest --build-config ${{ matrix.build_type }}

+ 2 - 0
.gitignore

@@ -8,6 +8,8 @@ makecfg.lst
 config.mak
 modules.lst
 # ignore dependency files
+build*/*
+
 *.d
 # ignore binary files and objects
 /ser

+ 61 - 0
CMakeLists.txt

@@ -0,0 +1,61 @@
+cmake_minimum_required(VERSION 3.10)
+
+# Use cmake -DCMAKE_SYSTEM_NAME .. for cross-compiling (inside build directory)
+
+# Set the project name
+project(kamailio VERSION 6.0.0)
+
+# Set the version number
+set(EXTRAVERSION "-dev2")
+set(RELEASE "${PROJECT_VERSION}${EXTRAVERSION}")
+
+message(STATUS "PROJECT_VERSION: ${PROJECT_VERSION}")
+message(STATUS "RELEASE:  ${RELEASE}")
+
+math(
+  EXPR
+  VERSIONVAL
+  "${PROJECT_VERSION_MAJOR}*1000000 + ${PROJECT_VERSION_MINOR}*1000 + ${PROJECT_VERSION_PATCH}"
+)
+message(STATUS "VERSIONVAL: ${VERSIONVAL}")
+
+# Specify the C standard
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_C_STANDARD_REQUIRED True)
+
+# -----------------------
+# Main project name
+# -----------------------
+# main binary name
+set(MAIN_NAME "kamailio")
+# use kamailio config
+set(CFG_NAME "kamailio")
+
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
+
+# Add the source directory
+add_subdirectory(src)
+
+# Add utils
+add_subdirectory(utils/kamctl)
+
+# TODO: Packaging stuuf. These should be on different file propably
+set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
+set(CPACK_PACKAGE_NAME kamailio)
+set(CPACK_GENERATOR DEB)
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "test")
+
+include(CPack)
+
+# Add uninstall target
+if(NOT TARGET uninstall)
+  configure_file(
+    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
+    "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake" IMMEDIATE @ONLY
+  )
+
+  add_custom_target(
+    uninstall COMMAND ${CMAKE_COMMAND} -P
+                      ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake
+  )
+endif()

+ 54 - 0
CMakelists.notes

@@ -0,0 +1,54 @@
+USE_TCP is required 
+---
+error: invalid use of undefined type ‘struct tcp_connection’
+==================
+
+USE_DANGLE is required
+----
+warning: ‘tcp_proto_no’ defined but not used [-Wunused-variable]
+==================
+
+USE_TLS requires TLS_HOOKS support
+
+#ifdef CORE_TLS
+#include "core/tls/tls_init.h" THIS FOLDER DOES not exist
+#define tls_has_init_si() 1
+#define tls_loaded() 1
+#else
+#include "core/tls_hooks_init.h"
+
+CORE_TLS obsolete?
+==================
+
+USE_NAPTR is required also requires USE_DNS_CACHE
+
+create_srv_name is not defined
+
+==================
+
+F_MALLOC and Q_MALLOC and TSLF_MALLOC are required
+undefined reference to `fm_malloc_init_shm_manager' same for others
+
+This also requires MALLOC_STATS to compile or else it will give 
+```
+error: ‘SREV_PKG_UPDATE_STATS’ undeclared (first use in this function)
+  820 |   sr_event_exec(SREV_PKG_UPDATE_STATS, 0);
+```
+
+==================
+
+REQUIRES #ifdef STATISTICS
+
+pv_stats.c:49:2: error: unknown type name ‘stat_var’
+   49 |  stat_var *stat;
+
+tmx_mod.c:92:1: error: unknown type name ‘stat_var’; did you mean ‘start_retr’?
+
+registrar.h:117:8: error: unknown type name ‘stat_var’
+
+usrloc/udomain.h:53:2: error: unknown type name ‘stat_var’
+   53 |  stat_var *users;
+
+==================
+
+presence requires libxml

+ 28 - 0
cmake/aarch64-toolchain.cmake

@@ -0,0 +1,28 @@
+set(CMAKE_SYSTEM_NAME Linux)
+set(CMAKE_SYSTEM_PROCESSOR aarch64)
+
+find_program(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
+find_program(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
+
+if(NOT CMAKE_C_COMPILER)
+  message(FATAL_ERROR "aarch64-linux-gnu-g++")
+endif()
+
+if(NOT CMAKE_CXX_COMPILER)
+  message(FATAL_ERROR "aarch64-linux-gnu-g++")
+endif()
+
+# Where to look for the target environment. (More paths can be added here)
+set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu)
+# set(CMAKE_SYSROOT /usr/aarch64-linux-gnu)
+
+# Adjust the default behavior of the FIND_XXX() commands: search programs in the
+# host environment only.
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+
+# Search headers and libraries in the target environment only.
+# set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+# set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+# set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+
+set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE arm64)

+ 240 - 0
cmake/cmake-format.py

@@ -0,0 +1,240 @@
+# ----------------------------------
+# Options affecting listfile parsing
+# ----------------------------------
+with section("parse"): # type: ignore
+
+  # Specify structure for custom cmake functions
+  additional_commands = { 'foo': { 'flags': ['BAR', 'BAZ'],
+             'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}}
+
+  # Override configurations per-command where available
+  override_spec = {}
+
+  # Specify variable tags.
+  vartags = []
+
+  # Specify property tags.
+  proptags = []
+
+# -----------------------------
+# Options affecting formatting.
+# -----------------------------
+with section("format"): # type: ignore
+
+  # Disable formatting entirely, making cmake-format a no-op
+  disable = False
+
+  # How wide to allow formatted cmake files
+  line_width = 80
+
+  # How many spaces to tab for indent
+  tab_size = 2
+
+  # If true, lines are indented using tab characters (utf-8 0x09) instead of
+  # <tab_size> space characters (utf-8 0x20). In cases where the layout would
+  # require a fractional tab character, the behavior of the  fractional
+  # indentation is governed by <fractional_tab_policy>
+  use_tabchars = False
+
+  # If <use_tabchars> is True, then the value of this variable indicates how
+  # fractional indentions are handled during whitespace replacement. If set to
+  # 'use-space', fractional indentation is left as spaces (utf-8 0x20). If set
+  # to `round-up` fractional indentation is replaced with a single tab character
+  # (utf-8 0x09) effectively shifting the column to the next tabstop
+  fractional_tab_policy = 'use-space'
+
+  # If an argument group contains more than this many sub-groups (parg or kwarg
+  # groups) then force it to a vertical layout.
+  max_subgroups_hwrap = 2
+
+  # If a positional argument group contains more than this many arguments, then
+  # force it to a vertical layout.
+  max_pargs_hwrap = 6
+
+  # If a cmdline positional group consumes more than this many lines without
+  # nesting, then invalidate the layout (and nest)
+  max_rows_cmdline = 2
+
+  # If true, separate flow control names from their parentheses with a space
+  separate_ctrl_name_with_space = False
+
+  # If true, separate function names from parentheses with a space
+  separate_fn_name_with_space = False
+
+  # If a statement is wrapped to more than one line, than dangle the closing
+  # parenthesis on its own line.
+  dangle_parens = True
+
+  # If the trailing parenthesis must be 'dangled' on its on line, then align it
+  # to this reference: `prefix`: the start of the statement,  `prefix-indent`:
+  # the start of the statement, plus one indentation  level, `child`: align to
+  # the column of the arguments
+  dangle_align = 'prefix'
+
+  # If the statement spelling length (including space and parenthesis) is
+  # smaller than this amount, then force reject nested layouts.
+  min_prefix_chars = 4
+
+  # If the statement spelling length (including space and parenthesis) is larger
+  # than the tab width by more than this amount, then force reject un-nested
+  # layouts.
+  max_prefix_chars = 10
+
+  # If a candidate layout is wrapped horizontally but it exceeds this many
+  # lines, then reject the layout.
+  max_lines_hwrap = 2
+
+  # What style line endings to use in the output.
+  line_ending = 'unix'
+
+  # Format command names consistently as 'lower' or 'upper' case
+  command_case = 'canonical'
+
+  # Format keywords consistently as 'lower' or 'upper' case
+  keyword_case = 'unchanged'
+
+  # A list of command names which should always be wrapped
+  always_wrap = []
+
+  # If true, the argument lists which are known to be sortable will be sorted
+  # lexicographicall
+  enable_sort = True
+
+  # If true, the parsers may infer whether or not an argument list is sortable
+  # (without annotation).
+  autosort = False
+
+  # By default, if cmake-format cannot successfully fit everything into the
+  # desired linewidth it will apply the last, most agressive attempt that it
+  # made. If this flag is True, however, cmake-format will print error, exit
+  # with non-zero status code, and write-out nothing
+  require_valid_layout = False
+
+  # A dictionary mapping layout nodes to a list of wrap decisions. See the
+  # documentation for more information.
+  layout_passes = {}
+
+# ------------------------------------------------
+# Options affecting comment reflow and formatting.
+# ------------------------------------------------
+with section("markup"): # type: ignore
+
+  # What character to use for bulleted lists
+  bullet_char = '*'
+
+  # What character to use as punctuation after numerals in an enumerated list
+  enum_char = '.'
+
+  # If comment markup is enabled, don't reflow the first comment block in each
+  # listfile. Use this to preserve formatting of your copyright/license
+  # statements.
+  first_comment_is_literal = False
+
+  # If comment markup is enabled, don't reflow any comment block which matches
+  # this (regex) pattern. Default is `None` (disabled).
+  literal_comment_pattern = None
+
+  # Regular expression to match preformat fences in comments default=
+  # ``r'^\s*([`~]{3}[`~]*)(.*)$'``
+  fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
+
+  # Regular expression to match rulers in comments default=
+  # ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'``
+  ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
+
+  # If a comment line matches starts with this pattern then it is explicitly a
+  # trailing comment for the preceeding argument. Default is '#<'
+  explicit_trailing_pattern = '#<'
+
+  # If a comment line starts with at least this many consecutive hash
+  # characters, then don't lstrip() them off. This allows for lazy hash rulers
+  # where the first hash char is not separated by space
+  hashruler_min_length = 10
+
+  # If true, then insert a space between the first hash char and remaining hash
+  # chars in a hash ruler, and normalize its length to fill the column
+  canonicalize_hashrulers = True
+
+  # enable comment markup parsing and reflow
+  enable_markup = False
+
+# ----------------------------
+# Options affecting the linter
+# ----------------------------
+with section("lint"): # type: ignore
+
+  # a list of lint codes to disable
+  disabled_codes = []
+
+  # regular expression pattern describing valid function names
+  function_pattern = '[0-9a-z_]+'
+
+  # regular expression pattern describing valid macro names
+  macro_pattern = '[0-9A-Z_]+'
+
+  # regular expression pattern describing valid names for variables with global
+  # (cache) scope
+  global_var_pattern = '[A-Z][0-9A-Z_]+'
+
+  # regular expression pattern describing valid names for variables with global
+  # scope (but internal semantic)
+  internal_var_pattern = '_[A-Z][0-9A-Z_]+'
+
+  # regular expression pattern describing valid names for variables with local
+  # scope
+  local_var_pattern = '[a-z][a-z0-9_]+'
+
+  # regular expression pattern describing valid names for privatedirectory
+  # variables
+  private_var_pattern = '_[0-9a-z_]+'
+
+  # regular expression pattern describing valid names for public directory
+  # variables
+  public_var_pattern = '[A-Z][0-9A-Z_]+'
+
+  # regular expression pattern describing valid names for function/macro
+  # arguments and loop variables.
+  argument_var_pattern = '[a-z][a-z0-9_]+'
+
+  # regular expression pattern describing valid names for keywords used in
+  # functions or macros
+  keyword_pattern = '[A-Z][0-9A-Z_]+'
+
+  # In the heuristic for C0201, how many conditionals to match within a loop in
+  # before considering the loop a parser.
+  max_conditionals_custom_parser = 2
+
+  # Require at least this many newlines between statements
+  min_statement_spacing = 1
+
+  # Require no more than this many newlines between statements
+  max_statement_spacing = 2
+  max_returns = 6
+  max_branches = 12
+  max_arguments = 5
+  max_localvars = 15
+  max_statements = 50
+
+# -------------------------------
+# Options affecting file encoding
+# -------------------------------
+with section("encode"): # type: ignore
+
+  # If true, emit the unicode byte-order mark (BOM) at the start of the file
+  emit_byteorder_mark = False
+
+  # Specify the encoding of the input file. Defaults to utf-8
+  input_encoding = 'utf-8'
+
+  # Specify the encoding of the output file. Defaults to utf-8. Note that cmake
+  # only claims to support utf-8 so be careful when using anything else
+  output_encoding = 'utf-8'
+
+# -------------------------------------
+# Miscellaneous configurations options.
+# -------------------------------------
+with section("misc"): # type: ignore
+
+  # A dictionary containing any per-command configuration overrides. Currently
+  # only `command_case` is supported.
+  per_command = {}

+ 32 - 0
cmake/cmake_uninstall.cmake.in

@@ -0,0 +1,32 @@
+if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+  message(
+    FATAL_ERROR
+      "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt"
+  )
+endif()
+
+file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
+list(APPEND files "@CMAKE_INSTALL_PREFIX@/etc/kamailio/kamailio.cfg")
+list(APPEND files "@CMAKE_INSTALL_PREFIX@/etc/kamailio/kamctlrc")
+
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+  message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+  if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    execute_process(
+      COMMAND "${CMAKE_COMMAND}" -E remove "$ENV{DESTDIR}${file}"
+      RESULT_VARIABLE rm_retval
+      OUTPUT_VARIABLE rm_out
+    )
+    # exec_program(
+    #   "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
+    #   OUTPUT_VARIABLE rm_out
+    #   RETURN_VALUE rm_retval
+    #   )
+    if(NOT "${rm_retval}" STREQUAL 0)
+      message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+    endif()
+  else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+  endif()
+endforeach()

+ 55 - 0
cmake/compiler-specific.cmake

@@ -0,0 +1,55 @@
+# Quite analogous to the Makefile.defs file This file is used to define the
+# common flags and options for the project The flags are defined as INTERFACE
+# properties of the common library The flags are then used by the other
+# libraries and executables
+cmake_minimum_required(VERSION 3.10)
+
+# Define the common flags and options for GCC
+option(PROFILE "Enable profiling" OFF)
+
+# Define the flags for the C compiler
+if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+
+  if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+    target_compile_definitions(common INTERFACE CC_GCC_LIKE_ASM)
+
+    target_compile_options(
+      common INTERFACE -O0
+                       # <$<$<BOOL:${PROFILE}>:-pg>
+    )
+
+    target_compile_options(
+      common
+      INTERFACE -Wall -funroll-loops -Wcast-align
+                -Werror=implicit-function-declaration -Werror=implicit-int
+    )
+
+    # If GCC version is greater than 4.2.0, enable the following flags
+    if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0)
+      target_compile_options(
+        common INTERFACE -m64 -minline-all-stringops -falign-loops
+                         -ftree-vectorize -fno-strict-overflow -mtune=generic
+      )
+    endif()
+  elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
+    target_compile_definitions(common INTERFACE CC_GCC_LIKE_ASM)
+    target_compile_options(common INTERFACE -m64)
+    target_link_options(common INTERFACE -m64)
+  endif()
+
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
+
+  if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+    target_compile_definitions(common INTERFACE CC_GCC_LIKE_ASM)
+
+    # target_compile_options(common INTERFACE -O0 # <$<$<BOOL:${PROFILE}>:-pg> )
+
+    # target_compile_options( common INTERFACE -marm -march=armv5t
+    # -funroll-loops -fsigned-char )
+
+    # # If GCC version is greater than 4.2.0, enable the following flags
+    # if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0) target_compile_options(
+    # common INTERFACE -ftree-vectorize -fno-strict-overflow ) endif()
+
+  endif()
+endif()

+ 318 - 0
cmake/defs.cmake

@@ -0,0 +1,318 @@
+# Quite analogous to the Makefile.defs file This file is used to define the
+# common flags and options for the project The flags are defined as INTERFACE
+# properties of the common library The flags are then used by the other
+# libraries and executables
+cmake_minimum_required(VERSION 3.10)
+
+add_library(common INTERFACE)
+
+message(STATUS "CMAKE_C_COMPILER_VERSION: ${CMAKE_C_COMPILER_VERSION}")
+
+set(OS ${CMAKE_SYSTEM_NAME})
+message(STATUS "OS: ${OS}")
+
+set(OSREL ${CMAKE_SYSTEM_VERSION})
+message(STATUS "OS version: ${OSREL}")
+# set(HOST_ARCH "__CPU_${CMAKE_HOST_SYSTEM_PROCESSOR}")
+set(TARGET_ARCH "__CPU_${CMAKE_SYSTEM_PROCESSOR}")
+
+message(STATUS "Host Processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
+# message(STATUS "Processor compile definition: ${HOST_ARCH}")
+message(STATUS "Target Processor: ${CMAKE_SYSTEM_PROCESSOR}")
+message(STATUS "Target Processor compile definition: ${TARGET_ARCH}")
+
+# TODO Check if target arch is supported if(NOT TARGET_ARCH IN_LIST
+# supported_archs) message(FATAL_ERROR "Target architecture not supported")
+# endif()
+
+# Flavor of the project flavour: sip-router, ser or kamailio This is used to
+# define the MAIN_NAME flag TODO: Kamailio only
+set(flavours kamailio)
+set(FLAVOUR
+    "kamailio"
+    CACHE STRING "Flavour of the project"
+)
+set_property(CACHE FLAVOUR PROPERTY STRINGS ${flavours})
+
+# Verbose option (for debugging purposes) (was quiet in Makefile.defs) Probably
+# not needed in CMake and can be removed Use the -DCMAKE_VERBOSE_MAKEFILE=ON
+# option to enable verbose mode
+option(VERBOSE "Verbose " OFF)
+if(VERBOSE)
+  set(CMAKE_VERBOSE_MAKEFILE ON)
+endif()
+
+option(KMSTATS "Kamailio statistics" ON)
+option(FMSTATS "Fast memory statistics" ON)
+option(WITHAS "With Application server support" ON)
+option(SCTP "SCTP support" ON)
+option(RAW_SOCKS "Raw sockets support" ON)
+option(MEMPKG "Package memory or sys " ON)
+
+option(NO_KQUEUE "No kqueue support" OFF)
+option(NO_SELECT "No select support" OFF)
+option(NO_EPOLL "No epoll support" OFF)
+option(NO_SIGIO_RT "No poll support" OFF)
+option(NO_DEV_POLL "No /dev/poll support" OFF)
+
+option(USE_TCP "Use TCP" ON)
+option(USE_TLS "Use TLS" ON)
+option(USE_NAPTR "Use NAPTR" ON)
+option(USE_DNS_CACHE "Use DNS cache" ON)
+
+# Not strictly required to build
+option(USE_SCTP "Use SCTP" ON)
+option(DISABLE_NAGLE "Disable Nagle algorithm" ON)
+option(USE_MCAST "Use Multicast" ON)
+option(DNS_IP_HACK "Use DNS IP hack" ON)
+option(SHM_MMAP "Use mmap for shared memory" ON)
+
+option(PKG_MALLOC "Use package memory" ON)
+option(MEM_JOIN_FREE "Use mem_join_free" ON)
+option(F_MALLOC "Use f_malloc" ON)
+option(Q_MALLOC "Use q_malloc" ON)
+option(TLSF_MALLOC "Use tlsf_malloc" ON)
+option(MALLOC_STATS "Use malloc stats" ON)
+option(DBG_SR_MEMORY "Use memory debugging system" ON)
+
+option(USE_DNS_FAILOVER "Use DNS failover" ON)
+option(USE_DST_BLOCKLIST "Use destination blacklist" ON)
+option(HAVE_RESOLV_RES "Have resolv_res" ON)
+
+option(KSR_PTHREAD_MUTEX_SHARED "Use shared mutex for TLS" ON)
+option(FMSTATS "Fast memory statistics" ON)
+option(STATISTICS "Statistics" ON)
+# if(${MEMPKG}) target_compile_definitions(common INTERFACE PKG_MALLOC) else()
+# if(${MEMDBGSYS}) target_compile_definitions(common INTERFACE DDBG_SYS_MEMORY)
+# endif() endif()
+
+# -----------------------
+# TLS support
+# -----------------------
+option(TLS_HOOKS "TLS hooks support" ON)
+option(CORE_TLS "CORE_TLS" OFF)
+# set(CORE_TLS "" CACHE STRING "CORE_TLS") set(TLS_HOOKS ON CACHE BOOL "TLS
+# hooks support")
+
+if(${CORE_TLS})
+  set(RELEASE "${RELEASE}-tls")
+  set(TLS_HOOKS OFF)
+else()
+  set(TLS_HOOKS ON)
+endif()
+
+set(LIBSSL_SET_MUTEX_SHARED
+    ON
+    CACHE BOOL
+          "enable workaround for libssl 1.1+ to set shared mutex attribute"
+)
+if(NOT ${LIBSSL_SET_MUTEX_SHARED})
+  message(
+    STATUS
+      "Checking if can enable workaround for libssl 1.1+ to set shared mutex attribute"
+  )
+  if(NOT DEFINED CMAKE_CROSSCOMPILING OR NOT ${CMAKE_CROSSCOMPILING})
+    message(STATUS "Checking for OpenSSL 1.1.0")
+    find_package(OpenSSL 1.1.0)
+    if(OPENSSL_FOUND)
+      message(STATUS "OpenSSL version: ${OPENSSL_VERSION}")
+      if(${OPENSSL_VERSION} VERSION_GREATER_EQUAL "1.1.0")
+        message(
+          STATUS
+            "Enabling workaround for libssl 1.1+ to set shared mutex attribute"
+        )
+        set(LIBSSL_SET_MUTEX_SHARED ON)
+      endif()
+    endif()
+  endif()
+
+endif()
+
+# -----------------------
+# Locking mechanism macro
+# -----------------------
+
+option(FAST_LOCK "Use fast locking" ON)
+# Fast-lock not available for all platforms like mips Check the system processor
+if(CMAKE_SYSTEM_PROCESSOR MATCHES
+   "i386|x86_64|sparc64|sparc|arm6|arm7|ppc|ppc64|alpha|mips2|mips64"
+)
+  set(USE_FAST_LOCK YES)
+elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64")
+  set(USE_FAST_LOCK YES)
+  target_compile_definitions(common INTERFACE NOSMP) # memory barriers not
+                                                     # implemented for arm
+elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips")
+  set(USE_FAST_LOCK NO)
+  target_compile_definitions(common INTERFACE MIPS_HAS_LLSC) # likely
+  target_compile_definitions(common INTERFACE NOSMP) # very likely
+endif()
+
+# Add definitions if USE_FAST_LOCK is YES
+if(USE_FAST_LOCK)
+  target_compile_definitions(
+    common INTERFACE FAST_LOCK ADAPTIVE_WAIT ADAPTIVE_WAIT_LOOPS=1024
+  )
+endif()
+message(STATUS "Fast lock: ${USE_FAST_LOCK}")
+
+# List of locking methods in option
+set(locking_methods USE_FUTEX USE_PTHREAD_MUTEX USE_POSIX_SEM USE_SYSV_SEM)
+set(LOCK_METHOD
+    USE_FUTEX
+    CACHE STRING "Locking method to use"
+)
+set_property(CACHE LOCK_METHOD PROPERTY STRINGS ${locking_methods})
+
+# set(LOCKING_DEFINITION "${locking_method}")
+message(STATUS "Locking method: ${LOCK_METHOD}")
+
+# -----------------------
+# Setting all the flags from options
+if(USE_TCP)
+  target_compile_definitions(common INTERFACE USE_TCP)
+endif()
+
+if(USE_TLS)
+  target_compile_definitions(common INTERFACE USE_TLS)
+endif()
+
+if(TLS_HOOKS)
+  target_compile_definitions(common INTERFACE TLS_HOOKS)
+endif()
+
+if(USE_NAPTR)
+  target_compile_definitions(common INTERFACE USE_NAPTR)
+endif()
+
+if(USE_DNS_CACHE)
+  target_compile_definitions(common INTERFACE USE_DNS_CACHE)
+endif()
+
+if(F_MALLOC)
+  target_compile_definitions(common INTERFACE F_MALLOC)
+endif()
+
+if(Q_MALLOC)
+  target_compile_definitions(common INTERFACE Q_MALLOC)
+endif()
+
+if(TLSF_MALLOC)
+  target_compile_definitions(common INTERFACE TLSF_MALLOC)
+endif()
+
+if(MALLOC_STATS)
+  target_compile_definitions(common INTERFACE MALLOC_STATS)
+endif()
+
+if(DBG_SR_MEMORY)
+  target_compile_definitions(common INTERFACE DBG_SR_MEMORY)
+endif()
+
+if(USE_DNS_FAILOVER)
+  target_compile_definitions(common INTERFACE USE_DNS_FAILOVER)
+endif()
+
+if(USE_DST_BLOCKLIST)
+  target_compile_definitions(common INTERFACE USE_DST_BLOCKLIST)
+endif()
+
+if(HAVE_RESOLV_RES)
+  target_compile_definitions(common INTERFACE HAVE_RESOLV_RES)
+endif()
+
+if(USE_MCAST)
+  target_compile_definitions(common INTERFACE USE_MCAST)
+endif()
+
+if(DISABLE_NAGLE)
+  target_compile_definitions(common INTERFACE DISABLE_NAGLE)
+endif()
+
+if(DNS_IP_HACK)
+  target_compile_definitions(common INTERFACE DNS_IP_HACK)
+endif()
+
+if(SHM_MMAP)
+  target_compile_definitions(common INTERFACE SHM_MMAP)
+endif()
+
+if(PKG_MALLOC)
+  target_compile_definitions(common INTERFACE PKG_MALLOC)
+endif()
+
+if(NO_KQUEUE)
+  target_compile_definitions(common INTERFACE NO_KQUEUE)
+endif()
+
+if(NO_SELECT)
+  target_compile_definitions(common INTERFACE NO_SELECT)
+endif()
+
+if(NO_EPOLL)
+  target_compile_definitions(common INTERFACE NO_EPOLL)
+endif()
+
+if(NO_SIGIO_RT)
+  target_compile_definitions(common INTERFACE NO_SIGIO_RT)
+endif()
+
+if(NO_DEV_POLL)
+  target_compile_definitions(common INTERFACE NO_DEV_POLL)
+endif()
+
+# if(USE_SCTP) target_compile_definitions(common INTERFACE USE_SCTP) endif()
+
+if(RAW_SOCKS)
+  target_compile_definitions(common INTERFACE RAW_SOCKS)
+endif()
+
+if(KSR_PTHREAD_MUTEX_SHARED)
+  target_compile_definitions(common INTERFACE KSR_PTHREAD_MUTEX_SHARED)
+endif()
+
+if(FMSTATS)
+  target_compile_definitions(common INTERFACE FMSTATS)
+endif()
+
+if(KMSTATS)
+  target_compile_definitions(common INTERFACE KMSTATS)
+endif()
+
+include(${CMAKE_SOURCE_DIR}/cmake/compiler-specific.cmake)
+include(${CMAKE_SOURCE_DIR}/cmake/os-specific.cmake)
+
+string(TOLOWER ${OS} OS_LOWER)
+target_compile_definitions(
+  common
+  INTERFACE
+    NAME="${MAIN_NAME}"
+    VERSION="${RELEASE}"
+    ARCH="${CMAKE_HOST_SYSTEM_PROCESSOR}"
+    OS=${OS}
+    OS_QUOTED="${OS}"
+    COMPILER="${CMAKE_C_COMPILER_VERSION}"
+    # ${HOST_ARCH}
+    ${TARGET_ARCH}
+    __OS_${OS_LOWER}
+    VERSIONVAL=${VERSIONVAL}
+    CFG_DIR="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/${CFG_NAME}/"
+    SHARE_DIR="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${MAIN_NAME}/"
+    # Absolute path this run is always /var/run/kamailio either for local or
+    # system installs
+    RUN_DIR="/${CMAKE_INSTALL_LOCALSTATEDIR}/run/${MAIN_NAME}"
+    ${LOCK_METHOD}
+    # Module stuff?
+    PIC
+    # TODO: We can use the generator expression to define extra flags instead of
+    # checking the options each time
+    $<$<BOOL:${USE_SCTP}>:USE_SCTP>
+    $<$<BOOL:${STATISTICS}>:STATISTICS>
+)
+
+# -----------------------
+add_library(common_modules INTERFACE)
+target_compile_options(common_modules INTERFACE -fPIC)
+
+# TODO: Do we need all the option from common as well?
+target_link_libraries(common_modules INTERFACE common)

+ 686 - 0
cmake/groups.cmake

@@ -0,0 +1,686 @@
+# Kamailio build system Module groups definitions
+#
+
+# lists are sets of modules that don't include modules that are in other lists -
+# break the lists as needed in order to use them to build desired groups and
+# packages
+#
+
+# * basic used modules, with no extra dependency (widespread usage)
+set(MOD_LIST_BASIC
+    async
+    auth
+    benchmark
+    blst
+    cfg_rpc
+    cfgutils
+    corex
+    counters
+    ctl
+    debugger
+    diversion
+    enum
+    exec
+    ipops
+    kex
+    mangler
+    maxfwd
+    mediaproxy
+    mqueue
+    nat_traversal
+    nathelper
+    path
+    pike
+    pv
+    ratelimit
+    rr
+    rtimer
+    rtpproxy
+    sanity
+    sdpops
+    siputils
+    sl
+    statistics
+    textops
+    textopsx
+    tm
+    tmx
+    topoh
+    xlog
+    rtpengine
+    stun
+    sipt
+    tcpops
+    auth_xkeys
+    smsops
+    tsilo
+    cfgt
+    statsc
+    topos
+    sipdump
+    pv_headers
+    kemix
+)
+
+# * extra used modules, with no extra dependency
+set(MOD_LIST_EXTRA
+    avp
+    auth_diameter
+    call_control
+    call_obj
+    dmq
+    domainpolicy
+    msrp
+    carrierroute
+    pdb
+    qos
+    sca
+    seas
+    sms
+    sst
+    timer
+    tmrec
+    uac_redirect
+    xhttp
+    xhttp_rpc
+    xprint
+    jsonrpcs
+    nosip
+    dmq_usrloc
+    statsd
+    rtjson
+    log_custom
+    keepalive
+    ss7ops
+    acc_diameter
+    evrexec
+    file_out
+    sipjson
+    lrkproxy
+    math
+    posops
+    xhttp_prom
+    dlgs
+    sworker
+    influxdbc
+)
+
+# * common modules depending on database
+set(MOD_LIST_DB
+    acc
+    alias_db
+    auth_db
+    avpops
+    cfg_db
+    db_text
+    db_flatstore
+    db_cluster
+    dialog
+    dispatcher
+    domain
+    drouting
+    group
+    htable
+    imc
+    matrix
+    mohqueue
+    msilo
+    mtree
+    p_usrloc
+    pdt
+    permissions
+    pipelimit
+    prefix_route
+    registrar
+    sipcapture
+    siptrace
+    speeddial
+    sqlops
+    uac
+    uri_db
+    userblocklist
+    usrloc
+    secfilter
+)
+
+# * common modules depending on database, using UID db schema
+set(MOD_LIST_DBUID db2_ops uid_auth_db uid_avp_db uid_domain uid_gflags
+                   uid_uri_db
+)
+
+# * modules for devel purposes
+set(MOD_LIST_DEVEL misctest print print_lib)
+
+# * modules depending on pcre3 library
+set(MOD_LIST_PCRE dialplan lcr regex)
+
+# * modules depending on radius client library
+set(MOD_LIST_RADIUS acc_radius auth_radius misc_radius peering)
+
+# * modules depending on ldap client library
+set(MOD_LIST_LDAP db2_ldap h350 ldap)
+
+# * modules depending on mysql client library
+set(MOD_LIST_MYSQL db_mysql)
+
+# * modules depending on postgres client library
+set(MOD_LIST_POSTGRES db_postgres)
+
+# * modules depending on unixodbc library
+set(MOD_LIST_UNIXODBC db_unixodbc)
+
+# * modules depending on mysql cassandra library
+set(MOD_LIST_CASSANDRA db_cassandra ndb_cassandra)
+
+# * modules depending on xml2 library
+set(MOD_LIST_CPLC cplc)
+
+# * modules depending on xml2 library
+set(MOD_LIST_XMLDEPS xhttp_pi xmlrpc xmlops)
+
+# * modules depending on net-snmp library
+set(MOD_LIST_SNMPSTATS snmpstats)
+
+# * modules depending on expat library
+set(MOD_LIST_XMPP xmpp)
+
+# * modules depending on bdb (db4) library
+set(MOD_LIST_BERKELEY db_berkeley)
+
+# * modules depending on curl library
+set(MOD_LIST_UTILS utils http_client lost slack)
+
+# * modules depending on curl and libevent2 library
+set(MOD_LIST_HTTP_ASYNC http_async_client)
+
+# * modules depending on memcache library
+set(MOD_LIST_MEMCACHED memcached)
+
+# * modules depending on openssl library
+set(MOD_LIST_TLSDEPS crypto tls)
+
+# * modules depending on static openssl library
+set(MOD_LIST_TLSA tlsa)
+
+# * modules depending on static wolfssl library
+set(MOD_LIST_TLS_WOLFSSL tls_wolfssl)
+
+# * modules depending on openssl library
+set(MOD_LIST_OUTBOUND outbound)
+
+# * modules depending on openssl and unistring library
+set(MOD_LIST_WEBSOCKET websocket)
+
+# * modules depending on libval-threads libcrypto libsres libpthread
+set(MOD_LIST_DNSSEC dnssec)
+
+# * modules depending on libsctp
+set(MOD_LIST_SCTP sctp)
+
+# * modules depending on openssl library
+set(MOD_LIST_AUTHEPH auth_ephemeral)
+
+# * modules related to SIMPLE presence extensions
+set(MOD_LIST_PRESENCE
+    presence
+    presence_conference
+    presence_dialoginfo
+    presence_mwi
+    presence_profile
+    presence_reginfo
+    presence_xml
+    pua
+    pua_bla
+    pua_dialoginfo
+    pua_reginfo
+    pua_rpc
+    pua_usrloc
+    pua_xmpp
+    rls
+    xcap_client
+    xcap_server
+)
+
+# * modules depending on lua library
+set(MOD_LIST_LUA app_lua)
+
+# * modules depending on perl library
+set(MOD_LIST_PERLDEPS app_perl db_perlvdb)
+
+# * modules depending on python library
+set(MOD_LIST_PYTHON app_python)
+
+# * modules depending on python3 library
+set(MOD_LIST_PYTHON3 app_python3 app_python3s)
+
+# * modules depending on libm (math library - standard system library)
+set(MOD_LIST_JSDT app_jsdt)
+
+# * modules depending on ruby library
+set(MOD_LIST_RUBY app_ruby app_ruby_proc)
+
+# * modules depending on geoip library
+set(MOD_LIST_GEOIP geoip)
+
+# * modules depending on new geoip library
+set(MOD_LIST_GEOIP2 geoip2)
+
+# * modules depending on sqlite library
+set(MOD_LIST_SQLITE db_sqlite)
+
+# * modules depending on oracle library
+set(MOD_LIST_ORACLE db_oracle)
+
+# * modules depending on json library
+set(MOD_LIST_JSON json pua_json)
+
+# * modules depending on json (+libevent) library
+set(MOD_LIST_JSON_EVENT jsonrpcc)
+
+# * modules depending on jansson library
+set(MOD_LIST_JANSSON jansson acc_json)
+
+# * modules depending on jansson (+libevent) library
+set(MOD_LIST_JANSSON_EVENT janssonrpcc)
+
+# * modules depending on redis library
+set(MOD_LIST_REDIS db_redis ndb_redis topos_redis)
+
+# * modules depending on mono library
+set(MOD_LIST_MONO app_mono)
+
+# * modules related to IMS extensions
+set(MOD_LIST_IMS
+    cdp
+    cdp_avp
+    ims_dialog
+    ims_auth
+    ims_isc
+    ims_icscf
+    ims_qos
+    ims_registrar_pcscf
+    ims_registrar_scscf
+    ims_usrloc_pcscf
+    ims_usrloc_scscf
+    ims_charging
+    ims_ocs
+    ims_diameter_server
+    ims_ipsec_pcscf
+)
+
+# * modules depending on osp toolkit library
+set(MOD_LIST_OSP osp)
+
+# * modules depending on java library
+set(MOD_LIST_JAVA app_java)
+
+# * modules depending on gzip library
+set(MOD_LIST_GZCOMPRESS gzcompress)
+
+# * modules depending on uuid library
+set(MOD_LIST_UUID uuid)
+
+# * modules depending on ev library
+set(MOD_LIST_EV evapi)
+
+# * modules depending on libjwt library
+set(MOD_LIST_JWT jwt)
+
+# * modules depending on libwebsockets library
+set(MOD_LIST_LWSC lwsc)
+
+# * modules depending on libstirshaken library
+set(MOD_LIST_STIRSHAKEN stirshaken)
+
+# * modules depending on kazoo/rabbitmq
+set(MOD_LIST_KAZOO kazoo)
+
+# * modules depending on mongodb
+set(MOD_LIST_MONGODB db_mongodb ndb_mongodb)
+
+# * modules depending on redis and event library
+set(MOD_LIST_CNXCC cnxcc)
+
+# * modules depending on erlang library
+set(MOD_LIST_ERLANG erlang)
+
+# * modules depending on systemd library
+set(MOD_LIST_SYSTEMD log_systemd systemdops)
+
+# * modules depending on libnsq (+libev libevbuffsock libcurl libjson-c) library
+set(MOD_LIST_NSQ nsq)
+
+# * modules depending on librabbitmq library
+set(MOD_LIST_RABBITMQ rabbitmq)
+
+# * modules depending on libphonenumber library
+set(MOD_LIST_PHONENUM phonenum)
+
+# * modules depending on rdkafka library
+set(MOD_LIST_KAFKA kafka)
+
+# * modules depending on mqtt mosquitto and ev library
+set(MOD_LIST_MQTT mqtt)
+
+# * modules depending on nats and ev library
+set(MOD_LIST_NATS nats)
+
+# * modules depending on ruxc library
+set(MOD_LIST_RUXC ruxc)
+
+# * modules depending on microhttpd library
+set(MOD_LIST_MICROHTTPD microhttpd)
+
+# * modules depending on nghttp2 library
+set(MOD_LIST_NGHTTP2 nghttp2)
+
+# * modules depending on libgcrypt library
+set(MOD_LIST_GCRYPT gcrypt)
+
+# * modules depending on secsipid library
+set(MOD_LIST_SECSIPID secsipid secsipid_proc)
+
+# * modules depending on oRTP and mediastreamer2 libraries
+set(MOD_LIST_RTP_MEDIA_SERVER rtp_media_server)
+
+# * all modules
+set(MOD_LIST_ALL
+    ${MOD_LIST_BASIC}
+    ${MOD_LIST_EXTRA}
+    ${MOD_LIST_DB}
+    ${MOD_LIST_DBUID}
+    ${MOD_LIST_DEVEL}
+    ${MOD_LIST_PCRE}
+    ${MOD_LIST_RADIUS}
+    ${MOD_LIST_LDAP}
+    ${MOD_LIST_MYSQL}
+    ${MOD_LIST_POSTGRES}
+    ${MOD_LIST_UNIXODBC}
+    ${MOD_LIST_XMLDEPS}
+    ${MOD_LIST_PERLDEPS}
+    ${MOD_LIST_CPLC}
+    ${MOD_LIST_XMPP}
+    ${MOD_LIST_BERKELEY}
+    ${MOD_LIST_UTILS}
+    ${MOD_LIST_MEMCACHED}
+    ${MOD_LIST_TLSDEPS}
+    ${MOD_LIST_WEBSOCKET}
+    ${MOD_LIST_SNMPSTATS}
+    ${MOD_LIST_PRESENCE}
+    ${MOD_LIST_LUA}
+    ${MOD_LIST_PYTHON}
+    ${MOD_LIST_PYTHON3}
+    ${MOD_LIST_RUBY}
+    ${MOD_LIST_GEOIP}
+    ${MOD_LIST_SQLITE}
+    ${MOD_LIST_JSON}
+    ${MOD_LIST_JSON_EVENT}
+    ${MOD_LIST_REDIS}
+    ${MOD_LIST_MONO}
+    ${MOD_LIST_IMS}
+    ${MOD_LIST_CASSANDRA}
+    ${MOD_LIST_ORACLE}
+    ${MOD_LIST_OUTBOUND}
+    ${MOD_LIST_OSP}
+    ${MOD_LIST_JAVA}
+    ${MOD_LIST_DNSSEC}
+    ${MOD_LIST_SCTP}
+    ${MOD_LIST_AUTHEPH}
+    ${MOD_LIST_GZCOMPRESS}
+    ${MOD_LIST_UUID}
+    ${MOD_LIST_EV}
+    ${MOD_LIST_KAZOO}
+    ${MOD_LIST_MONGODB}
+    ${MOD_LIST_CNXCC}
+    ${MOD_LIST_JANSSON}
+    ${MOD_LIST_JANSSON_EVENT}
+    ${MOD_LIST_GEOIP2}
+    ${MOD_LIST_ERLANG}
+    ${MOD_LIST_SYSTEMD}
+    ${MOD_LIST_HTTP_ASYNC}
+    ${MOD_LIST_NSQ}
+    ${MOD_LIST_RABBITMQ}
+    ${MOD_LIST_JSDT}
+    ${MOD_LIST_PHONENUM}
+    ${MOD_LIST_KAFKA}
+    ${MOD_LIST_MQTT}
+    ${MOD_LIST_NATS}
+    ${MOD_LIST_RUXC}
+    ${MOD_LIST_SECSIPID}
+    ${MOD_LIST_JWT}
+    ${MOD_LIST_LWSC}
+    ${MOD_LIST_STIRSHAKEN}
+    ${MOD_LIST_TLSA}
+    ${MOD_LIST_TLS_WOLFSSL}
+    ${MOD_LIST_MICROHTTPD}
+    ${MOD_LIST_NGHTTP2}
+    ${MOD_LIST_GCRYPT}
+    ${MOD_LIST_RTP_MEDIA_SERVER}
+)
+
+# sort the list
+list(SORT MOD_LIST_ALL)
+
+# --- Groups defined for source code compilation ###
+
+# groups are sets of modules selected by compile target interest (should be
+# built by combining lists)
+
+# Modules in this group are the default compiled modules due to no external
+# compile or link dependencies
+set(MODULE_GROUP_ALL ${MOD_LIST_ALL})
+
+set(MODULE_GROUP_DEFAULT ${MOD_LIST_BASIC} ${MOD_LIST_EXTRA} ${MOD_LIST_DB}
+                         ${MOD_LIST_DBUID} ${MOD_LIST_DEVEL} ${MOD_LIST_JSDT}
+)
+
+# Modules in this group are the default compiled modules due to no
+# internal/external compile or link dependencies
+# module_group_standard=$(mod_list_basic) $(mod_list_extra) \ $(mod_list_devel)
+# $(mod_list_jsdt)
+set(MODULE_GROUP_STANDARD ${MOD_LIST_BASIC} ${MOD_LIST_EXTRA} ${MOD_LIST_DEVEL}
+                          ${MOD_LIST_JSDT}
+)
+
+# Modules in this group are considered a standard part due to widespread usage,
+# but they have dependencies that must be satisfied for compilation (e.g., lcr,
+# radius, presence, tls, ...). module_group_common=$(mod_list_db)
+# $(mod_list_dbuid) \ $(mod_list_pcre) $(mod_list_radius) \ $(mod_list_xmldeps)
+# $(mod_list_presence) \ $(mod_list_tlsdeps)
+set(MODULE_GROUP_COMMON
+    ${MOD_LIST_DB}
+    ${MOD_LIST_DBUID}
+    ${MOD_LIST_PCRE}
+    ${MOD_LIST_RADIUS}
+    ${MOD_LIST_XMLDEPS}
+    ${MOD_LIST_PRESENCE}
+    ${MOD_LIST_TLSDEPS}
+)
+
+# For db use (db modules, excluding drivers) module_group_db=$(mod_list_db)
+set(MODULE_GROUP_DB ${MOD_LIST_DB})
+
+# For mysql module_group_mysql_driver=$(mod_list_mysql)
+# module_group_mysql=$(module_group_mysql_driver) $(module_group_db)
+set(MODULE_GROUP_MYSQL_DRIVER ${MOD_LIST_MYSQL})
+set(MODULE_GROUP_MYSQL ${MODULE_GROUP_MYSQL_DRIVER} ${MODULE_GROUP_DB})
+
+# For postgress module_group_postgres_driver=$(mod_list_postgres)
+# module_group_postgres=$(module_group_postgres_driver) $(module_group_db)
+set(MODULE_GROUP_POSTGRES_DRIVER ${MOD_LIST_POSTGRES})
+set(MODULE_GROUP_POSTGRES ${MODULE_GROUP_POSTGRES_DRIVER} ${MODULE_GROUP_DB})
+
+# For sqlite module_group_sqlite_driver=$(mod_list_sqlite)
+# module_group_sqlite=$(module_group_sqlite_driver) $(module_group_db)
+set(MODULE_GROUP_SQLITE_DRIVER ${MOD_LIST_SQLITE})
+set(MODULE_GROUP_SQLITE ${MODULE_GROUP_SQLITE_DRIVER} ${MODULE_GROUP_DB})
+
+# For radius module_group_radius=$(mod_list_radius)
+
+# For presence kamailio modules module_group_presence=$(mod_list_presence)
+
+# For cassandra module_group_cassandra_driver=$(mod_list_cassandra)
+# module_group_cassandra=$(module_group_cassandra_driver) $(module_group_db)
+
+# For all modules not compiled by default module_group_ignore= $(sort
+# $(filter-out $(module_group_default), $(mod_list_all)))
+
+set(AVAILABLE_GROUPS
+    ALL
+    DEFAULT
+    STANDARD
+    COMMON
+    # MODULE_GROUP_DB
+    # MODULE_GROUP_MYSQL_DRIVER
+    # MODULE_GROUP_MYSQL
+    # MODULE_GROUP_POSTGRES_DRIVER
+    # MODULE_GROUP_POSTGRES
+    # MODULE_GROUP_SQLITE_DRIVER
+    # MODULE_GROUP_SQLITE
+    # MODULE_GROUP_RADIUS
+    # module_group_presence
+)
+# --- Groups defined for pacKaging ###
+
+# Standard modules in main pkg module_group_kstandard=$(mod_list_basic)
+# $(mod_list_extra) \ $(mod_list_db) $(mod_list_dbuid) \ $(mod_list_pcre)
+# $(mod_list_jsdt)
+
+# Standard modules without any dependencies (such as pcre)
+# module_group_kmini=$(mod_list_basic) $(mod_list_extra) \ $(mod_list_db)
+# $(mod_list_dbuid) \ $(mod_list_jsdt)
+
+# pkg pcre module module_group_kpcre=$(mod_list_pcre)
+
+# pkg mysql module module_group_kmysql=$(mod_list_mysql)
+
+# pkg postgress module module_group_kpostgres=$(mod_list_postgres)
+
+# pkg cpl module module_group_kcpl=$(mod_list_cpl)
+
+# pkg xml modules module_group_kxml=$(mod_list_xmldeps)
+
+# pkg radius modules module_group_kradius=$(mod_list_radius)
+
+# pkg unixodbc module module_group_kunixodbc=$(mod_list_unixodbc)
+
+# pkg perl module module_group_kperl=$(mod_list_perldeps)
+
+# pkg snmpstats module module_group_ksnmpstats=$(mod_list_snmpstats)
+
+# pkg xmpp module module_group_kxmpp=$(mod_list_xmpp)
+
+# pkg berkeley module module_group_kberkeley=$(mod_list_berkeley)
+
+# pkg ldap modules module_group_kldap=$(mod_list_ldap)
+
+# pkg utils module module_group_kutils=$(mod_list_utils)
+
+# pkg https_async module module_group_khttp_async=$(mod_list_http_async)
+
+# pkg memcached module module_group_kmemcached=$(mod_list_memcached)
+
+# pkg tls module module_group_ktls_basic=$(mod_list_tlsdeps)
+
+# ifeq ($(KTLS_INCLUDE_TLSA),yes) pkg tls module with curl
+# module_group_ktls=$(mod_list_tlsdeps) $(mod_list_tlsa) else pkg tls module
+# with curl module_group_ktls=$(mod_list_tlsdeps)
+
+# pkg tlsa module module_group_ktlsa=$(mod_list_tlsa) endif
+
+# pkg tls_wolfssl module module_group_ktls_wolfssl=$(mod_list_tls_wolfssl)
+
+# pkg websocket module module_group_kwebsocket=$(mod_list_websocket)
+
+# pkg presence modules module_group_kpresence=$(mod_list_presence)
+
+# pkg lua module module_group_klua=$(mod_list_lua)
+
+# pkg python module module_group_kpython=$(mod_list_python)
+
+# pkg python3 module module_group_kpython3=$(mod_list_python3)
+
+# pkg ruby module module_group_kruby=$(mod_list_ruby)
+
+# pkg geoip module module_group_kgeoip=$(mod_list_geoip)
+
+# pkg geoip2 module module_group_kgeoip2=$(mod_list_geoip2)
+
+# pkg sqlite module module_group_ksqlite=$(mod_list_sqlite)
+
+# K json modules module_group_kjson_basic=$(mod_list_json)
+
+# K json modules with libevent module_group_kjson=$(mod_list_json)
+# $(mod_list_json_event)
+
+# K jansson modules module_group_kjansson_basic=$(mod_list_jansson)
+
+# K jansson modules with libevent module_group_kjansson=$(mod_list_jansson)
+# $(mod_list_jansson_event)
+
+# pkg redis module module_group_kredis=$(mod_list_redis)
+
+# pkg mono module module_group_kmono=$(mod_list_mono)
+
+# pkg IMS modules module_group_kims=$(mod_list_ims)
+
+# pkg outbound module module_group_koutbound=$(mod_list_outbound)
+
+# pkg java module module_group_kjava=$(mod_list_java)
+
+# pkg dnssec module module_group_kdnssec=$(mod_list_dnssec)
+
+# pkg sctp module module_group_ksctp=$(mod_list_sctp)
+
+# pkg auth_ephemeral module module_group_kautheph=$(mod_list_autheph)
+
+# pkg gzcompress module module_group_kgzcompress=$(mod_list_gzcompress)
+
+# pkg uuid module module_group_kuuid=$(mod_list_uuid)
+
+# pkg libev modules module_group_kev=$(mod_list_ev)
+
+# pkg jwt module module_group_kjwt=$(mod_list_jwt)
+
+# pkg lwsc module module_group_klwsc=$(mod_list_lwsc)
+
+# pkg stirshaken module module_group_kstirshaken=$(mod_list_stirshaken)
+
+# pkg kazoo module module_group_kkazoo=$(mod_list_kazoo)
+
+# pkg mongodb modules module_group_kmongodb=$(mod_list_mongodb)
+
+# pkg cnxcc module module_group_kcnxcc=$(mod_list_cnxcc)
+
+# pkg erlang module module_group_kerlang=$(mod_list_erlang)
+
+# pkg systemd module module_group_ksystemd=$(mod_list_systemd)
+
+# K nsq modules module_group_knsq=$(mod_list_nsq)
+
+# K rabbitmq modules module_group_krabbitmq=$(mod_list_rabbitmq)
+
+# K phonenumber modules module_group_kphonenum=$(mod_list_phonenum)
+
+# K kafka modules module_group_kkafka=$(mod_list_kafka)
+
+# K mqtt modules module_group_kmqtt=$(mod_list_mqtt)
+
+# K nats modules module_group_knats=$(mod_list_nats)
+
+# K ruxc modules module_group_kruxc=$(mod_list_ruxc)
+
+# K microhttpd module module_group_kmicrohttpd=$(mod_list_microhttpd)
+
+# K nghttp2 module module_group_knghttp2=$(mod_list_nghttp2)
+
+# K gcrypt module module_group_kgcrypt=$(mod_list_gcrypt)
+
+# K secsipid modules module_group_ksecsipid=$(mod_list_secsipid)
+
+# K rtp_media_server modules
+# module_group_krtp_media_server=$(mod_list_rtp_media_server)
+
+# list of static modules
+#
+# static_modules:=

+ 182 - 0
cmake/modules/FindBerkeleyDB.cmake

@@ -0,0 +1,182 @@
+# Copyright (c) 2023-present The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or https://opensource.org/license/mit/.
+
+#[=======================================================================[
+FindBerkeleyDB
+--------------
+
+Finds the Berkeley DB headers and library.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+This module provides imported target ``BerkeleyDB::BerkeleyDB``, if
+Berkeley DB has been found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables:
+
+``BerkeleyDB_FOUND``
+  "True" if Berkeley DB found.
+
+``BerkeleyDB_VERSION``
+  The MAJOR.MINOR version of Berkeley DB found.
+
+#]=======================================================================]
+
+set(_BerkeleyDB_homebrew_prefix)
+if(CMAKE_HOST_APPLE)
+  find_program(HOMEBREW_EXECUTABLE brew)
+  if(HOMEBREW_EXECUTABLE)
+    # The Homebrew package manager installs the berkeley-db* packages as
+    # "keg-only", which means they are not symlinked into the default prefix.
+    # To find such a package, the find_path() and find_library() commands
+    # need additional path hints that are computed by Homebrew itself.
+    execute_process(
+      COMMAND ${HOMEBREW_EXECUTABLE} --prefix [email protected]
+      OUTPUT_VARIABLE _BerkeleyDB_homebrew_prefix
+      ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+  endif()
+endif()
+
+find_path(
+  BerkeleyDB_INCLUDE_DIR
+  NAMES db_cxx.h
+  HINTS ${_BerkeleyDB_homebrew_prefix}/include
+  PATH_SUFFIXES
+    4.8
+    48
+    db4.8
+    4
+    db4
+    5.3
+    db5.3
+    5
+    db5
+)
+mark_as_advanced(BerkeleyDB_INCLUDE_DIR)
+unset(_BerkeleyDB_homebrew_prefix)
+
+if(NOT BerkeleyDB_LIBRARY)
+  if(VCPKG_TARGET_TRIPLET)
+    # The vcpkg package manager installs the berkeleydb package with the same name
+    # of release and debug libraries. Therefore, the default search paths set by
+    # vcpkg's toolchain file cannot be used to search libraries as the debug one
+    # will always be found.
+    set(CMAKE_FIND_USE_CMAKE_PATH FALSE)
+  endif()
+
+  get_filename_component(
+    _BerkeleyDB_lib_hint "${BerkeleyDB_INCLUDE_DIR}" DIRECTORY
+  )
+
+  find_library(
+    BerkeleyDB_LIBRARY_RELEASE
+    NAMES db_cxx-4.8
+          db4_cxx
+          db48
+          db_cxx-5.3
+          db_cxx-5
+          db_cxx
+          libdb48
+          NAMES_PER_DIR
+    HINTS ${_BerkeleyDB_lib_hint}
+    PATH_SUFFIXES lib
+  )
+  mark_as_advanced(BerkeleyDB_LIBRARY_RELEASE)
+
+  find_library(
+    BerkeleyDB_LIBRARY_DEBUG
+    NAMES db_cxx-4.8
+          db4_cxx
+          db48
+          db_cxx-5.3
+          db_cxx-5
+          db_cxx
+          libdb48
+          NAMES_PER_DIR
+    HINTS ${_BerkeleyDB_lib_hint}
+    PATH_SUFFIXES debug/lib
+  )
+  mark_as_advanced(BerkeleyDB_LIBRARY_DEBUG)
+
+  unset(_BerkeleyDB_lib_hint)
+  unset(CMAKE_FIND_USE_CMAKE_PATH)
+
+  include(SelectLibraryConfigurations)
+  select_library_configurations(BerkeleyDB)
+  # The select_library_configurations() command sets BerkeleyDB_FOUND, but we
+  # want the one from the find_package_handle_standard_args() command below.
+  unset(BerkeleyDB_FOUND)
+endif()
+
+if(BerkeleyDB_INCLUDE_DIR)
+  file(STRINGS "${BerkeleyDB_INCLUDE_DIR}/db.h" _BerkeleyDB_version_strings
+       REGEX "^#define[\t ]+DB_VERSION_(MAJOR|MINOR|PATCH)[ \t]+[0-9]+.*"
+  )
+  string(REGEX
+         REPLACE ".*#define[\t ]+DB_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1"
+                 _BerkeleyDB_version_major "${_BerkeleyDB_version_strings}"
+  )
+  string(REGEX
+         REPLACE ".*#define[\t ]+DB_VERSION_MINOR[ \t]+([0-9]+).*" "\\1"
+                 _BerkeleyDB_version_minor "${_BerkeleyDB_version_strings}"
+  )
+  string(REGEX
+         REPLACE ".*#define[\t ]+DB_VERSION_PATCH[ \t]+([0-9]+).*" "\\1"
+                 _BerkeleyDB_version_patch "${_BerkeleyDB_version_strings}"
+  )
+  unset(_BerkeleyDB_version_strings)
+  # The MAJOR.MINOR.PATCH version will be logged in the following find_package_handle_standard_args() command.
+  set(_BerkeleyDB_full_version
+      ${_BerkeleyDB_version_major}.${_BerkeleyDB_version_minor}.${_BerkeleyDB_version_patch}
+  )
+  set(BerkeleyDB_VERSION
+      ${_BerkeleyDB_version_major}.${_BerkeleyDB_version_minor}
+  )
+  unset(_BerkeleyDB_version_major)
+  unset(_BerkeleyDB_version_minor)
+  unset(_BerkeleyDB_version_patch)
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+  BerkeleyDB
+  REQUIRED_VARS BerkeleyDB_LIBRARY BerkeleyDB_INCLUDE_DIR
+  VERSION_VAR _BerkeleyDB_full_version
+)
+unset(_BerkeleyDB_full_version)
+
+if(BerkeleyDB_FOUND AND NOT TARGET BerkeleyDB::BerkeleyDB)
+  add_library(BerkeleyDB::BerkeleyDB UNKNOWN IMPORTED)
+  set_target_properties(
+    BerkeleyDB::BerkeleyDB PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
+                                      "${BerkeleyDB_INCLUDE_DIR}"
+  )
+  if(BerkeleyDB_LIBRARY_RELEASE)
+    set_property(
+      TARGET BerkeleyDB::BerkeleyDB
+      APPEND
+      PROPERTY IMPORTED_CONFIGURATIONS RELEASE
+    )
+    set_target_properties(
+      BerkeleyDB::BerkeleyDB PROPERTIES IMPORTED_LOCATION_RELEASE
+                                        "${BerkeleyDB_LIBRARY_RELEASE}"
+    )
+  endif()
+  if(BerkeleyDB_LIBRARY_DEBUG)
+    set_property(
+      TARGET BerkeleyDB::BerkeleyDB
+      APPEND
+      PROPERTY IMPORTED_CONFIGURATIONS DEBUG
+    )
+    set_target_properties(
+      BerkeleyDB::BerkeleyDB PROPERTIES IMPORTED_LOCATION_DEBUG
+                                        "${BerkeleyDB_LIBRARY_DEBUG}"
+    )
+  endif()
+endif()

+ 151 - 0
cmake/modules/FindErlang.cmake

@@ -0,0 +1,151 @@
+# https://gist.github.com/JayKickliter/c79cad0c3e3acfc3465cac41b7051fa9
+# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+#[=======================================================================[.rst:
+FindErlang
+-------
+
+Finds Erlang libraries.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+This module provides the following imported targets, if found:
+
+``Erlang::Erlang``
+  Header only interface library suitible for compiling NIFs.
+
+``Erlang::EI``
+  Erlang interface library.
+
+``Erlang::ERTS``
+  Erlang runtime system library.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This will define the following variables:
+
+``Erlang_FOUND``
+  True if the system has the Erlang library.
+``Erlang_RUNTIME``
+  The path to the Erlang runtime.
+``Erlang_COMPILE``
+  The path to the Erlang compiler.
+``Erlang_EI_PATH``
+  The path to the Erlang erl_interface path.
+``Erlang_ERTS_PATH``
+  The path to the Erlang erts path.
+``Erlang_EI_INCLUDE_DIRS``
+  /include appended to Erlang_EI_PATH.
+``Erlang_EI_LIBRARY_PATH``
+  /lib appended to Erlang_EI_PATH.
+``Erlang_ERTS_INCLUDE_DIRS``
+  /include appended to Erlang_ERTS_PATH.
+``Erlang_ERTS_LIBRARY_PATH``
+  /lib appended to Erlang_ERTS_PATH.
+
+#]=======================================================================]
+include(FindPackageHandleStandardArgs)
+
+set(Erlang_BIN_PATH $ENV{ERLANG_HOME}/bin /opt/bin /sw/bin /usr/bin
+                    /usr/local/bin /opt/local/bin
+)
+
+find_program(
+  Erlang_RUNTIME
+  NAMES erl
+  PATHS ${Erlang_BIN_PATH}
+)
+
+find_program(
+  Erlang_COMPILE
+  NAMES erlc
+  PATHS ${Erlang_BIN_PATH}
+)
+
+execute_process(
+  COMMAND erl -noshell -eval "io:format(\"~s\", [code:lib_dir()])" -s erlang
+          halt OUTPUT_VARIABLE Erlang_OTP_LIB_DIR
+)
+
+execute_process(
+  COMMAND erl -noshell -eval "io:format(\"~s\", [code:root_dir()])" -s erlang
+          halt OUTPUT_VARIABLE Erlang_OTP_ROOT_DIR
+)
+
+execute_process(
+  COMMAND
+    erl -noshell -eval
+    "io:format(\"~s\",[filename:basename(code:lib_dir('erl_interface'))])" -s
+    erlang halt
+  OUTPUT_VARIABLE Erlang_EI_DIR
+)
+
+execute_process(
+  COMMAND
+    erl -noshell -eval
+    "io:format(\"~s\",[filename:basename(code:lib_dir('erts'))])" -s erlang halt
+  OUTPUT_VARIABLE Erlang_ERTS_DIR
+)
+
+set(Erlang_EI_PATH ${Erlang_OTP_LIB_DIR}/${Erlang_EI_DIR})
+set(Erlang_EI_INCLUDE_DIRS ${Erlang_OTP_LIB_DIR}/${Erlang_EI_DIR}/include)
+set(Erlang_EI_LIBRARY_PATH ${Erlang_OTP_LIB_DIR}/${Erlang_EI_DIR}/lib)
+
+set(Erlang_ERTS_PATH ${Erlang_OTP_ROOT_DIR}/${Erlang_ERTS_DIR})
+set(Erlang_ERTS_INCLUDE_DIRS ${Erlang_OTP_ROOT_DIR}/${Erlang_ERTS_DIR}/include)
+set(Erlang_ERTS_LIBRARY_PATH ${Erlang_OTP_ROOT_DIR}/${Erlang_ERTS_DIR}/lib)
+
+find_package_handle_standard_args(
+  Erlang
+  DEFAULT_MSG
+  Erlang_RUNTIME
+  Erlang_COMPILE
+  Erlang_OTP_LIB_DIR
+  Erlang_OTP_ROOT_DIR
+  Erlang_EI_DIR
+  Erlang_ERTS_DIR
+)
+
+if(Erlang_FOUND)
+  if(NOT TARGET Erlang::Erlang)
+    add_library(Erlang::Erlang INTERFACE IMPORTED)
+    set_target_properties(
+      Erlang::Erlang PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
+                                ${Erlang_OTP_ROOT_DIR}/usr/include
+    )
+  endif()
+
+  if(NOT TARGET Erlang::ERTS)
+    add_library(Erlang::ERTS STATIC IMPORTED)
+    set_target_properties(
+      Erlang::ERTS
+      PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${Erlang_ERTS_INCLUDE_DIRS}
+                 IMPORTED_LOCATION ${Erlang_ERTS_LIBRARY_PATH}/liberts.a
+    )
+  endif()
+
+  if(NOT TARGET Erlang::EI)
+    add_library(erlang_ei STATIC IMPORTED)
+    set_property(
+      TARGET erlang_ei PROPERTY IMPORTED_LOCATION
+                                ${Erlang_EI_LIBRARY_PATH}/libei.a
+    )
+    add_library(erlang_erl_interface STATIC IMPORTED)
+    set_property(
+      TARGET erlang_erl_interface
+      PROPERTY IMPORTED_LOCATION ${Erlang_EI_LIBRARY_PATH}/liberl_interface.a
+    )
+    add_library(Erlang::EI INTERFACE IMPORTED)
+    set_property(
+      TARGET Erlang::EI PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+                                 ${Erlang_EI_INCLUDE_DIRS}
+    )
+    set_property(
+      TARGET Erlang::EI PROPERTY INTERFACE_LINK_LIBRARIES erlang_ei
+                                 erlang_erl_interface
+    )
+  endif()
+endif(Erlang_FOUND)

+ 119 - 0
cmake/modules/FindLdap.cmake

@@ -0,0 +1,119 @@
+# https://github.com/KDE/kldap/blob/master/cmake/FindLdap.cmake
+# .rst:
+# FindLdap
+# --------
+#
+# Try to find the LDAP client libraries.
+#
+# This will define the following variables:
+#
+# ``Ldap_FOUND``
+#     True if libldap is available.
+#
+# ``Ldap_VERSION``
+#     The version of libldap
+#
+# ``Ldap_INCLUDE_DIRS``
+#     This should be passed to target_include_directories() if
+#     the target is not used for linking
+#
+# ``Ldap_LIBRARIES``
+#     The LDAP libraries (libldap + liblber if available)
+#     This can be passed to target_link_libraries() instead of
+#     the ``Ldap::Ldap`` target
+#
+# If ``Ldap_FOUND`` is TRUE, the following imported target
+# will be available:
+#
+# ``Ldap::Ldap``
+#     The LDAP library
+#
+# Since pre-5.0.0.
+#
+# Imported target since 5.1.41
+#
+#=============================================================================
+# SPDX-FileCopyrightText: 2006 Szombathelyi György <[email protected]>
+# SPDX-FileCopyrightText: 2007-2024 Laurent Montel <[email protected]>
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#=============================================================================
+
+find_path(Ldap_INCLUDE_DIRS NAMES ldap.h)
+
+if(APPLE)
+  find_library(
+    Ldap_LIBRARIES
+    NAMES LDAP
+    PATHS /System/Library/Frameworks /Library/Frameworks
+  )
+else()
+  find_library(Ldap_LIBRARY NAMES ldap)
+  find_library(Lber_LIBRARY NAMES lber)
+endif()
+
+if(Ldap_LIBRARY AND Lber_LIBRARY)
+  set(Ldap_LIBRARIES ${Ldap_LIBRARY} ${Lber_LIBRARY})
+endif()
+
+if(EXISTS ${Ldap_INCLUDE_DIRS}/ldap_features.h)
+  file(READ ${Ldap_INCLUDE_DIRS}/ldap_features.h LDAP_FEATURES_H_CONTENT)
+  string(REGEX MATCH "#define LDAP_VENDOR_VERSION_MAJOR[ ]+[0-9]+"
+               _LDAP_VERSION_MAJOR_MATCH ${LDAP_FEATURES_H_CONTENT}
+  )
+  string(REGEX MATCH "#define LDAP_VENDOR_VERSION_MINOR[ ]+[0-9]+"
+               _LDAP_VERSION_MINOR_MATCH ${LDAP_FEATURES_H_CONTENT}
+  )
+  string(REGEX MATCH "#define LDAP_VENDOR_VERSION_PATCH[ ]+[0-9]+"
+               _LDAP_VERSION_PATCH_MATCH ${LDAP_FEATURES_H_CONTENT}
+  )
+
+  string(REGEX REPLACE ".*_MAJOR[ ]+(.*)" "\\1" LDAP_VERSION_MAJOR
+                       ${_LDAP_VERSION_MAJOR_MATCH}
+  )
+  string(REGEX REPLACE ".*_MINOR[ ]+(.*)" "\\1" LDAP_VERSION_MINOR
+                       ${_LDAP_VERSION_MINOR_MATCH}
+  )
+  string(REGEX REPLACE ".*_PATCH[ ]+(.*)" "\\1" LDAP_VERSION_PATCH
+                       ${_LDAP_VERSION_PATCH_MATCH}
+  )
+
+  set(Ldap_VERSION
+      "${LDAP_VERSION_MAJOR}.${LDAP_VERSION_MINOR}.${LDAP_VERSION_PATCH}"
+  )
+endif()
+
+include(FindPackageHandleStandardArgs)
+
+find_package_handle_standard_args(
+  Ldap
+  FOUND_VAR Ldap_FOUND
+  REQUIRED_VARS Ldap_LIBRARIES Ldap_INCLUDE_DIRS
+  VERSION_VAR Ldap_VERSION
+)
+
+if(Ldap_FOUND AND NOT TARGET Lber::Lber)
+  add_library(Lber::Lber UNKNOWN IMPORTED)
+  set_target_properties(
+    Lber::Lber PROPERTIES IMPORTED_LOCATION "${Lber_LIBRARY}"
+  )
+endif()
+
+if(Ldap_FOUND AND NOT TARGET Ldap::Ldap)
+  add_library(Ldap::Ldap UNKNOWN IMPORTED)
+  set_target_properties(
+    Ldap::Ldap
+    PROPERTIES IMPORTED_LOCATION "${Ldap_LIBRARY}"
+               INTERFACE_INCLUDE_DIRECTORIES "${Ldap_INCLUDE_DIRS}"
+               INTERFACE_LINK_LIBRARIES Lber::Lber
+  )
+endif()
+
+mark_as_advanced(Ldap_INCLUDE_DIRS Ldap_LIBRARY Lber_LIBRARY Ldap_LIBRARIES)
+
+include(FeatureSummary)
+set_package_properties(
+  Ldap PROPERTIES
+  URL "https://www.openldap.org/"
+  DESCRIPTION "LDAP (Lightweight Directory Access Protocol) libraries."
+)

+ 60 - 0
cmake/modules/FindLibev.cmake

@@ -0,0 +1,60 @@
+#[=======================================================================[.rst:
+FindLibev
+---------
+
+Find the Libev library.
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``Libev::Libev``
+  The Libev library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``Libev_FOUND``
+  If false, do not try to use Libev.
+``LIBEV_INCLUDE_DIR``
+  where to find libev headers.
+``LIBEV_LIBRARIES``
+  the libraries needed to use Libev.
+``LIBEV_VERSION``
+  the version of the Libev library found
+
+#]=======================================================================]
+
+find_path(LIBEV_INCLUDE_DIR ev.h HINTS "${LIBEV_DIR}" "${LIBEV_DIR}/include")
+
+find_library(
+  LIBEV_LIBRARY
+  NAMES ev libev
+  HINTS "${LIBEV_DIR}" "${LIBEV_DIR}/lib"
+)
+
+set(LIBEV_LIBRARIES "")
+
+if(LIBEV_INCLUDE_DIR AND LIBEV_LIBRARY)
+  if(NOT TARGET Libev::Libev)
+    add_library(Libev::Libev UNKNOWN IMPORTED)
+    set_target_properties(
+      Libev::Libev
+      PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBEV_INCLUDE_DIR}"
+                 IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+                 IMPORTED_LOCATION "${LIBEV_LIBRARY}"
+    )
+  endif()
+endif()
+
+list(APPEND LIBEV_LIBRARIES "${LIBEV_LIBRARY}")
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+  Libev REQUIRED_VARS LIBEV_LIBRARIES LIBEV_INCLUDE_DIR
+)
+
+mark_as_advanced(LIBEV_INCLUDE_DIR LIBEV_LIBRARIES LIBEV_LIBRARY)

+ 68 - 0
cmake/modules/FindMariaDBClient.cmake

@@ -0,0 +1,68 @@
+# https://github.com/viaduck/cmake-modules/blob/master/FindMariaDBClient.cmake
+# MIT License
+#
+# Copyright (c) 2018 The ViaDuck Project
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+
+# - Try to find MariaDB client library. This matches both the "old" client library and the new C connector.
+# Once found this will define
+#  MariaDBClient_FOUND - System has MariaDB client library
+#  MariaDBClient_INCLUDE_DIRS - The MariaDB client library include directories
+#  MariaDBClient_LIBRARIES - The MariaDB client library
+
+# includes
+find_path(
+  MariaDBClient_INCLUDE_DIR
+  NAMES mysql.h
+  PATH_SUFFIXES mariadb mysql
+)
+
+# library
+set(BAK_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
+find_library(
+  MariaDBClient_LIBRARY
+  NAMES mariadb libmariadb mariadbclient libmariadbclient mysqlclient
+        libmysqlclient
+  PATH_SUFFIXES mariadb mysql
+)
+set(CMAKE_FIND_LIBRARY_SUFFIXES ${BAK_CMAKE_FIND_LIBRARY_SUFFIXES})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+  MariaDBClient DEFAULT_MSG MariaDBClient_LIBRARY MariaDBClient_INCLUDE_DIR
+)
+
+if(MariaDBClient_FOUND)
+  if(NOT TARGET MariaDBClient::MariaDBClient)
+    add_library(MariaDBClient::MariaDBClient UNKNOWN IMPORTED)
+    set_target_properties(
+      MariaDBClient::MariaDBClient
+      PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${MariaDBClient_INCLUDE_DIR}"
+                 IMPORTED_LOCATION "${MariaDBClient_LIBRARY}"
+    )
+  endif()
+endif()
+
+mark_as_advanced(MariaDBClient_INCLUDE_DIR MariaDBClient_LIBRARY)
+
+set(MariaDBClient_LIBRARIES ${MariaDBClient_LIBRARY})
+set(MariaDBClient_INCLUDE_DIRS ${MariaDBClient_INCLUDE_DIR})

+ 964 - 0
cmake/modules/FindMySQL.cmake

@@ -0,0 +1,964 @@
+# -*- indent-tabs-mode:nil; -*-
+# vim: set expandtab:
+#
+# Copyright (c) 2011, 2024, Oracle and/or its affiliates.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License, version 2.0, as
+# published by the Free Software Foundation.
+#
+# This program is designed to work with certain software (including
+# but not limited to OpenSSL) that is licensed under separate terms, as
+# designated in a particular file or component or in included license
+# documentation. The authors of MySQL hereby grant you an additional
+# permission to link the program and your derivative works with the
+# separately licensed software that they have either included with
+# the program or referenced in the documentation.
+#
+# Without limiting anything contained in the foregoing, this file,
+# which is part of Connector/ODBC, is also subject to the
+# Universal FOSS Exception, version 1.0, a copy of which can be found at
+# https://oss.oracle.com/licenses/universal-foss-exception.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License, version 2.0, for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+##########################################################################
+
+##########################################################################
+#
+# Configuration variables, all optional, are
+#
+#   MYSQL_DIR         - Set in environment or as parameter to "cmake",
+#                       this is the top directory of the MySQL Server or
+#                       Connector/C install
+#   MYSQL_INCLUDE_DIR - Set in environment or as parameter to "cmake",
+#                       this is the include directory where to find
+#                       the client library
+#   MYSQL_LIB_DIR     - Set in environment or as parameter to "cmake",
+#                       this is the library directory where to find
+#                       the client library
+#   MYSQLCLIENT_STATIC_LINKING
+#                     - Specify that you want static linking, dynamic
+#                       linking is the default
+#   MYSQLCLIENT_NO_THREADS
+#                     - Specify to link against the single threaded
+#                       library, "libmysqlclient". Note that in 5.5
+#                       and up "libmysqlclient" is multithreaded and
+#                       "libmysqlclient_r" just a soft link to it
+#   MYSQL_CONFIG_EXECUTABLE
+#                     - "mysql_config" executable to use
+#   MYSQL_CXX_LINKAGE - Specify that client library needs C++ linking
+#   MYSQL_EXTRA_LIBRARIES
+#                     - Libraries to add to the linkage
+#   MYSQL_CFLAGS      - C compiler flags
+#   MYSQL_CXXFLAGS    - C++ compiler flags
+#   MYSQL_LINK_FLAGS  - User defined extra linkage flags
+#   FINDMYSQL_DEBUG   - Set if want debug output from this script
+#
+# Note that most variables above, if not set by the user they will be
+# set by this include file.
+#
+# In addition, the below CMake variables are set by this include file
+#
+#   MYSQL_VERSION     - Three position numeric version, like 5.6.41
+#   MYSQL_VERSION_ID  - Numeric padded version, 5.13.4 => 51304
+#   MYSQL_NUM_VERSION - Same as MYSQL_VERSION_ID, for compatibility
+#   MYSQL_LIB         - Path to the client library
+#   MYSQL_LIBRARIES   - Library name, might be "-lmysqlclient" while
+#                       MYSQL_LIB is the path to the library
+#   MYSQL_CLIENT_LIBS - Same as MYSQL_LIBRARIES, for compatibility
+#
+# (1) If MYSQL_INCLUDE_DIR or MYSQL_LIB_DIR are given, these are
+#     used and an error is reported if can't be used
+# (2) If MYSQL_CONFIG_EXECUTABLE is given, it is used to get
+#     headers and libraries
+# (3) If MYSQL_DIR is given and "${MYSQL_DIR}/bin/mysql_config" is
+#     found, then same as (2)
+# (4) If MYSQL_DIR is given and no "${MYSQL_DIR}/bin/mysql_config",
+#     search MYSQL_DIR
+#
+# FIXME if we get a "mysql_config" on Windows, things needs to change
+# FIXME rename the VERSION variables above
+# FIXME let MYSQL_VERSION include "-beta" etc?
+# FIXME can mysql_config --version be C/C verson?
+# FIXME if no mysql_config, find version from include/mysql_version.h?
+#       #define MYSQL_SERVER_VERSION       "5.7.5-m15"
+#       #define MYSQL_VERSION_ID            50705
+#       #define LIBMYSQL_VERSION           "6.1.5"
+#       #define LIBMYSQL_VERSION_ID         60105
+# FIXME can MYSQL_LIB_DIR be a list of paths?
+# FIXME is MYSQLCLIENT_LIBS a better name?
+# FIXME cache variables, makes them command line args?
+# FIXME really do include_directories() and link_directories()? Likely
+# FIXME add check that if not static, not picked up .a or mysqlclient.lib
+# FIXME MYSQL_VERSION_ID need to take into account Cluster versions
+#       and Connector/C versions
+# FIXME handle MYSQL_VERSION_ID, LIBMYSQL_VERSION and LIBMYSQL_VERSION_ID?
+#
+##########################################################################
+
+##########################################################################
+#
+# Check the input data
+#
+##########################################################################
+
+# If using both MYSQL_DIR as a cmake argument and set in environment,
+# and not empty strings, they better be the same. Else stop and complain
+
+set(ENV_OR_OPT_VARS
+    MYSQL_DIR
+    MYSQL_INCLUDE_DIR
+    MYSQL_LIB_DIR
+    MYSQL_LIB_DIR_LIST
+    MYSQL_PLUGIN_DIR
+    MYSQL_CFLAGS
+    MYSQL_CXXFLAGS
+    MYSQL_CONFIG_EXECUTABLE
+    MYSQLCLIENT_STATIC_LINKING
+    MYSQLCLIENT_NO_THREADS
+    MYSQL_CXX_LINKAGE
+    MYSQL_EXTRA_LIBRARIES
+    MYSQL_LINK_FLAGS
+)
+
+# Mark the variable names that have values that are paths
+set(ENV_OR_OPT_PATH_VARS MYSQL_DIR MYSQL_INCLUDE_DIR MYSQL_LIB_DIR
+                         MYSQL_PLUGIN_DIR
+)
+
+foreach(_xvar ${ENV_OR_OPT_VARS})
+
+  if((DEFINED ${_xvar})
+     AND (DEFINED ENV{${_xvar}})
+     AND (NOT "${${_xvar}}" STREQUAL "")
+     AND (NOT "$ENV{${_xvar}}" STREQUAL "")
+     AND (NOT "$ENV{${_xvar}}" STREQUAL "${${_xvar}}")
+  )
+    message(FATAL_ERROR "Please pass -D${_xvar}=... as an argument or "
+                        "set ${_xvar} in the environment, but not both"
+    )
+  endif()
+
+  # Now we know both are not set, set the CMake variable if needed
+  if((DEFINED ENV{${_xvar}}) AND (NOT "$ENV{${_xvar}}" STREQUAL ""))
+    set(${_xvar} $ENV{${_xvar}})
+  endif()
+
+  # Notmalize the path if the variable is set and is a path
+  if(${_xvar})
+    list(FIND ENV_OR_OPT_PATH_VARS ${_xvar} _index)
+    if(${_index} GREATER -1)
+      file(TO_CMAKE_PATH "${${_xvar}}" ${_xvar})
+      get_filename_component(${_xvar} ${${_xvar}} ABSOLUTE)
+    endif()
+  endif()
+
+endforeach()
+
+# Bail out if both MYSQL_DIR/MYSQL_CONFIG_EXECUTABLE and MYSQL_INCLUDE/LIB_DIR
+# were given
+
+if(MYSQL_DIR AND (MYSQL_INCLUDE_DIR OR MYSQL_LIB_DIR))
+  message(
+    FATAL_ERROR
+      "Both MYSQL_DIR and MYSQL_INCLUDE_DIR/MYSQL_LIB_DIR were specified,"
+      " use either one or the other way of pointing at MySQL location."
+  )
+endif()
+
+if(MYSQL_CONFIG_EXECUTABLE AND (MYSQL_INCLUDE_DIR OR MYSQL_LIB_DIR))
+  message(
+    FATAL_ERROR
+      "Both MYSQL_CONFIG_EXECUTABLE and MYSQL_INCLUDE_DIR/MYSQL_LIB_DIR were specified,"
+      " mixing settings detected with mysql_config and manually set by variables"
+      " is not supported and would confuse our build logic."
+  )
+endif()
+
+if(MYSQL_CONFIG_EXECUTABLE)
+  set(_mysql_config_set_by_user 1)
+else()
+  # If MYSQL_DIR is set, set MYSQL_CONFIG_EXECUTABLE
+  if((NOT WIN32)
+     AND (DEFINED MYSQL_DIR)
+     AND (EXISTS "${MYSQL_DIR}/bin/mysql_config")
+  )
+    set(MYSQL_CONFIG_EXECUTABLE "${MYSQL_DIR}/bin/mysql_config")
+    set(_mysql_config_in_mysql_dir 1)
+  endif()
+endif()
+
+##########################################################################
+#
+# Data and basic settings
+#
+##########################################################################
+
+# Set sub directory to search in
+# dist = for mysql binary distributions
+# build = for custom built tree
+
+if(CMAKE_BUILD_TYPE STREQUAL Debug)
+  set(_lib_suffix_dist debug)
+  set(_lib_suffix_build Debug)
+else()
+  set(_lib_suffix_dist opt)
+  set(_lib_suffix_build Release)
+  add_definitions(-DNDEBUG) # FIXME what?!
+endif()
+
+set(_exe_fallback_path /usr/bin /usr/local/bin /opt/mysql/mysql/bin
+                       /usr/local/mysql/bin
+)
+
+set(_include_fallback_path
+    /usr/include/mysql
+    /usr/local/include/mysql
+    /opt/mysql/mysql/include
+    /opt/mysql/mysql/include/mysql
+    /usr/local/mysql/include
+    /usr/local/mysql/include/mysql
+    $ENV{ProgramFiles}/MySQL/*/include
+    $ENV{SystemDrive}/MySQL/*/include
+)
+
+set(_lib_fallback_path
+    /usr/lib/mysql
+    /usr/local/lib/mysql
+    /usr/local/mysql/lib
+    /usr/local/mysql/lib/mysql
+    /opt/mysql/mysql/lib
+    /opt/mysql/mysql/lib/mysql
+    $ENV{ProgramFiles}/MySQL/*/lib/${_lib_suffix_dist}
+    $ENV{ProgramFiles}/MySQL/*/lib
+    $ENV{SystemDrive}/MySQL/*/lib/${_lib_suffix_dist}
+    $ENV{SystemDrive}/MySQL/*/lib
+)
+
+set(_lib_subdirs
+    # Paths in build tree, really being too nice
+    libmysql/${_lib_suffix_build}
+    client/${_lib_suffix_build}
+    libmysql_r/.libs
+    libmysql/.libs
+    libmysql
+    # Install sub directories
+    lib/mysql
+    lib/${_lib_suffix_dist} # Need to be before "lib"
+    lib
+)
+
+set(_static_subdirs mysql ${_lib_suffix_dist})
+
+if(MSVC90)
+  set(_vs_subdir vs9)
+elseif(MSVC10)
+  set(_vs_subdir vs10)
+elseif(MSVC11)
+  set(_vs_subdir vs11)
+elseif(MSVC12)
+  set(_vs_subdir vs12)
+elseif(MSVC13)
+  set(_vs_subdir vs13)
+elseif(MSVC14)
+  set(_vs_subdir vs14)
+elseif(MSVC15)
+  set(_vs_subdir vs15)
+endif()
+
+if(_vs_subdir)
+  if("${_lib_suffix_dist}" STREQUAL "debug")
+    set(_vs_subdir "${_vs_subdir}/debug")
+  endif()
+  list(INSERT _lib_subdirs 0 "lib/${_vs_subdir}")
+endif()
+
+# For Windows, the client library name differs, so easy to
+# make sure find_library() picks the right one. For Unix, it
+# is the file extension that differs. In the static library
+# case we know it is ".a", so we add it to the library name
+# we search for to make sure it is picked in the static case.
+if(WIN32)
+  set(_dynamic_libs "libmysql")
+  set(_static_libs "mysqlclient")
+  set(_static_lib_ext ".lib") # Careful, can be import library for DLL
+elseif(MYSQLCLIENT_NO_THREADS)
+  # In 5.1 and below there is a single threaded library
+  set(_dynamic_libs "mysqlclient")
+  set(_static_libs "libmysqlclient.a")
+  set(_static_lib_ext ".a")
+else()
+  # We try the multithreaded "libmysqlclient_r" first and if not
+  # there, pick "libmysqlclient" that in 5.5 and up is multithreaded
+  # anyway (soft link "libmysqlclient_r" is not installed MySQL Server
+  # 5.6 and Debian/Ubuntu and might go in 5.7 for all installs)
+  set(_dynamic_libs "mysqlclient_r" "mysqlclient")
+  set(_static_libs "libmysqlclient_r.a" "libmysqlclient.a")
+  set(_static_lib_ext ".a")
+endif()
+
+if(MYSQLCLIENT_STATIC_LINKING)
+  set(_link_type "static")
+  set(_search_libs ${_static_libs})
+else()
+  set(_link_type "dynamic")
+  set(_search_libs ${_dynamic_libs})
+endif()
+
+# Just to pretty print in error messages
+string(REPLACE ";" " " _pp_search_libs "${_search_libs}")
+string(REPLACE ";" " " _pp_lib_subdirs "${_lib_subdirs}")
+string(REPLACE ";" " " _pp_lib_fallback_path "${_lib_fallback_path}")
+string(REPLACE ";" " " _pp_include_fallback_path "${_include_fallback_path}")
+
+message(STATUS "You will link ${_link_type}ally to the MySQL client"
+               " library (set with -DMYSQLCLIENT_STATIC_LINKING=<bool>)"
+)
+message(
+  STATUS
+    "Searching for ${_link_type} libraries with the base name(s) \"${_pp_search_libs}\""
+)
+
+##########################################################################
+#
+# Macros
+#
+##########################################################################
+
+# ----------------------------------------------------------------------
+#
+# Macro that runs "mysql_config ${_opt}" and return the line after
+# trimming away ending space/newline.
+#
+# _mysql_conf(
+#   _var    - output variable name, will contain a ';' separated list
+#   _opt    - the flag to give to mysql_config
+#
+# ----------------------------------------------------------------------
+
+macro(_mysql_conf _var _opt)
+  execute_process(
+    COMMAND ${MYSQL_CONFIG_EXECUTABLE} ${_opt}
+    OUTPUT_VARIABLE ${_var}
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+  )
+endmacro()
+
+# ----------------------------------------------------------------------
+#
+# Macro that runs "mysql_config ${_opt}", selects output args using a
+# regex, and clean it up a bit removing space/tab/newline before
+# setting it to a variable.
+#
+# _mysql_config(
+#   _var    - output variable name, will contain a ';' separated list
+#   _regex  - regular expression matching the prefix of args to select
+#   _opt    - the flag to give to mysql_config
+#
+# ----------------------------------------------------------------------
+
+macro(_mysql_config _var _regex _opt)
+  _mysql_conf(_mysql_config_output ${_opt})
+  string(REGEX MATCHALL "${_regex}([^ ]+)" _mysql_config_output
+               "${_mysql_config_output}"
+  )
+  string(REGEX REPLACE "^[ \t]+" "" _mysql_config_output
+                       "${_mysql_config_output}"
+  )
+  if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
+    string(REGEX REPLACE " -latomic" "" _mysql_config_output
+                         "${_mysql_config_output}"
+    )
+  endif()
+  string(REGEX REPLACE "${_regex}" "" _mysql_config_output
+                       "${_mysql_config_output}"
+  )
+  separate_arguments(_mysql_config_output)
+  set(${_var} ${_mysql_config_output})
+endmacro()
+
+# ----------------------------------------------------------------------
+#
+# Macro that runs "mysql_config ${_opt}" and selects output using a
+# prefix regex. Cleans it up a bit removing space/tab/newline. Then
+# removes the prefix on all in the list, and finally replace what
+# matches another regular expression with a replacement string.
+#
+# _mysql_config_replace(
+#   _var     - output variable name, will contain a ';' separated list
+#   _regex1  - regular expression to match out arguments
+#   _replace - what to replace match _regex1 with
+#   _regex2  - regular expression matching the prefix of args to select
+#   _opt     - the flag to give to mysql_config
+#
+# ----------------------------------------------------------------------
+
+macro(_mysql_config_replace _var _regex1 _replace _regex2 _opt)
+  _mysql_conf(_mysql_config_output ${_opt})
+  string(REGEX MATCHALL "${_regex2}([^ ]+)" _mysql_config_output
+               "${_mysql_config_output}"
+  )
+  string(REGEX REPLACE "^[ \t]+" "" _mysql_config_output
+                       "${_mysql_config_output}"
+  )
+  if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
+    string(REGEX REPLACE " -latomic" "" _mysql_config_output
+                         "${_mysql_config_output}"
+    )
+  endif()
+  string(REGEX REPLACE "${_regex2}" "" _mysql_config_output
+                       "${_mysql_config_output}"
+  )
+  string(REGEX REPLACE "${_regex1}" "${_replace}" _mysql_config_output
+                       "${_mysql_config_output}"
+  )
+  separate_arguments(_mysql_config_output)
+  set(${_var} ${_mysql_config_output})
+endmacro()
+
+# ----------------------------------------------------------------------
+#
+# Macro to check that we found a library and that we got the right type
+#
+# ----------------------------------------------------------------------
+
+macro(_check_lib_search_error _lib_dir_var _lib_var _exta_err_string)
+
+  set(_lib "${${_lib_var}}")
+  set(_lib_dir "${${_lib_dir_var}}")
+
+  if(FINDMYSQL_DEBUG)
+    message("_lib         \"${_lib}\"")
+    message("_lib_dir     \"${_lib_dir}\"")
+    message("_lib_var     \"${_lib_var}\"")
+    message("_lib_dir_var \"${_lib_dir_var}\"")
+  endif()
+
+  set(_err_string
+      "Could not find ${_link_type} "
+      "\"${_pp_search_libs}\" in ${_lib_dir_var} "
+      "\"${_lib_dir}\" ${_exta_err_string}"
+  )
+
+  if(NOT ${_lib_var})
+    message(FATAL_ERROR ${_err_string})
+  endif()
+
+  # find_library() try find a shared library first, then a static
+  # one. For Windows the library has a different name, but for
+  # Unix only the extension differs. So we check here that we
+  # got the library kind we expected.
+  if(NOT WIN32)
+    if(NOT MYSQLCLIENT_STATIC_LINKING)
+      get_filename_component(_ext ${_lib} EXT)
+      if(${_ext} STREQUAL ${_static_lib_ext})
+        message(FATAL_ERROR ${_err_string})
+      endif()
+    endif()
+  endif()
+endmacro()
+
+##########################################################################
+#
+# Try find MYSQL_CONFIG_EXECUTABLE if not set, and find version
+#
+##########################################################################
+
+if(NOT WIN32)
+
+  if(NOT MYSQL_CONFIG_EXECUTABLE)
+    find_program(
+      MYSQL_CONFIG_EXECUTABLE
+      NAMES mysql_config
+      DOC "full path of mysql_config"
+      PATHS ${_exe_fallback_path}
+    )
+  endif()
+
+  if(MYSQL_CONFIG_EXECUTABLE)
+    message(STATUS "mysql_config was found ${MYSQL_CONFIG_EXECUTABLE}")
+
+    _mysql_conf(MYSQL_VERSION "--version")
+  endif()
+
+endif()
+
+##########################################################################
+#
+# Find MYSQL_INCLUDE_DIR
+#
+##########################################################################
+
+if(FINDMYSQL_DEBUG AND MYSQL_INCLUDE_DIR)
+  message("DBG: User gave MYSQL_INCLUDE_DIR = \"${MYSQL_INCLUDE_DIR}\"")
+endif()
+
+if(FINDMYSQL_DEBUG AND MYSQL_DIR)
+  message("DBG: User gave MYSQL_DIR = \"${MYSQL_DIR}\"")
+endif()
+
+if(MYSQL_INCLUDE_DIR)
+
+  if(FINDMYSQL_DEBUG)
+    message("DBG: Using MYSQL_INCLUDE_DIR to find \"mysql.h\"")
+  endif()
+
+  if(NOT EXISTS "${MYSQL_INCLUDE_DIR}/mysql.h")
+    message(FATAL_ERROR "MYSQL_INCLUDE_DIR given, but no \"mysql.h\" "
+                        "in \"${MYSQL_INCLUDE_DIR}\""
+    )
+  endif()
+
+elseif(
+  MYSQL_DIR
+  AND (NOT _mysql_config_in_mysql_dir)
+  AND (NOT _mysql_config_set_by_user)
+)
+
+  if(FINDMYSQL_DEBUG)
+    message("DBG: Using MYSQL_DIR without \"mysql_config\" to find \"mysql.h\"")
+  endif()
+
+  set(MYSQL_INCLUDE_DIR "${MYSQL_DIR}/include")
+  if(NOT EXISTS "${MYSQL_INCLUDE_DIR}/mysql.h")
+    message(FATAL_ERROR "MYSQL_DIR given, but no \"mysql.h\" "
+                        "in \"${MYSQL_INCLUDE_DIR}\""
+    )
+  endif()
+
+elseif(MYSQL_CONFIG_EXECUTABLE)
+
+  if(FINDMYSQL_DEBUG)
+    message("DBG: Using \"mysql_config\" to find \"mysql.h\"")
+  endif()
+
+  # This code assumes there is just one "-I...." and that
+  # no space between "-I" and the path
+  _mysql_config(MYSQL_INCLUDE_DIR "(^| )-I" "--include")
+  if(NOT MYSQL_INCLUDE_DIR)
+    message(FATAL_ERROR "Could not find the include dir from running "
+                        "\"${MYSQL_CONFIG_EXECUTABLE}\""
+    )
+  endif()
+
+  if(NOT EXISTS "${MYSQL_INCLUDE_DIR}/mysql.h")
+    message(
+      FATAL_ERROR "Could not find \"mysql.h\" in \"${MYSQL_INCLUDE_DIR}\" "
+                  "found from running \"${MYSQL_CONFIG_EXECUTABLE}\""
+    )
+  endif()
+
+else()
+
+  if(FINDMYSQL_DEBUG)
+    message("DBG: Using find_path() searching "
+            "\"${_pp_include_fallback_path}\" to find \"mysql.h\""
+    )
+  endif()
+
+  # No specific paths, try some common install paths
+  find_path(MYSQL_INCLUDE_DIR mysql.h ${_include_fallback_path})
+
+  if(NOT MYSQL_INCLUDE_DIR)
+    message(FATAL_ERROR "Could not find \"mysql.h\" from searching "
+                        "\"${_pp_include_fallback_path}\""
+    )
+  endif()
+
+endif()
+
+if(FINDMYSQL_DEBUG)
+  message("DBG: MYSQL_INCLUDE_DIR = \"${MYSQL_INCLUDE_DIR}\"")
+endif()
+
+##########################################################################
+#
+# Find MYSQL_LIB_DIR, MYSQL_LIB, MYSQL_PLUGIN_DIR and MYSQL_LIBRARIES
+#
+##########################################################################
+
+if(FINDMYSQL_DEBUG AND MYSQL_LIB_DIR)
+  message("DBG: User gave MYSQL_LIB_DIR = \"${MYSQL_LIB_DIR}\"")
+endif()
+
+if(MYSQL_LIB_DIR)
+
+  if(FINDMYSQL_DEBUG)
+    message("DBG: Using find_library() searching MYSQL_LIB_DIR")
+  endif()
+
+  find_library(
+    MYSQL_LIB
+    NAMES ${_search_libs}
+    PATHS "${MYSQL_LIB_DIR}"
+    NO_DEFAULT_PATH
+  )
+  _check_lib_search_error(MYSQL_LIB_DIR MYSQL_LIB "")
+  set(MYSQL_LIBRARIES ${MYSQL_LIB})
+
+  if(NOT DEFINED MYSQL_PLUGIN_DIR)
+    set(MYSQL_PLUGIN_DIR "${MYSQL_LIB_DIR}/plugin")
+  endif()
+
+elseif(
+  MYSQL_DIR
+  AND (NOT _mysql_config_in_mysql_dir)
+  AND (NOT _mysql_config_set_by_user)
+)
+
+  if(FINDMYSQL_DEBUG)
+    message("DBG: Using find_library() searching "
+            "MYSQL_DIR and \"${_pp_lib_subdirs}\""
+    )
+  endif()
+
+  find_library(
+    MYSQL_LIB
+    NAMES ${_search_libs}
+    PATHS "${MYSQL_DIR}"
+    PATH_SUFFIXES ${_lib_subdirs}
+    NO_DEFAULT_PATH
+  )
+  _check_lib_search_error(MYSQL_DIR MYSQL_LIB "in \"${_pp_lib_subdirs}\"")
+  get_filename_component(MYSQL_LIB_DIR "${MYSQL_LIB}" PATH)
+  set(MYSQL_LIBRARIES "${MYSQL_LIB}")
+
+  if(((NOT DEFINED MYSQL_PLUGIN_DIR) OR (NOT ${MYSQL_PLUGIN_DIR}))
+     AND MYSQL_LIB_DIR
+  )
+    if(EXISTS "${MYSQL_LIB_DIR}/plugin")
+      set(MYSQL_PLUGIN_DIR "${MYSQL_LIB_DIR}/plugin")
+    else()
+      # FIXME: If directory does not exist it must be a debug dir layout
+      if(EXISTS "${MYSQL_LIB_DIR}/../plugin/")
+        set(MYSQL_PLUGIN_DIR "${MYSQL_LIB_DIR}/../plugin")
+      endif()
+    endif()
+  endif()
+
+elseif(MYSQL_CONFIG_EXECUTABLE)
+
+  if(FINDMYSQL_DEBUG)
+    message("DBG: Using \"mysql_config\" to find the libraries")
+  endif()
+
+  # This code assumes there is just one "-L...." and that
+  # no space between "-L" and the path
+  _mysql_config(MYSQL_LIB_DIR "(^| )-L" "--libs")
+
+  # Note: Allow overriding plugin dir reported by mysql_config because
+  # that can be wrong sometimes
+
+  if(NOT MYSQL_PLUGIN_DIR)
+    _mysql_conf(MYSQL_PLUGIN_DIR "--variable=plugindir")
+  endif()
+
+  if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
+    # This is needed to make Solaris binaries using the default runtime lib path
+    _mysql_config(DEV_STUDIO_RUNTIME_DIR "(^| )-R" "--libs")
+  endif()
+
+  list(LENGTH MYSQL_LIB_DIR dir_cnt)
+  message(STATUS "Libraries paths found: ${n}")
+  if(${dir_cnt} GREATER 1)
+    set(MYSQL_LIB_DIR_LIST ${MYSQL_LIB_DIR})
+    message(STATUS "MYSQL_LIB_DIR_LIST = ${MYSQL_LIB_DIR_LIST}")
+
+    foreach(_path_to_check IN LISTS MYSQL_LIB_DIR)
+      find_library(
+        _mysql_client_lib_var
+        NAMES ${_search_libs}
+        PATHS ${_path_to_check}
+        NO_DEFAULT_PATH
+      )
+      if(_mysql_client_lib_var)
+        message(STATUS "CLIENT LIB VAR: ${_mysql_client_lib_var}")
+        unset(_mysql_client_lib_var CACHE)
+        set(MYSQL_LIB_DIR ${_path_to_check})
+      endif()
+    endforeach(_path_to_check)
+  endif()
+
+  if(NOT MYSQL_LIB_DIR)
+    message(FATAL_ERROR "Could not find the library dir from running "
+                        "\"${MYSQL_CONFIG_EXECUTABLE}\""
+    )
+  endif()
+
+  if(NOT EXISTS "${MYSQL_LIB_DIR}")
+    message(FATAL_ERROR "Could not find the directory \"${MYSQL_LIB_DIR}\" "
+                        "found from running \"${MYSQL_CONFIG_EXECUTABLE}\""
+    )
+  endif()
+
+  # We have the assumed MYSQL_LIB_DIR. The output from "mysql_config"
+  # might not be correct for static libraries, so we might need to
+  # adjust MYSQL_LIB_DIR later on.
+
+  if(MYSQLCLIENT_STATIC_LINKING)
+
+    # Find the static library, might be one level down
+    find_library(
+      MYSQL_LIB
+      NAMES ${_search_libs}
+      PATHS ${MYSQL_LIB_DIR}
+      PATH_SUFFIXES ${_static_subdirs}
+      NO_DEFAULT_PATH
+    )
+    _check_lib_search_error(MYSQL_LIB_DIR MYSQL_LIB "in \"${_static_subdirs}\"")
+
+    # Adjust MYSQL_LIB_DIR in case it changes
+    get_filename_component(MYSQL_LIB_DIR "${MYSQL_LIB}" PATH)
+
+    # Replace the current library references with the full path
+    # to the library, i.e. the -L will be ignored
+    _mysql_config_replace(
+      MYSQL_LIBRARIES "(mysqlclient|mysqlclient_r)" "${MYSQL_LIB}" "(^| )-l"
+      "--libs"
+    )
+
+  else()
+
+    _mysql_config(MYSQL_LIBRARIES "(^| )-l" "--libs")
+    foreach(__lib IN LISTS MYSQL_LIBRARIES)
+      string(REGEX MATCH "mysqlclient([^ ]*)" _matched_lib __lib)
+      if(_matched_lib)
+        set(_search_libs ${matched_lib})
+      endif()
+    endforeach()
+    # First library is assumed to be the client library
+    # list(GET MYSQL_LIBRARIES 0 _search_libs)
+    find_library(
+      MYSQL_LIB
+      NAMES ${_search_libs}
+      PATHS ${MYSQL_LIB_DIR}
+      NO_DEFAULT_PATH
+    )
+    _check_lib_search_error(MYSQL_LIB_DIR MYSQL_LIB "")
+
+  endif()
+
+else()
+
+  if(FINDMYSQL_DEBUG)
+    message("DBG: Using find_library() searching "
+            "\"${_pp_lib_fallback_path}\" to find the client library"
+    )
+  endif()
+
+  # Search standard places
+  find_library(
+    MYSQL_LIB
+    NAMES ${_search_libs}
+    PATHS ${_lib_fallback_path}
+  )
+  if(NOT MYSQL_LIB)
+    message(FATAL_ERROR "Could not find \"${_pp_search_libs}\" from searching "
+                        "\"${_pp_lib_fallback_path}\""
+    )
+  endif()
+
+  get_filename_component(MYSQL_LIB_DIR "${MYSQL_LIB}" PATH)
+
+endif()
+
+##########################################################################
+#
+# Add more libraries to MYSQL_LIBRARIES
+#
+##########################################################################
+
+# FIXME needed?!
+if(MYSQLCLIENT_STATIC_LINKING
+   AND NOT WIN32
+   AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin"
+)
+  list(APPEND MYSQL_LIBRARIES "rt")
+endif()
+
+# The built-in sys and strings are used for static and dynamic linking.
+list(APPEND SYS_LIBRARIES "mysql_sys")
+list(APPEND SYS_LIBRARIES "mysql_strings")
+list(APPEND SYS_LIBRARIES ${MYSQL_LIBRARIES})
+set(MYSQL_LIBRARIES ${SYS_LIBRARIES})
+
+if(MYSQL_EXTRA_LIBRARIES)
+  separate_arguments(MYSQL_EXTRA_LIBRARIES)
+  list(APPEND MYSQL_LIBRARIES ${MYSQL_EXTRA_LIBRARIES})
+endif()
+
+list(LENGTH MYSQL_LIBRARIES len)
+if(MYSQL_STATIC_LINKING AND (len LESS 2))
+  message(
+    WARNING
+      "Statically linking MySQL client library normally requires linking"
+      " additional libraries that the client library depends on. It seems"
+      " no extra libraries have been specified. Provide the list of required"
+      " dependencies through MYSQL_EXTRA_LIBRARIES."
+  )
+endif()
+
+# For compatibility
+set(MYSQL_CLIENT_LIBS ${MYSQL_LIBRARIES})
+
+##########################################################################
+#
+# If not found MySQL Serverv version, compile a small client app
+# and let it write a small cmake file with the settings
+#
+##########################################################################
+
+if(MYSQL_INCLUDE_DIR AND NOT MYSQL_VERSION)
+
+  # Write the C source file that will include the MySQL headers
+  set(GETMYSQLVERSION_SOURCEFILE
+      "${CMAKE_CURRENT_BINARY_DIR}/getmysqlversion.c"
+  )
+  file(WRITE "${GETMYSQLVERSION_SOURCEFILE}"
+       "#include <mysql.h>\n" "#include <stdio.h>\n" "int main() {\n"
+       "  printf(\"%s\", MYSQL_SERVER_VERSION);\n" "}\n"
+  )
+
+  # Compile and run the created executable, store output in MYSQL_VERSION
+  try_run(
+    _run_result _compile_result "${CMAKE_BINARY_DIR}"
+    "${GETMYSQLVERSION_SOURCEFILE}"
+    CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${MYSQL_INCLUDE_DIR}"
+    RUN_OUTPUT_VARIABLE MYSQL_VERSION
+  )
+
+  if(FINDMYSQL_DEBUG)
+    if(NOT _compile_result)
+      message("DBG: Could not compile \"getmysqlversion.c\"")
+    endif()
+    if(_run_result)
+      message("DBG: Running \"getmysqlversion\" returned ${_run_result}")
+    endif()
+  endif()
+
+endif()
+
+##########################################################################
+#
+# Clean up MYSQL_VERSION and create MYSQL_VERSION_ID/MYSQL_NUM_VERSION
+#
+##########################################################################
+
+if(NOT MYSQL_VERSION)
+  message(FATAL_ERROR "Could not determine the MySQL Server version")
+endif()
+
+# Clean up so only numeric, in case of "-alpha" or similar
+string(REGEX MATCHALL "([0-9]+.[0-9]+.[0-9]+)" MYSQL_VERSION "${MYSQL_VERSION}")
+# To create a fully numeric version, first normalize so N.NN.NN
+string(REGEX REPLACE "[.]([0-9])[.]" ".0\\1." MYSQL_VERSION_ID
+                     "${MYSQL_VERSION}"
+)
+string(REGEX REPLACE "[.]([0-9])$" ".0\\1" MYSQL_VERSION_ID
+                     "${MYSQL_VERSION_ID}"
+)
+# Finally remove the dot
+string(REGEX REPLACE "[.]" "" MYSQL_VERSION_ID "${MYSQL_VERSION_ID}")
+set(MYSQL_NUM_VERSION ${MYSQL_VERSION_ID})
+
+##########################################################################
+#
+# Try determine if to use C++ linkage, and also find C++ flags
+#
+##########################################################################
+
+if(NOT WIN32)
+
+  if(MYSQL_CONFIG_EXECUTABLE)
+
+    if(NOT MYSQL_CFLAGS)
+      _mysql_conf(MYSQL_CFLAGS "--cflags")
+    endif()
+
+    if(NOT MYSQL_CXXFLAGS)
+      if(MYSQL_CXX_LINKAGE OR MYSQL_VERSION_ID GREATER 50603)
+        _mysql_conf(MYSQL_CXXFLAGS "--cxxflags")
+        set(MYSQL_CXX_LINKAGE 1)
+      else()
+        set(MYSQL_CXXFLAGS "${MYSQL_CFLAGS}")
+      endif()
+    endif()
+
+    # FIXME this should not be needed, caller of this module should set
+    #       it's own flags and just use the library on it's on terms
+    #       (change the infe message if enabling this code)
+    #   if(NOT MYSQL_LINK_FLAGS)
+    #     # Find -mcpu -march -mt -m32 -m64 and other flags starting with "-m"
+    #     string(REGEX MATCHALL "(^| )-m([^\r\n ]+)" MYSQL_LINK_FLAGS "${MYSQL_CXXFLAGS}")
+    #     string(REGEX REPLACE "^ " ""  MYSQL_LINK_FLAGS "${MYSQL_LINK_FLAGS}")
+    #     string(REGEX REPLACE "; " ";" MYSQL_LINK_FLAGS "${MYSQL_LINK_FLAGS}")
+    #   endif()
+
+  endif()
+
+endif()
+
+##########################################################################
+#
+# Inform CMake where to look for headers and libraries
+#
+##########################################################################
+
+# string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKEBT)
+# set(CMAKE_CXX_FLAGS                "${CMAKE_CXX_FLAGS} ${MYSQL_CXXFLAGS}")
+# set(CMAKE_CXX_FLAGS_${CMAKEBT}     "${CMAKE_CXX_FLAGS_${CMAKEBT}} ${MYSQL_CXXFLAGS}")
+
+include_directories("${MYSQL_INCLUDE_DIR}")
+
+link_directories("${MYSQL_LIB_DIR}")
+
+message(STATUS "MYSQL_LIB_DIR_LIST = ${MYSQL_LIB_DIR_LIST}")
+if(MYSQL_LIB_DIR_LIST)
+  foreach(__libpath IN LISTS MYSQL_LIB_DIR_LIST)
+    link_directories("${__libpath}")
+  endforeach()
+endif()
+
+##########################################################################
+#
+# Report
+#
+##########################################################################
+
+message(
+  STATUS
+    "MySQL client environment/cmake variables set that the user can override"
+)
+
+message(STATUS "  MYSQL_DIR                   : ${MYSQL_DIR}")
+message(STATUS "  MYSQL_INCLUDE_DIR           : ${MYSQL_INCLUDE_DIR}")
+message(STATUS "  MYSQL_LIB_DIR               : ${MYSQL_LIB_DIR}")
+message(STATUS "  MYSQL_PLUGIN_DIR            : ${MYSQL_PLUGIN_DIR}")
+message(STATUS "  MYSQL_CONFIG_EXECUTABLE     : ${MYSQL_CONFIG_EXECUTABLE}")
+message(STATUS "  MYSQL_CXX_LINKAGE           : ${MYSQL_CXX_LINKAGE}")
+message(STATUS "  MYSQL_CFLAGS                : ${MYSQL_CFLAGS}")
+message(STATUS "  MYSQL_CXXFLAGS              : ${MYSQL_CXXFLAGS}")
+message(STATUS "  MYSQLCLIENT_STATIC_LINKING  : ${MYSQLCLIENT_STATIC_LINKING}")
+message(STATUS "  MYSQLCLIENT_NO_THREADS      : ${MYSQLCLIENT_NO_THREADS}")
+
+message(
+  STATUS "MySQL client optional environment/cmake variables set by the user"
+)
+
+message(STATUS "  MYSQL_EXTRA_LIBRARIES       : ${MYSQL_EXTRA_LIBRARIES}")
+message(STATUS "  MYSQL_LINK_FLAGS            : ${MYSQL_LINK_FLAGS}")
+
+message(STATUS "MySQL client settings that the user can't override")
+
+message(STATUS "  MYSQL_VERSION               : ${MYSQL_VERSION}")
+message(STATUS "  MYSQL_VERSION_ID            : ${MYSQL_VERSION_ID}")
+message(STATUS "  MYSQL_LIB                   : ${MYSQL_LIB}")
+message(STATUS "  MYSQL_LIBRARIES             : ${MYSQL_LIBRARIES}")

+ 82 - 0
cmake/modules/FindNETSNMP.cmake

@@ -0,0 +1,82 @@
+# https://fossies.org/linux/syslog-ng/cmake/Modules/FindNETSNMP.cmake
+#############################################################################
+# Copyright (c) 2019 Balabit
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# As an additional exemption you are allowed to compile & link against the
+# OpenSSL libraries as published by the OpenSSL project. See the file
+# COPYING for details.
+#
+#############################################################################
+
+# - Try to find the net-snmp library
+# Once done this will define
+#
+#  NETSNMP_FOUND - system has the net-snmp library
+#  NETSNMP_CFLAGS -
+#  NETSNMP_LIBS - the libraries needed to use net-snmp
+#
+
+if(NETSNMP_LIBS)
+  # Already in cache, be silent
+  set(NETSNMP_FIND_QUIETLY TRUE)
+endif(NETSNMP_LIBS)
+
+find_program(NETSNMP_CONFIG_BIN net-snmp-config)
+
+if(NETSNMP_CONFIG_BIN)
+  execute_process(
+    COMMAND ${NETSNMP_CONFIG_BIN} --cflags OUTPUT_VARIABLE _NETSNMP_CFLAGS
+  )
+  execute_process(
+    COMMAND ${NETSNMP_CONFIG_BIN} --libs OUTPUT_VARIABLE _NETSNMP_LIBS
+  )
+  # Strip trailing and leading whitespaces
+  string(STRIP "${_NETSNMP_CFLAGS}" _NETSNMP_CFLAGS)
+  string(STRIP "${_NETSNMP_LIBS}" _NETSNMP_LIBS)
+
+  set(NETSNMP_CFLAGS
+      ${_NETSNMP_CFLAGS}
+      CACHE STRING "CFLAGS for net-snmp lib"
+  )
+  set(NETSNMP_LIBS
+      ${_NETSNMP_LIBS}
+      CACHE STRING "linker options for net-snmp lib"
+  )
+  set(NETSNMP_FOUND TRUE BOOL "net-snmp is found")
+
+  add_library(NETSNMP::NETSNMP INTERFACE IMPORTED)
+  set_target_properties(
+    NETSNMP::NETSNMP PROPERTIES COMPILE_FLAGS "${NETSNMP_CFLAGS}"
+                                INTERFACE_LINK_LIBRARIES "${NETSNMP_LIBS}"
+  )
+
+  if(NOT TARGET NETSNMP::NETSNMP)
+    message(
+      FATAL_ERROR
+        "Failed to create NETSNMP::NETSNMP target, check the output of net-snmp-config"
+    )
+  endif()
+else()
+  set(NETSNMP_FOUND FALSE /BOOL "net-snmp is not found")
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+  NETSNMP DEFAULT_MSG NETSNMP_CONFIG_BIN NETSNMP_LIBS NETSNMP_CFLAGS
+)
+
+mark_as_advanced(NETSNMP_LIBS NETSNMP_CFLAGS)

+ 115 - 0
cmake/modules/FindOracle.cmake

@@ -0,0 +1,115 @@
+# https://github.com/SOCI/soci/blob/master/cmake/modules/FindOracle.cmake
+###############################################################################
+#
+# CMake module to search for Oracle client library (OCI)
+#
+# On success, the macro sets the following variables:
+# ORACLE_FOUND       = if the library found
+# ORACLE_LIBRARY     = full path to the library
+# ORACLE_LIBRARIES   = full path to the library
+# ORACLE_INCLUDE_DIR = where to find the library headers also defined,
+#                       but not for general use are
+# ORACLE_VERSION     = version of library which was found, e.g. "1.2.5"
+#
+# Copyright (c) 2009-2013 Mateusz Loskot <[email protected]>
+#
+# Developed with inspiration from Petr Vanek <[email protected]>
+# who wrote similar macro for TOra - http://torasql.com/
+#
+# Module source: http://github.com/mloskot/workshop/tree/master/cmake/
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+###############################################################################
+
+# First check for CMAKE  variable
+if(NOT ORACLE_HOME)
+  # If ORACLE_HOME is not defined check for env var and if exists set from env var
+  if(EXISTS $ENV{ORACLE_HOME})
+    set(ORACLE_HOME $ENV{ORACLE_HOME})
+  endif()
+endif()
+
+message(STATUS "ORACLE_HOME=${ORACLE_HOME}")
+
+find_path(
+  ORACLE_INCLUDE_DIR
+  NAMES oci.h
+  PATHS ${ORACLE_HOME}/rdbms/public
+        ${ORACLE_HOME}/include
+        ${ORACLE_HOME}/sdk/include # Oracle SDK
+        ${ORACLE_HOME}/OCI/include # Oracle XE on Windows
+        # instant client from rpm
+        /usr/include/oracle/*/client${LIB_SUFFIX}
+)
+
+set(ORACLE_VERSIONS
+    21
+    20
+    19
+    18
+    12
+    11
+    10
+)
+set(ORACLE_OCI_NAMES clntsh libclntsh oci
+)# Dirty trick might help on OSX, see issues/89
+set(ORACLE_OCCI_NAMES libocci occi)
+set(ORACLE_NNZ_NAMES ociw32)
+foreach(loop_var IN LISTS ORACLE_VERSIONS)
+  set(ORACLE_OCCI_NAMES ${ORACLE_OCCI_NAMES} oraocci${loop_var})
+  set(ORACLE_NNZ_NAMES ${ORACLE_NNZ_NAMES} nnz${loop_var} libnnz${loop_var})
+endforeach(loop_var)
+
+set(ORACLE_LIB_DIR
+    ${ORACLE_HOME}
+    ${ORACLE_HOME}/lib
+    ${ORACLE_HOME}/sdk/lib # Oracle SDK
+    ${ORACLE_HOME}/sdk/lib/msvc
+    ${ORACLE_HOME}/OCI/lib/msvc # Oracle XE on Windows
+    # Instant client from rpm
+    /usr/lib/oracle/*/client${LIB_SUFFIX}/lib
+)
+
+find_library(
+  ORACLE_OCI_LIBRARY
+  NAMES ${ORACLE_OCI_NAMES}
+  PATHS ${ORACLE_LIB_DIR}
+)
+find_library(
+  ORACLE_OCCI_LIBRARY
+  NAMES ${ORACLE_OCCI_NAMES}
+  PATHS ${ORACLE_LIB_DIR}
+)
+find_library(
+  ORACLE_NNZ_LIBRARY
+  NAMES ${ORACLE_NNZ_NAMES}
+  PATHS ${ORACLE_LIB_DIR}
+)
+
+set(ORACLE_LIBRARY ${ORACLE_OCI_LIBRARY} ${ORACLE_OCCI_LIBRARY}
+                   ${ORACLE_NNZ_LIBRARY}
+)
+
+if(NOT WIN32)
+  set(ORACLE_LIBRARY ${ORACLE_LIBRARY} ${ORACLE_CLNTSH_LIBRARY})
+endif(NOT WIN32)
+
+set(ORACLE_LIBRARIES ${ORACLE_LIBRARY})
+
+# Handle the QUIETLY and REQUIRED arguments and set ORACLE_FOUND to TRUE
+# if all listed variables are TRUE
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+  Oracle DEFAULT_MSG ORACLE_LIBRARY ORACLE_INCLUDE_DIR
+)
+
+if(NOT ORACLE_FOUND)
+  message(
+    STATUS
+      "None of the supported Oracle versions (${ORACLE_VERSIONS}) could be found, consider updating ORACLE_VERSIONS if the version you use is not among them."
+  )
+endif()
+
+mark_as_advanced(ORACLE_INCLUDE_DIR ORACLE_LIBRARY)

+ 51 - 0
cmake/modules/FindRadius.cmake

@@ -0,0 +1,51 @@
+find_package(PkgConfig)
+
+# TODO: Discuss if other libraries are still used
+# - radiusclient library (probaly yes)
+# - radiusclient-ng library (probaly not)
+# Old makefile just defined the compile definitions whithout checking for
+# the library.
+# Modern cmake should check for the library and define the compile
+# definitions if the library is found.
+# Latest OS (Ubuntu) only offer radcli from package managemnt
+
+# Mutually exclusive options
+
+set(RADIUSCLIENTS FREERADIUS RADCLI RADIUSCLIENT_NG)
+set(RADIUSCLIENT
+    RADCLI
+    CACHE STRING "Locking method to use"
+)
+set_property(CACHE RADIUSCLIENT PROPERTY STRINGS ${RADIUSCLIENTS})
+
+# option(FREERADIUS "Use freeradius-client library" OFF)
+# option(RADCLI "Use radcli library" ON)
+# option(RADIUSCLIENT_NG "Use radiusclient-ng library" OFF)
+
+# if(FREERADIUS AND RADCLI)
+#   message(FATAL_ERROR "Only one of FREERADIUS or RADCLI can be enabled")
+# endif()
+
+# Verify that the user-defined RADIUSCLIENT is valid
+if(NOT RADIUSCLIENT IN_LIST RADIUSCLIENTS)
+  message(
+    FATAL_ERROR
+      "Invalid RADIUSCLIENT specified: ${RADIUSCLIENT}. Available options are: ${RADIUSCLIENTS}."
+  )
+endif()
+
+if(${RADIUSCLIENT} STREQUAL "FREERADIUS")
+  # - freeradius-client library
+  set(RADIUSCLIENT_LIB "freeradius-client")
+  pkg_check_modules(RADIUS REQUIRED IMPORTED_TARGET freeradius)
+elseif(${RADIUSCLIENT} STREQUAL "RADCLI")
+  # - radcli library
+  set(RADIUSCLIENT_LIB USE_RADCLI)
+  pkg_check_modules(RADIUS REQUIRED IMPORTED_TARGET radcli)
+  # Check for radiusclient-ng version
+  # elseif(NOT radiusclient_ng STREQUAL "4")
+  #   # - radiusclient-ng v5 or v4 library
+  #   set(RADIUSCLIENT_LIB "radiusclient-ng")
+  # Uncomment if needed
+  # target_compile_definitions(MyModule PRIVATE RADIUSCLIENT_NG_5P)
+endif()

+ 74 - 0
cmake/modules_docs.cmake

@@ -0,0 +1,74 @@
+option(BUILD_DOC "Build documentation" ON)
+
+# Readme file and man page
+find_program(XSLTPROC_EXECUTABLE xsltproc QUIET)
+find_program(PANDOC_EXECUTABLE pandoc QUIET)
+
+# Function to add a module docs entry
+function(docs_add_module MODULE_NAME)
+  # message(STATUS "Adding documentation for module ${MODULE_NAME}")
+  if(BUILD_DOC)
+
+    set(MODULE_PATH "${MODULES_DIR}/${MODULE_NAME}")
+    set(MODULE_DOC_PATH "${MODULE_PATH}/doc")
+    # Check if the module has a 'doc' directory and if it contains a file named
+    # MODULE_NAME.xml
+
+    if(XSLTPROC_EXECUTABLE)
+
+      add_custom_command(
+        OUTPUT # ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.md
+               # ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.txt
+               ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/README
+        # ${MODULE_NAME}_doc The following command is used to generate the
+        # documentation in html format from the xml file
+        COMMAND
+          ${XSLTPROC_EXECUTABLE} --novalid --xinclude
+          # -o ${CMAKE_CURRENT_BINARY_DIR}/xprint2.xml
+          ${CMAKE_SOURCE_DIR}/doc/docbook/html.xsl
+          ${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_NAME}/doc/${MODULE_NAME}.xml
+        COMMAND
+          ${PANDOC_EXECUTABLE} -s -f html -t markdown_strict --output
+          ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.md
+          ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/index.html
+        COMMAND
+          ${PANDOC_EXECUTABLE} -s -f html -t plain --output
+          # ${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_NAME}/README
+          ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.txt
+          ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/index.html
+        COMMAND
+          ${CMAKE_COMMAND} -E copy
+          ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.txt
+          ${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_NAME}/README
+        DEPENDS
+          ${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_NAME}/doc/${MODULE_NAME}.xml
+          ${CMAKE_SOURCE_DIR}/doc/docbook/html.xsl
+        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}
+        COMMENT "Generating documentation with xsltproc for ${MODULE_NAME}"
+      )
+
+      add_custom_target(
+        ${MODULE_NAME}_doc
+        DEPENDS # ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.md
+                # ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.txt
+                ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/README
+      )
+
+      install(
+        FILES ${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_NAME}/README
+        RENAME README.${MODULE_NAME}
+        DESTINATION ${CMAKE_INSTALL_DOCDIR}/modules
+        COMPONENT kamailio_docs
+        # OPTIONAL
+      )
+
+      # if(IS_DIRECTORY ${MODULE_DOC_PATH} AND EXISTS
+      # ${MODULE_DOC_PATH}/${MODULE_NAME}.xml ) install( FILES
+      # ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.md DESTINATION
+      # ${CMAKE_INSTALL_DOCDIR}/modules COMPONENT kamailio-docs OPTIONAL ) #
+      # endif()
+
+      # endif()
+    endif()
+  endif()
+endfunction()

+ 97 - 0
cmake/os-specific.cmake

@@ -0,0 +1,97 @@
+# Quite analogous to the Makefile.defs file
+# This file is used to define the common flags and options for the project
+# The flags are defined as INTERFACE properties of the common library
+# The flags are then used by the other libraries and executables
+cmake_minimum_required(VERSION 3.10)
+
+# Linux specific flags
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+  message(STATUS "Configuring for Linux")
+  target_compile_definitions(common INTERFACE
+                HAVE_GETHOSTBYNAME2
+                HAVE_UNION_SEMUN
+                HAVE_SCHED_YIELD
+                HAVE_MSG_NOSIGNAL
+                HAVE_MSGHDR_MSG_CONTROL
+                HAVE_ALLOCA_H
+                HAVE_TIMEGM
+                HAVE_SCHED_SETSCHEDULER
+                HAVE_IP_MREQN
+                )
+  if(${RAW_SOCKS})
+    target_compile_definitions(common INTERFACE
+                USE_RAW_SOCKS
+                )
+  endif()
+  
+  message(STATUS "USE_FAST_LOCK = ${USE_FAST_LOCK}")
+  if(NOT ${USE_FAST_LOCK})
+    target_compile_definitions(common INTERFACE
+                USE_PTHREAD_MUTEX
+                )
+    target_link_libraries(common INTERFACE pthread)
+
+  else()
+    # Check if lock_method is posix or pthread
+    if(LOCK_METHOD STREQUAL "USE_POSIX_SEM" OR LOCK_METHOD STREQUAL "USE_PTHREAD_MUTEX" )
+      message(STATUS "Using ${LOCK_METHOD} for locks")
+      target_link_libraries(common INTERFACE pthread)
+    endif()
+
+  endif()
+
+  if(NOT DEFINED ${NO_SELECT})
+    target_compile_definitions(common INTERFACE
+                HAVE_SELECT
+                )
+  endif()
+
+  if(NOT DEFINED ${NO_EPOLL})
+    target_compile_definitions(common INTERFACE
+                HAVE_EPOLL
+                )
+  endif()
+
+  if(NOT DEFINED ${NO_SIGIO})
+    target_compile_definitions(common INTERFACE
+                HAVE_SIGIO_RT 
+                SIGINFO64_WORKAROUND
+                )
+  endif()
+
+endif()
+
+# DragonFly BSD specific flags
+if(CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
+  message(STATUS "Configuring for DragonFly BSD")
+  target_compile_definitions(common INTERFACE
+                HAVE_SOCKADDR_SA_LEN
+                HAVE_GETHOSTBYNAME2
+                HAVE_UNION_SEMUN
+                HAVE_SCHED_YIELD
+                HAVE_MSGHDR_MSG_CONTROL
+                HAVE_CONNECT_ECONNRESET_BUG
+                HAVE_TIMEGM
+                HAVE_NETINET_IN_SYSTM
+                )
+  message(STATUS "USE_FAST_LOCK = ${USE_FAST_LOCK}")
+  if(NOT ${USE_FAST_LOCK})
+    target_compile_definitions(common INTERFACE
+                USE_PTHREAD_MUTEX
+                )
+    target_link_libraries(common INTERFACE pthread)
+  endif()
+
+  if(NOT DEFINED ${NO_KQUEUE})
+    target_compile_definitions(common INTERFACE
+                HAVE_KQUEUE
+                )
+  endif()
+
+  if(NOT DEFINED ${NO_SELECT})
+    target_compile_definitions(common INTERFACE
+                HAVE_SELECT
+                )
+  endif()
+  
+endif()

+ 141 - 0
src/CMakeLists.txt

@@ -0,0 +1,141 @@
+cmake_minimum_required(VERSION 3.10)
+
+include(GNUInstallDirs)
+
+# # Check if LIBDIR is not defined if(NOT DEFINED LIBDIR) # Get the system
+# architecture if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(LIBDIR "lib64") else()
+# set(LIBDIR "lib") endif() endif()
+
+# Set the installation paths
+message(STATUS "Cross compile: ${CMAKE_CROSSCOMPILING}")
+
+message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
+message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_FULL_LIBDIR}")
+message(STATUS "CMAKE_INSTALL_BINDIR: ${CMAKE_INSTALL_FULL_BINDIR}")
+message(STATUS "CMAKE_INSTALL_SBINDIR: ${CMAKE_INSTALL_FULL_SBINDIR}")
+message(STATUS "CMAKE_INSTALL_SYSCONFDIR: ${CMAKE_INSTALL_FULL_SYSCONFDIR}")
+message(
+  STATUS
+    "CMAKE_INSTALL_LOCALSTATEDIR: /${CMAKE_INSTALL_LOCALSTATEDIR}/run/${MAIN_NAME}"
+)
+message(STATUS "CMAKE_INSTALL_DATADIR: ${CMAKE_INSTALL_FULL_DATADIR}")
+message(STATUS "CMAKE_INSTALL_DOCDIR: ${CMAKE_INSTALL_FULL_DOCDIR}")
+message(STATUS "CMAKE_INSTALL_MANDIR: ${CMAKE_INSTALL_FULL_MANDIR}")
+
+find_package(Threads REQUIRED)
+
+include(${CMAKE_SOURCE_DIR}/cmake/defs.cmake)
+
+# -----------------------
+# The following produces core/autover.h Find Git
+find_package(Git REQUIRED)
+
+if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
+  execute_process(
+    COMMAND ${GIT_EXECUTABLE} rev-parse --verify --short=6 HEAD
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+    OUTPUT_VARIABLE REPO_VER
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+  )
+
+  execute_process(
+    COMMAND
+      bash -c
+      "${GIT_EXECUTABLE} diff-index --name-only HEAD | grep -vE 'Makefile|CMakeLists.txt'"
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+    OUTPUT_VARIABLE GIT_DIFF_OUTPUT
+  )
+  set(REPO_HASH ${REPO_VER})
+
+  if(NOT "${GIT_DIFF_OUTPUT}" STREQUAL "")
+    set(REPO_VER "${REPO_VER}-dirty")
+  endif()
+
+  string(REGEX REPLACE "(.*)-dirty" "dirty" REPO_STATE ${REPO_VER})
+else()
+  set(REPO_VER "")
+  set(REPO_HASH "unknown")
+  set(REPO_STATE "")
+endif()
+
+configure_file(
+  "${CMAKE_CURRENT_SOURCE_DIR}/core/autover.h.in"
+  "${CMAKE_CURRENT_SOURCE_DIR}/core/autover.h"
+)
+
+# -----------------------
+
+add_subdirectory(core)
+add_subdirectory(lib)
+add_subdirectory(modules)
+
+# -----------------------
+
+# We also set the GENERATED property to 1 because before CMake 3.20,
+# the GENERATED property was not set for files generated in other
+# CMakeLists.txt files.
+if(CMAKE_VERSION VERSION_LESS 3.20)
+  set_property(
+    SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/core/lex.yy.c PROPERTY GENERATED 1
+  )
+  set_property(
+    SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/core/cfg.tab.c PROPERTY GENERATED 1
+  )
+endif()
+
+add_executable(kamailio ${CMAKE_CURRENT_SOURCE_DIR}/main.c ${kamailio_SRC})
+target_link_libraries(
+  kamailio
+  PUBLIC
+    common
+    m
+    Threads::Threads # Pthread library
+    # Use of ${CMAKE_DL_LIBS}
+    # https://stackoverflow.com/questions/73263834/cmake-how-to-set-rpath-in-a-shared-library-with-only-target-link-directories-w
+    ${CMAKE_DL_LIBS} # dl -- dlopen and more
+    resolv # resolv
+)
+# Make sure the cfg.tab.c and lex.yy.c are generated before building kamailio
+add_dependencies(kamailio GenerateParser)
+
+# Enable ENABLE_EXPORTS property so modules can link from symbols found in
+# main.c and core/*.
+set_target_properties(kamailio PROPERTIES ENABLE_EXPORTS TRUE)
+
+# Add the MODS_DIR definition required by main.c ---
+target_compile_definitions(
+  kamailio PUBLIC MODS_DIR="${CMAKE_INSTALL_FULL_LIBDIR}/${MAIN_NAME}/modules"
+)
+
+# Add the install targets Specify the directory on disk to which a file will be
+# installed. <dir> should be a relative path. An absolute path is allowed, but
+# not recommended. When a relative path is given it is interpreted relative to
+# the value of the CMAKE_INSTALL_PREFIX variable.
+install(
+  TARGETS kamailio
+  DESTINATION ${CMAKE_INSTALL_SBINDIR}
+  COMPONENT kamailio-core
+)
+
+# Install the configuration file (kamailio.cfg) using a CODE block to check
+# existence at install time instead of configure time
+# If(EXISTS ..) require full path
+install(
+  CODE "
+    if(EXISTS \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/${MAIN_NAME}/kamailio.cfg\")
+        message(STATUS \"kamailio.cfg already exists in  \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/${MAIN_NAME}/kamailio.cfg. Installing as kamailio.cfg.sample\")
+      file(INSTALL \"${CMAKE_SOURCE_DIR}/etc/kamailio.cfg\"
+        DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/${MAIN_NAME}\"
+        RENAME \"kamailio.cfg.sample\"
+        PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+      )
+    else()
+        file(INSTALL \"${CMAKE_SOURCE_DIR}/etc/kamailio.cfg\"
+          DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/${MAIN_NAME}\"
+          PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+        )
+    endif()
+
+"
+  COMPONENT kamailio-cfg
+)

+ 57 - 0
src/core/CMakeLists.txt

@@ -0,0 +1,57 @@
+cmake_minimum_required(VERSION 3.10)
+
+# This is just for Debugging and print the compile definitions and options
+# for the common target
+get_target_property(
+  MY_INTERFACE_DEFINITIONS common INTERFACE_COMPILE_DEFINITIONS
+)
+message(STATUS "Compile definitions for common: ${MY_INTERFACE_DEFINITIONS}")
+
+get_target_property(MY_INTERFACE_OPTIONS common INTERFACE_COMPILE_OPTIONS)
+message(STATUS "Compile options for common: ${MY_INTERFACE_OPTIONS}")
+
+# -----------------------
+# The following produces core/lex.yy.c and core/cfg.tab.c and core/cfg.tab.h
+# files
+
+# Find Flex
+find_package(FLEX REQUIRED)
+
+# Find Bison
+find_package(BISON REQUIRED)
+
+# Generate lex.yy.c from cfg.lex
+add_custom_command(
+  OUTPUT ${CMAKE_SOURCE_DIR}/src/core/lex.yy.c
+  COMMAND ${FLEX_EXECUTABLE} -o ${CMAKE_CURRENT_SOURCE_DIR}/lex.yy.c
+          ${CMAKE_CURRENT_SOURCE_DIR}/cfg.lex
+  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cfg.lex
+          ${CMAKE_CURRENT_SOURCE_DIR}/cfg.tab.h
+  COMMENT "Generating lex.yy.c from cfg.lex"
+)
+
+# Generate cfg.tab.c and cfg.tab.h from cfg.y
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/cfg.tab.c
+         ${CMAKE_CURRENT_SOURCE_DIR}/cfg.tab.h
+  COMMAND ${BISON_EXECUTABLE} -d -b cfg -o ${CMAKE_CURRENT_SOURCE_DIR}/cfg.tab.c
+          ${CMAKE_CURRENT_SOURCE_DIR}/cfg.y
+  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cfg.y
+  COMMENT "Generating cfg.tab.c and cfg.tab.h from cfg.y"
+)
+
+# Add library target to ensure the above commands run
+add_library(
+  GenerateParser ${CMAKE_CURRENT_SOURCE_DIR}/lex.yy.c
+                 ${CMAKE_CURRENT_SOURCE_DIR}/cfg.tab.c
+)
+target_link_libraries(GenerateParser PUBLIC common)
+
+# -----------------------
+
+file(GLOB_RECURSE kamailio_SRC "*.c")
+set(kamailio_SRC
+    ${kamailio_SRC}
+    PARENT_SCOPE
+)
+# message(STATUS "kamailio_SRC: ${kamailio_SRC}")

+ 6 - 0
src/core/autover.h.in

@@ -0,0 +1,6 @@
+/* this file is autogenerated by CMake */
+/* DO NOT EDIT IT */
+
+#define REPO_VER "@REPO_VER@"
+#define REPO_HASH "@REPO_HASH@"
+#define REPO_STATE "@REPO_STATE@"

+ 2 - 2
src/core/forward.h

@@ -129,6 +129,7 @@ static inline int msg_send_buffer(
 	str outb;
 	sr_net_info_t netinfo;
 	sr_event_param_t evp = {0};
+	int ret;
 
 #ifdef USE_TCP
 	int port;
@@ -138,7 +139,6 @@ static inline int msg_send_buffer(
 	struct tcp_connection *con = NULL;
 	struct ws_event_info wsev;
 	int dproto;
-	int ret;
 #endif
 
 	outb.s = buf;
@@ -184,7 +184,7 @@ static inline int msg_send_buffer(
 			} else
 				su_setport(&local_addr, 0); /* any local port will do */
 #else
-			su_setport(&local_addr, 0);		/* any local port will do */
+			su_setport(&local_addr, 0); /* any local port will do */
 #endif
 			from = &local_addr;
 		}

+ 8 - 0
src/core/resolve.c

@@ -1859,11 +1859,15 @@ ip_addr_t *str2ip(str *st)
 */
 struct hostent *__resolvehost(char *name)
 {
+#ifdef USE_DNS_CACHE
 	if(dns_cache_init) {
 		return dns_resolvehost(name);
 	} else {
+#endif
 		return _resolvehost(name);
+#ifdef USE_DNS_CACHE
 	}
+#endif
 }
 
 /*
@@ -1880,11 +1884,15 @@ struct hostent *__resolvehost(char *name)
 */
 struct hostent *__sip_resolvehost(str *name, unsigned short *port, char *proto)
 {
+#ifdef USE_DNS_CACHE
 	if(dns_cache_init) {
 		return dns_sip_resolvehost(name, port, proto);
 	} else {
+#endif
 		return _sip_resolvehost(name, port, proto);
+#ifdef USE_DNS_CACHE
 	}
+#endif
 }
 /* converts a str to an ipv6 address struct stored in ipb
  * - ipb must be already allocated

+ 30 - 0
src/lib/CMakeLists.txt

@@ -0,0 +1,30 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(kamailio_libs)
+
+set(LIBS_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+
+# Each library is built as a separate target. The libraries are in the
+# subdirectories of this folder and each subdirectory contains a CMakeLists.txt
+# file that defines the library target.
+
+file(
+  GLOB children
+  RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+  LIST_DIRECTORIES true
+  *
+)
+
+foreach(child ${children})
+  if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${child}
+     AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${child}/CMakeLists.txt
+  )
+    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${child})
+
+    install(
+      TARGETS lib_${child}
+      DESTINATION ${CMAKE_INSTALL_LIBDIR}/${MAIN_NAME}
+      COMPONENT kamailio_libs
+    )
+  endif()
+endforeach()

+ 22 - 0
src/lib/ims/CMakeLists.txt

@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(kamailio_lib_ims VERSION 0.1.0)
+
+find_package(LibXml2 REQUIRED)
+file(GLOB SRC_FILES "*.c")
+
+# Original target to be named as folder, so when included from lib/CMakeLists.txt
+# it will be named as lib/ims.so
+add_library(lib_ims SHARED ${SRC_FILES})
+target_link_libraries(lib_ims common kamailio)
+
+# TODO: do we need version control?
+set_target_properties(
+  lib_ims PROPERTIES VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
+                     OUTPUT_NAME ims
+)
+set_target_properties(lib_ims PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})
+
+# Target alias for linking
+# TODO: Check how is handled in makefiles
+add_library(kamailio_ims ALIAS lib_ims)

+ 18 - 0
src/lib/print/CMakeLists.txt

@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(kamailio_lib_print VERSION 1.2.1)
+
+file(GLOB SRC_FILES "*.c")
+
+# Original target to be named as folder, so when included from lib/CMakeLists.txt
+# it will be named as lib/ims.so
+add_library(lib_print SHARED ${SRC_FILES})
+
+target_link_libraries(lib_print common kamailio)
+
+# TODO: do we need version control?
+set_target_properties(
+  lib_print PROPERTIES VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
+                       OUTPUT_NAME print
+)
+set_target_properties(lib_print PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})

+ 17 - 0
src/lib/srdb1/CMakeLists.txt

@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(kamailio_lib_srdb1 VERSION 1.0.0)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(lib_srdb1 SHARED ${SRC_FILES})
+target_link_libraries(lib_srdb1 common kamailio)
+
+# TODO: do we need version control?
+set_target_properties(
+  lib_srdb1 PROPERTIES VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
+                       OUTPUT_NAME srdb1
+)
+set_target_properties(lib_srdb1 PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})
+
+add_library(srdb1 ALIAS lib_srdb1)

+ 15 - 0
src/lib/srdb2/CMakeLists.txt

@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(kamailio_lib_srdb2 VERSION 1.0.0)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(lib_srdb2 SHARED ${SRC_FILES})
+target_link_libraries(lib_srdb2 common kamailio)
+
+set_target_properties(
+  lib_srdb2 PROPERTIES VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
+                       OUTPUT_NAME srdb2
+)
+set_target_properties(lib_srdb2 PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})
+add_library(srdb2 ALIAS lib_srdb2)

+ 16 - 0
src/lib/trie/CMakeLists.txt

@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(kamailio_lib_trie VERSION 1.0.0)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(lib_trie SHARED ${SRC_FILES})
+target_link_libraries(lib_trie common kamailio)
+
+# TODO: do we need version control?
+set_target_properties(
+  lib_trie PROPERTIES VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
+                      OUTPUT_NAME trie
+)
+set_target_properties(lib_trie PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})
+add_library(trie ALIAS lib_trie)

+ 143 - 0
src/modules/CMakeLists.txt

@@ -0,0 +1,143 @@
+# Modules
+set(MODULES_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+
+# Initialize a global property to track added modules
+set_property(GLOBAL PROPERTY ADDED_MODULES_LIST "")
+set_property(GLOBAL PROPERTY ALL_MODULE_DOC_TARGETS "")
+
+include(${CMAKE_SOURCE_DIR}/cmake/groups.cmake)
+
+# TODO: Add proper search for all or find better way
+# TODO: Allow the selection of a group of modules defined in groups.cmake
+set(MODULE_GROUP_NAMES ${AVAILABLE_GROUPS})
+set(MODULE_GROUP_NAME
+    "DEFAULT"
+    CACHE STRING "Group of modules to build (all, or a custom group)"
+)
+
+# Check if the specified group exists
+list(FIND AVAILABLE_GROUPS "${MODULE_GROUP_NAME}" GROUP_INDEX)
+if(GROUP_INDEX EQUAL -1)
+  message(
+    FATAL_ERROR
+      "Invalid module group specified: ${MODULE_GROUP_NAME}. Available groups: ${AVAILABLE_GROUPS}"
+  )
+endif()
+
+if(MODULE_GROUP_NAME STREQUAL "ALL")
+  list(SORT MODULE_GROUP_ALL)
+  set(MODULE_GROUP ${MODULE_GROUP_ALL})
+elseif(MODULE_GROUP_NAME STREQUAL "DEFAULT")
+  list(SORT MODULE_GROUP_DEFAULT)
+  set(MODULE_GROUP ${MODULE_GROUP_DEFAULT})
+endif()
+
+# list(SORT MODULE_GROUP_DEFAULT)
+# message(STATUS "MODULE_GROUP_DEFAULT: ${MODULE_GROUP_DEFAULT}")
+
+# Allow users to specify extra modules to build
+set(INCLUDE_MODULES
+    ""
+    CACHE STRING "List of extra modules to build (space-separated)"
+)
+
+set(EXCLUDE_MODULES
+    ""
+    CACHE STRING "List of modules to exclude from building (space-separated)"
+)
+
+include(${CMAKE_SOURCE_DIR}/cmake/modules_docs.cmake)
+
+# Function to add modules from a list
+function(add_module_group GROUP_MODULES)
+  foreach(MODULE_NAME IN LISTS GROUP_MODULES)
+    # Check if the module has already been added
+    get_property(ALREADY_ADDED GLOBAL PROPERTY ADDED_MODULES_LIST)
+    if(";${ALREADY_ADDED};" MATCHES ";${MODULE_NAME};")
+      message(
+        STATUS "Module ${MODULE_NAME} has already been added. Skipping..."
+      )
+    else()
+      # Construct the path to the module
+      set(MODULE_PATH "${MODULES_DIR}/${MODULE_NAME}")
+      # message(STATUS "Adding module: ${MODULE_NAME} (${MODULE_PATH})")
+      # Check if the directory exists before adding
+      if(IS_DIRECTORY ${MODULE_PATH} AND EXISTS ${MODULE_PATH}/CMakeLists.txt)
+        add_subdirectory(${MODULE_PATH})
+        # Remove the 'lib' prefix from the module name
+        set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
+
+        # Add this policy to new so we can use target_link_libraries(... PRIVATE ...)
+        # to link against targets defined in children directories
+        if(POLICY CMP0079)
+          cmake_policy(SET CMP0079 NEW)
+        endif()
+        target_link_libraries(${MODULE_NAME} PRIVATE common_modules)
+        target_compile_definitions(
+          ${MODULE_NAME} PRIVATE MOD_NAMEID=${MODULE_NAME}
+                                 MOD_NAME=\"${MODULE_NAME}\"
+        )
+        set_target_properties(
+          ${MODULE_NAME}
+          PROPERTIES
+            INSTALL_RPATH
+            "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${MAIN_NAME}"
+        )
+        # Install the module to the appropriate directory under the installation
+        # prefix
+        install(
+          TARGETS ${MODULE_NAME}
+          DESTINATION ${CMAKE_INSTALL_LIBDIR}/${MAIN_NAME}/modules
+          COMPONENT kamailio_modules
+        )
+        # Add the module to the list of added modules
+        set_property(GLOBAL APPEND PROPERTY ADDED_MODULES_LIST ${MODULE_NAME})
+        docs_add_module(${MODULE_NAME})
+        set_property(
+          GLOBAL APPEND PROPERTY ALL_MODULE_DOC_TARGETS ${MODULE_NAME}_doc
+        )
+      else()
+        message(WARNING "Module directory ${MODULE_PATH} does not exist.")
+      endif()
+    endif()
+  endforeach()
+endfunction()
+
+list(APPEND FINAL_MODULES_LIST ${MODULE_GROUP})
+
+# Parse and add extra modules specified by the user
+separate_arguments(INCLUDE_MODULES_LIST UNIX_COMMAND "${INCLUDE_MODULES}")
+message(STATUS "Extra modules: ${INCLUDE_MODULES_LIST}")
+list(APPEND FINAL_MODULES_LIST ${INCLUDE_MODULES_LIST})
+
+# Exclude modules that were explicitly excluded by the user
+separate_arguments(EXCLUDE_MODULES_LIST UNIX_COMMAND "${EXCLUDE_MODULES}")
+message(STATUS "Excluded modules: ${EXCLUDE_MODULES_LIST}")
+foreach(MODULE_NAME IN LISTS EXCLUDE_MODULES_LIST)
+  # if in list remove it and print a message
+  if(";${FINAL_MODULES_LIST};" MATCHES ";${MODULE_NAME};")
+    list(REMOVE_ITEM FINAL_MODULES_LIST ${MODULE_NAME})
+    message(STATUS "Removed module: ${MODULE_NAME}")
+  endif()
+endforeach()
+
+# Add each group of modules
+add_module_group("${FINAL_MODULES_LIST}")
+
+# Add a kamailio_docs target that depends on all module documentation targets
+get_property(ALL_MODULE_DOC_TARGETS GLOBAL PROPERTY ALL_MODULE_DOC_TARGETS)
+# message(STATUS "ALL_MODULE_DOC_TARGETS: ${ALL_MODULE_DOC_TARGETS}")
+
+add_custom_target(
+  kamailio_docs
+  DEPENDS ${ALL_MODULE_DOC_TARGETS}
+  COMMENT "Generating Kamailio documentation"
+)
+# add_dependencies(kamailio-docs kamailio_docs)
+
+add_custom_target(
+  install_kamailio_docs
+  COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --component
+          kamailio_docs
+  DEPENDS kamailio_docs
+)

+ 10 - 0
src/modules/acc/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(acc)
+
+file(GLOB acc_SRC "*.c")
+
+add_library(acc SHARED ${acc_SRC})
+target_link_libraries(acc PRIVATE kamailio)
+
+target_link_libraries(acc PRIVATE srdb1)

+ 8 - 0
src/modules/acc_diameter/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(acc_diameter)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(acc_diameter SHARED ${SRC_FILES})
+target_link_libraries(acc_diameter PRIVATE kamailio)

+ 12 - 0
src/modules/acc_json/CMakeLists.txt

@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(acc_json)
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(JANSSON REQUIRED IMPORTED_TARGET jansson)
+add_library(jansson::jansson ALIAS PkgConfig::JANSSON)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(acc_json SHARED ${SRC_FILES})
+target_link_libraries(acc_json PRIVATE kamailio jansson::jansson)

+ 11 - 0
src/modules/acc_radius/CMakeLists.txt

@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(acc_radius)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(Radius REQUIRED)
+
+add_library(acc_radius SHARED ${SRC_FILES})
+target_compile_definitions(acc_radius PRIVATE ${RADIUSCLIENT_LIB})
+target_link_libraries(acc_radius PRIVATE kamailio)

+ 10 - 0
src/modules/alias_db/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(alias_db)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(alias_db SHARED ${SRC_FILES})
+target_link_libraries(alias_db PRIVATE kamailio)
+
+target_link_libraries(alias_db PRIVATE srdb1)

+ 14 - 0
src/modules/app_java/CMakeLists.txt

@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(app_java)
+
+file(GLOB SRC_FILES "*.c")
+
+# TODO: GCJ is a discontiuned project from 2018
+# sudo apt install openjdk-13-jdk compiles with warnings
+find_package(JNI REQUIRED)
+
+add_library(app_java SHARED ${SRC_FILES})
+target_compile_options(app_java PRIVATE -O0 -g)
+target_include_directories(app_java PRIVATE JNI_INCLUDE_DIRS)
+target_link_libraries(app_java PRIVATE kamailio JNI::JNI)

+ 8 - 0
src/modules/app_jsdt/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(app_jsdt)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(app_jsdt SHARED ${SRC_FILES})
+target_link_libraries(app_jsdt PRIVATE kamailio)

+ 22 - 0
src/modules/app_lua/CMakeLists.txt

@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(app_lua)
+
+file(GLOB SRC_FILES "*.c")
+
+option(LUAJIT "Enable LuaJIT (for app_lua modules)" OFF)
+
+if(LUAJIT)
+  find_package(PkgConfig REQUIRED)
+  pkg_check_modules(LUA REQUIRED IMPORTED_TARGET luajit)
+else()
+  find_package(Lua REQUIRED)
+  # CMake FindLua defines include as LUA_INCLUDE_DIR and lib as LUA_LIBRARIES
+  set(LUA_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
+endif()
+
+add_library(app_lua SHARED ${SRC_FILES})
+# the LUA_COMPAT_MODULE fixes this error: implicit declaration of function ‘luaL_openlib
+target_compile_definitions(app_lua PRIVATE LUA_COMPAT_MODULE)
+target_include_directories(app_lua PRIVATE ${LUA_INCLUDE_DIRS})
+target_link_libraries(app_lua PRIVATE kamailio ${LUA_LIBRARIES})

+ 14 - 0
src/modules/app_perl/CMakeLists.txt

@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(app_perl)
+
+file(GLOB SRC_FILES "*.c")
+
+# libperl-dev
+find_package(PerlLibs REQUIRED)
+
+add_library(app_perl SHARED ${SRC_FILES})
+target_include_directories(app_perl PRIVATE ${PERL_INCLUDE_PATH})
+# message(STATUS "PERL_EXTRA_C_FLAGS: ${PERL_EXTRA_C_FLAGS}")
+target_compile_definitions(app_perl PRIVATE ${PERL_EXTRA_C_FLAGS})
+target_link_libraries(app_perl PRIVATE kamailio ${PERL_LIBRARY})

+ 11 - 0
src/modules/app_python/CMakeLists.txt

@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(app_python)
+
+file(GLOB SRC_FILES "*.c")
+
+# python2-dev package is required for Python2::Module target
+find_package(Python2 REQUIRED COMPONENTS Development)
+
+add_library(app_python SHARED ${SRC_FILES})
+target_link_libraries(app_python PRIVATE kamailio Python2::Module)

+ 10 - 0
src/modules/app_python3/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(app_python3)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(Python3 REQUIRED COMPONENTS Development)
+
+add_library(app_python3 SHARED ${SRC_FILES})
+target_link_libraries(app_python3 PRIVATE kamailio Python3::Python)

+ 10 - 0
src/modules/app_python3s/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(app_python3s)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(Python3 REQUIRED COMPONENTS Development)
+
+add_library(app_python3s STATIC ${SRC_FILES})
+target_link_libraries(app_python3s PRIVATE kamailio Python3::Module)

+ 10 - 0
src/modules/app_ruby/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(app_ruby)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(Ruby REQUIRED)
+
+add_library(app_ruby SHARED ${SRC_FILES})
+target_link_libraries(app_ruby PRIVATE kamailio)

+ 12 - 0
src/modules/app_ruby_proc/CMakeLists.txt

@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(app_ruby_proc)
+
+file(GLOB SRC_FILES "*.c")
+
+# ruby-dev package
+find_package(Ruby REQUIRED)
+add_library(app_ruby_proc SHARED ${SRC_FILES})
+
+target_include_directories(app_ruby_proc PRIVATE ${Ruby_INCLUDE_DIRS})
+target_link_libraries(app_ruby_proc PRIVATE kamailio ${Ruby_LIBRARIES})

+ 8 - 0
src/modules/async/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(async)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(async SHARED ${SRC_FILES})
+target_link_libraries(async PRIVATE kamailio)

+ 9 - 0
src/modules/auth/CMakeLists.txt

@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(auth)
+
+file(GLOB auth_SRC "*.c")
+
+add_library(auth SHARED ${auth_SRC})
+target_link_libraries(auth PRIVATE kamailio)
+target_compile_definitions(auth PRIVATE USE_NC USE_OT_NONCE)

+ 10 - 0
src/modules/auth_db/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(auth_db)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(auth_db SHARED ${SRC_FILES})
+target_link_libraries(auth_db PRIVATE kamailio)
+
+target_link_libraries(auth_db PRIVATE srdb1)

+ 8 - 0
src/modules/auth_diameter/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(auth_diameter)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(auth_diameter SHARED ${SRC_FILES})
+target_link_libraries(auth_diameter PRIVATE kamailio)

+ 8 - 0
src/modules/auth_ephemeral/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(auth_ephemeral)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(auth_ephemeral SHARED ${SRC_FILES})
+target_link_libraries(auth_ephemeral PRIVATE kamailio)

+ 11 - 0
src/modules/auth_radius/CMakeLists.txt

@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(auth_radius)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(Radius REQUIRED)
+
+add_library(auth_radius SHARED ${SRC_FILES})
+target_compile_definitions(auth_radius PRIVATE ${RADIUSCLIENT_LIB})
+target_link_libraries(auth_radius PRIVATE kamailio)

+ 8 - 0
src/modules/auth_xkeys/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(auth_xkeys)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(auth_xkeys SHARED ${SRC_FILES})
+target_link_libraries(auth_xkeys PRIVATE kamailio)

+ 8 - 0
src/modules/avp/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(avp)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(avp SHARED ${SRC_FILES})
+target_link_libraries(avp PRIVATE kamailio)

+ 10 - 0
src/modules/avpops/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(avpops)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(avpops SHARED ${SRC_FILES})
+
+target_link_libraries(avpops PRIVATE kamailio)
+target_link_libraries(avpops PRIVATE srdb1)

+ 8 - 0
src/modules/benchmark/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(benchmark)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(benchmark SHARED ${SRC_FILES})
+target_link_libraries(benchmark PRIVATE kamailio)

+ 8 - 0
src/modules/blst/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(blst)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(blst SHARED ${SRC_FILES})
+target_link_libraries(blst PRIVATE kamailio)

+ 8 - 0
src/modules/call_control/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(call_control)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(call_control SHARED ${SRC_FILES})
+target_link_libraries(call_control PRIVATE kamailio)

+ 8 - 0
src/modules/call_obj/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(call_obj)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(call_obj SHARED ${SRC_FILES})
+target_link_libraries(call_obj PRIVATE kamailio)

+ 10 - 0
src/modules/carrierroute/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(carrierroute)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(carrierroute SHARED ${SRC_FILES})
+
+target_link_libraries(carrierroute PRIVATE kamailio)
+target_link_libraries(carrierroute PRIVATE srdb1 trie)

+ 10 - 0
src/modules/cdp/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(cdp)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(LibXml2 REQUIRED)
+
+add_library(cdp SHARED ${SRC_FILES})
+target_link_libraries(cdp PRIVATE kamailio LibXml2::LibXml2)

+ 8 - 0
src/modules/cdp_avp/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(cdp_avp)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(cdp_avp SHARED ${SRC_FILES})
+target_link_libraries(cdp_avp PRIVATE kamailio)

+ 10 - 0
src/modules/cfg_db/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(cfg_db)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(cfg_db SHARED ${SRC_FILES})
+
+target_link_libraries(cfg_db PRIVATE kamailio)
+target_link_libraries(cfg_db PRIVATE srdb2)

+ 10 - 0
src/modules/cfg_rpc/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(cfg_rpc)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(cfg_rpc SHARED ${SRC_FILES})
+target_link_libraries(cfg_rpc PRIVATE kamailio)
+
+# TODO: Also install kamcmd binary

+ 8 - 0
src/modules/cfgt/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(cfgt)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(cfgt SHARED ${SRC_FILES})
+target_link_libraries(cfgt PRIVATE kamailio)

+ 8 - 0
src/modules/cfgutils/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(cfgutils)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(cfgutils SHARED ${SRC_FILES})
+target_link_libraries(cfgutils PRIVATE kamailio)

+ 18 - 0
src/modules/cnxcc/CMakeLists.txt

@@ -0,0 +1,18 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(cnxcc)
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(redis REQUIRED IMPORTED_TARGET hiredis)
+add_library(redis::redis ALIAS PkgConfig::redis)
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(EVENT REQUIRED IMPORTED_TARGET libevent)
+add_library(event::event ALIAS PkgConfig::EVENT)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(cnxcc SHARED ${SRC_FILES})
+target_link_libraries(cnxcc PRIVATE kamailio redis::redis event::event)
+
+target_link_libraries(cnxcc PRIVATE srdb1)

+ 8 - 0
src/modules/corex/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(corex)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(corex SHARED ${SRC_FILES})
+target_link_libraries(corex PRIVATE kamailio)

+ 10 - 0
src/modules/counters/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(counters)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(counters SHARED ${SRC_FILES})
+target_link_libraries(counters PRIVATE kamailio)
+
+# TODO: Also install kamcmd binary

+ 12 - 0
src/modules/cplc/CMakeLists.txt

@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(cplc)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(LibXml2 REQUIRED)
+
+add_library(cplc SHARED ${SRC_FILES})
+target_link_libraries(cplc PRIVATE kamailio LibXml2::LibXml2)
+
+target_link_libraries(cplc PRIVATE srdb1)

+ 10 - 0
src/modules/crypto/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(crypto)
+
+find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(crypto SHARED ${SRC_FILES})
+target_link_libraries(crypto PRIVATE kamailio OpenSSL::SSL OpenSSL::Crypto)

+ 12 - 0
src/modules/ctl/CMakeLists.txt

@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(ctl)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(ctl SHARED ${SRC_FILES})
+# TODO: Should this be picked by user defined or hardcoded?
+target_compile_definitions(ctl PRIVATE USE_FIFO CTL_SYSTEM_MALLOC)
+target_link_libraries(ctl PRIVATE kamailio)
+
+# TODO: Also install kamcmd binary

+ 22 - 0
src/modules/db2_ldap/CMakeLists.txt

@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db2_ldap)
+
+#  libsasl2-dev is required for LDAP support
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(libsasl2 REQUIRED IMPORTED_TARGET libsasl2)
+add_library(libsasl2::libsasl2 ALIAS PkgConfig::libsasl2)
+
+#  libldap-2.4-2 is required for LDAP support
+find_package(Ldap REQUIRED)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db2_ldap SHARED ${SRC_FILES})
+# LDAP_DEPRECATED is required for LDAP support else it will throw compile error
+target_compile_definitions(db2_ldap PRIVATE LDAP_DEPRECATED)
+target_include_directories(db2_ldap PRIVATE ${Ldap_INCLUDE_DIRS})
+target_link_libraries(
+  db2_ldap PRIVATE kamailio ${LDAP_LIBRARIES} libsasl2::libsasl2
+)
+target_link_libraries(db2_ldap PRIVATE srdb2)

+ 10 - 0
src/modules/db2_ops/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db2_ops)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db2_ops SHARED ${SRC_FILES})
+
+target_link_libraries(db2_ops PRIVATE kamailio)
+target_link_libraries(db2_ops PRIVATE srdb2)

+ 12 - 0
src/modules/db_berkeley/CMakeLists.txt

@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_berkeley)
+
+# libdb++-dev
+find_package(BerkeleyDB REQUIRED)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db_berkeley SHARED ${SRC_FILES})
+target_link_libraries(db_berkeley PRIVATE kamailio BerkeleyDB::BerkeleyDB)
+target_link_libraries(db_berkeley PRIVATE srdb1)

+ 10 - 0
src/modules/db_cluster/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_cluster)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db_cluster SHARED ${SRC_FILES})
+
+target_link_libraries(db_cluster PRIVATE kamailio)
+target_link_libraries(db_cluster PRIVATE srdb1)

+ 10 - 0
src/modules/db_flatstore/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_flatstore)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db_flatstore SHARED ${SRC_FILES})
+
+target_link_libraries(db_flatstore PRIVATE kamailio)
+target_link_libraries(db_flatstore PRIVATE srdb1 srdb2)

+ 17 - 0
src/modules/db_mongodb/CMakeLists.txt

@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_mongodb)
+
+# libmongoc-1.0 is required for this module
+# Missing dependency on Ubuntu 20.04 of libzstd-dev
+# find_package(zstd REQUIRED)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(mongoc REQUIRED IMPORTED_TARGET libmongoc-1.0>=1.7)
+add_library(mongoc::mongoc ALIAS PkgConfig::mongoc)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db_mongodb SHARED ${SRC_FILES})
+
+target_link_libraries(db_mongodb PRIVATE kamailio mongoc::mongoc)
+target_link_libraries(db_mongodb PRIVATE srdb1)

+ 19 - 0
src/modules/db_mysql/CMakeLists.txt

@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_mysql)
+
+find_package(MariaDBClient REQUIRED)
+
+if(NOT MariaDBClient_FOUND)
+  message(FATAL_ERROR "MySQL or MariaDBClient not found")
+  message(FATAL_ERROR "Please install the dev libraries")
+endif()
+
+file(GLOB mySQL_SRC "*.c")
+
+add_library(db_mysql SHARED ${mySQL_SRC})
+
+target_include_directories(db_mysql PRIVATE ${MariaDBClient_INCLUDE_DIRS})
+target_link_libraries(db_mysql PRIVATE kamailio ${MariaDBClient_LIBRARIES})
+
+# TODO Install script files for kamctl

+ 16 - 0
src/modules/db_oracle/CMakeLists.txt

@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_oracle)
+
+# TODO: Needs some testing for OS that support OracleDB
+find_package(Oracle REQUIRED)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db_oracle SHARED ${SRC_FILES})
+target_include_directories(db_oracle PRIVATE ${Oracle_INCLUDE_DIRS}
+)# /usr/include/oracle/18.3/client64)
+target_link_libraries(db_oracle PRIVATE occi clntsh)
+
+target_link_libraries(db_oracle PRIVATE kamailio)
+target_link_libraries(db_oracle PRIVATE srdb1)

+ 13 - 0
src/modules/db_perlvdb/CMakeLists.txt

@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_perlvdb)
+
+find_package(PerlLibs REQUIRED)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db_perlvdb SHARED ${SRC_FILES})
+target_include_directories(db_perlvdb PRIVATE ${PERL_INCLUDE_PATH})
+target_compile_definitions(db_perlvdb PRIVATE ${PERL_EXTRA_C_FLAGS})
+target_link_libraries(db_perlvdb PRIVATE kamailio ${PERL_LIBRARY})
+target_link_libraries(db_perlvdb PRIVATE srdb1)

+ 14 - 0
src/modules/db_postgres/CMakeLists.txt

@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_postgres)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(PostgreSQL REQUIRED)
+
+add_library(db_postgres SHARED ${SRC_FILES})
+
+target_compile_definitions(db_postgres PRIVATE ${PostgreSQL_DEFINITIONS})
+target_include_directories(db_postgres PRIVATE ${PostgreSQL_INCLUDE_DIRS})
+target_link_libraries(db_postgres PRIVATE kamailio ${PostgreSQL_LIBRARIES})
+target_link_libraries(db_postgres PRIVATE srdb1)

+ 16 - 0
src/modules/db_redis/CMakeLists.txt

@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_redis)
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(redis REQUIRED IMPORTED_TARGET hiredis)
+add_library(redis::redis ALIAS PkgConfig::redis)
+
+file(GLOB SRC_FILES "*.c")
+
+# TODO: Check with Makefile for cluster stuff
+
+add_library(db_redis SHARED ${SRC_FILES})
+
+target_link_libraries(db_redis PRIVATE kamailio redis::redis)
+target_link_libraries(db_redis PRIVATE srdb1 srdb2)

+ 12 - 0
src/modules/db_sqlite/CMakeLists.txt

@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_sqlite)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(SQLite3 REQUIRED)
+
+add_library(db_sqlite SHARED ${SRC_FILES})
+target_link_libraries(db_sqlite PRIVATE kamailio SQLite::SQLite3)
+
+target_link_libraries(db_sqlite PRIVATE srdb1)

+ 10 - 0
src/modules/db_text/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_text)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db_text SHARED ${SRC_FILES})
+target_link_libraries(db_text PRIVATE kamailio)
+
+target_link_libraries(db_text PRIVATE srdb1)

+ 13 - 0
src/modules/db_unixodbc/CMakeLists.txt

@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(db_unixodbc)
+
+find_package(ODBC REQUIRED)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(db_unixodbc SHARED ${SRC_FILES})
+target_include_directories(db_unixodbc PRIVATE ${ODBC_INCLUDE_DIRS})
+target_link_libraries(db_unixodbc PRIVATE kamailio ${ODBC_LIBRARIES})
+
+target_link_libraries(db_unixodbc PRIVATE srdb1)

+ 8 - 0
src/modules/debugger/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(debugger)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(debugger SHARED ${SRC_FILES})
+target_link_libraries(debugger PRIVATE kamailio)

+ 10 - 0
src/modules/dialog/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(dialog)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(dialog SHARED ${SRC_FILES})
+
+target_link_libraries(dialog PRIVATE kamailio)
+target_link_libraries(dialog PRIVATE srdb1)

+ 10 - 0
src/modules/dialplan/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(dialplan)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(dialplan SHARED ${SRC_FILES})
+
+target_link_libraries(dialplan PRIVATE kamailio)
+target_link_libraries(dialplan PRIVATE srdb1)

+ 10 - 0
src/modules/dispatcher/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(dispatcher)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(dispatcher SHARED ${SRC_FILES})
+
+target_link_libraries(dispatcher PRIVATE kamailio)
+target_link_libraries(dispatcher PRIVATE srdb1)

+ 8 - 0
src/modules/diversion/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(diversion)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(diversion SHARED ${SRC_FILES})
+target_link_libraries(diversion PRIVATE kamailio)

+ 8 - 0
src/modules/dlgs/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(dlgs)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(dlgs SHARED ${SRC_FILES})
+target_link_libraries(dlgs PRIVATE kamailio)

+ 10 - 0
src/modules/dmq/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(dmq)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(dmq SHARED ${SRC_FILES})
+
+target_link_libraries(dmq PRIVATE kamailio)
+target_link_libraries(dmq PRIVATE srdb1)

+ 8 - 0
src/modules/dmq_usrloc/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(dmq_usrloc)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(dmq_usrloc SHARED ${SRC_FILES})
+target_link_libraries(dmq_usrloc PRIVATE kamailio)

+ 19 - 0
src/modules/dnssec/CMakeLists.txt

@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(dnssec)
+
+file(GLOB SRC_FILES "*.c")
+
+find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto)
+find_package(Threads REQUIRED)
+
+add_library(dnssec SHARED ${SRC_FILES})
+
+# TODO: library libval not foud on recent distributions:
+# whichi library is sres?
+# Consider depreciating this module?
+target_link_libraries(
+  dnssec PRIVATE val-threads sres Threads::Threads OpenSSL::SSL OpenSSL::Crypto
+)
+
+target_link_libraries(dnssec PRIVATE kamailio)

+ 10 - 0
src/modules/domain/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(domain)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(domain SHARED ${SRC_FILES})
+
+target_link_libraries(domain PRIVATE kamailio)
+target_link_libraries(domain PRIVATE srdb1)

+ 10 - 0
src/modules/domainpolicy/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(domainpolicy)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(domainpolicy SHARED ${SRC_FILES})
+
+target_link_libraries(domainpolicy PRIVATE kamailio)
+target_link_libraries(domainpolicy PRIVATE srdb1)

+ 10 - 0
src/modules/drouting/CMakeLists.txt

@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(drouting)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(drouting SHARED ${SRC_FILES})
+
+target_link_libraries(drouting PRIVATE kamailio)
+target_link_libraries(drouting PRIVATE srdb1)

+ 8 - 0
src/modules/enum/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(enum)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(enum SHARED ${SRC_FILES})
+target_link_libraries(enum PRIVATE kamailio)

Некоторые файлы не были показаны из-за большого количества измененных файлов