summaryrefslogtreecommitdiff
path: root/CMake/gen_config.cmake
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2025-05-06 19:10:00 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2025-05-06 19:25:53 +0200
commit53491f2ca0f197a84f15cf10949f13450ce7d021 (patch)
tree9e6f700bbc1e568eed41b74fdea066e5f0705988 /CMake/gen_config.cmake
parent9ba11949ca58537c1f511e0919243ede7b86507d (diff)
Remove hardcoded version numbers: part 1
The goal is to change the version number for a new release only in CMakeLists.txt. This is the first step. Details: - CMake/gen_config.cmake: this new file is included to generate the header files config.h (private, root directory), and FL/fl_config.h (public, can be installed). This file implements also ABI version checks (removed from FL/Enumerations.H and with more checks). Warnings are issued if the chosen ABI version is invalid. - CMake/export.cmake: code to generate 'config.h' was moved to CMake/gen_config.cmake. - CMake/options.cmake: set default of FLTK_BUILD_FORMS=OFF + comments - CMakeLists.txt: move generation of FL/fl_config.h to gen_config.cmake, add API and ABI versions to CMake summary, - FL/Enumerations.H: remove most of the version number details which are now included in FL/fl_config.h. This needed also some doxygen related changes. - README.CMake.txt: improve docs of FL_ABI_VERSION and some more. Reflect the new default of CMake option FLTK_BUILD_FORMS (OFF). - documentation/Doxyfile.in: add FL/fl_config.h to file list. This file is created in the build tree (and may be "installed"). - fl_config.h.in: add version number details that have been moved here from Enumerations.H (used to generate FL/fl_config.h).
Diffstat (limited to 'CMake/gen_config.cmake')
-rw-r--r--CMake/gen_config.cmake109
1 files changed, 109 insertions, 0 deletions
diff --git a/CMake/gen_config.cmake b/CMake/gen_config.cmake
new file mode 100644
index 000000000..719b804d2
--- /dev/null
+++ b/CMake/gen_config.cmake
@@ -0,0 +1,109 @@
+#
+# Generate version numbers and configure header files
+#
+# Copyright 1998-2025 by Bill Spitzak and others.
+#
+# This library is free software. Distribution and use rights are outlined in
+# the file "COPYING" which should have been included with this file. If this
+# file is missing or damaged, see the license at:
+#
+# https://www.fltk.org/COPYING.php
+#
+# Please see the following page on how to report bugs and issues:
+#
+# https://www.fltk.org/bugs.php
+#
+
+#######################################################################
+# Calculate limits and check FL_ABI_VERSION syntax
+#######################################################################
+
+# Initialize FL_ABI_VERSION
+set(FL_ABI_VERSION "${FLTK_ABI_VERSION}")
+
+# These are the limits (min/max) FL_ABI_VERSION is allowed to have
+math(EXPR abi_version_min "${FLTK_VERSION_MAJOR} * 10000 + ${FLTK_VERSION_MINOR} * 100")
+math(EXPR abi_version_max "${abi_version_min} + ${FLTK_VERSION_PATCH} + 1")
+
+if(FL_ABI_VERSION STREQUAL "")
+
+ # no version set, silently use default
+ set(FL_ABI_VERSION "${abi_version_min}")
+
+else()
+
+ # check syntax of reuested ABI version (five digits)
+
+ string(REGEX MATCH "[1-9][0-9][0-9][0-9][0-9]" reg_match "${FL_ABI_VERSION}")
+ if(NOT reg_match STREQUAL "${FL_ABI_VERSION}")
+ message(STATUS "FLTK_ABI_VERSION \"${FLTK_ABI_VERSION}\" is invalid. Using default = ${abi_version_min}")
+ set(FL_ABI_VERSION "${abi_version_min}")
+ endif()
+
+ # check minor version (first three numbers must match)
+
+ string(SUBSTRING "${abi_version_min}" 0 3 abi_version_minor)
+ string(SUBSTRING "${FL_ABI_VERSION}" 0 3 abi_version_temp)
+
+ if(NOT abi_version_temp STREQUAL ${abi_version_minor})
+ set(FL_ABI_VERSION "${abi_version_min}")
+ message(STATUS "FLTK_ABI_VERSION \"${FLTK_ABI_VERSION}\" doesn't match minor version. Using default = ${abi_version_min}")
+ set(FL_ABI_VERSION "${abi_version_min}")
+ endif()
+
+endif()
+
+if(FL_ABI_VERSION STRLESS ${abi_version_min})
+ # should never happen
+ set(FL_ABI_VERSION "${abi_version_min}")
+elseif(FL_ABI_VERSION STRGREATER ${abi_version_max})
+ # accept w/o warning
+ set(FL_ABI_VERSION "${abi_version_max}")
+endif()
+
+# reset all temporary variables
+
+unset(abi_version_min)
+unset(abi_version_max)
+unset(abi_version_minor)
+unset(abi_version_temp)
+unset(reg_match)
+
+#######################################################################
+# configure the header file "FL/fl_config.h" in the build tree
+#######################################################################
+
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/fl_config.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/FL/fl_config.h
+ @ONLY
+)
+
+#######################################################################
+# generate the header file "config.h" in the build tree
+#######################################################################
+
+# prepare some variables for config.h
+
+if(IS_ABSOLUTE "${FLTK_DATADIR}")
+ set(PREFIX_DATA "${FLTK_DATADIR}/fltk")
+else(IS_ABSOLUTE "${FLTK_DATADIR}")
+ set(PREFIX_DATA "${CMAKE_INSTALL_PREFIX}/${FLTK_DATADIR}/fltk")
+endif(IS_ABSOLUTE "${FLTK_DATADIR}")
+
+if(IS_ABSOLUTE "${FLTK_DOCDIR}")
+ set(PREFIX_DOC "${FLTK_DOCDIR}/fltk")
+else(IS_ABSOLUTE "${FLTK_DOCDIR}")
+ set(PREFIX_DOC "${CMAKE_INSTALL_PREFIX}/${FLTK_DOCDIR}/fltk")
+endif(IS_ABSOLUTE "${FLTK_DOCDIR}")
+
+set(CONFIG_H_IN config.h.in)
+set(CONFIG_H config.h)
+
+# generate the header file
+
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/${CONFIG_H_IN}"
+ "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_H}"
+ @ONLY
+)