From fd5cd809356dc73d2ede5bb2f0db25098771cb8e Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Wed, 7 Feb 2024 18:30:11 +0100 Subject: Introduce "Modern CMake" in FLTK This is a big commit and there are too many changes to list them all. The main changes are: - rename all CMake build options to 'FLTK_*' - export library targets with namespace (prefix) 'fltk::' - standardize shared library target names with suffix '-shared' - set public build properties on libraries for consumers - document library names and aliases in README.CMake.txt - document changes in "Migrating Code from FLTK 1.3 to 1.4" - partial backwards compatibility for old user projects Included but not directly related changes: - fix Windows (Visual Studio) DLL build - add CMake function fl_debug_target() to show target properties - don't build test programs if FLTK is a subproject - internal: reformat CMake code: remove space before '(' Thanks to Matthias and Manolo for their help, testing, and feeback. --- CMake/fl_debug_var.cmake | 101 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 16 deletions(-) (limited to 'CMake/fl_debug_var.cmake') diff --git a/CMake/fl_debug_var.cmake b/CMake/fl_debug_var.cmake index 5717704a3..08f91bf1d 100644 --- a/CMake/fl_debug_var.cmake +++ b/CMake/fl_debug_var.cmake @@ -1,7 +1,7 @@ # -# Macro used by the CMake build system for the Fast Light Tool Kit (FLTK). +# Function used by the CMake build system for the Fast Light Tool Kit (FLTK). # -# Copyright 1998-2022 by Bill Spitzak and others. +# Copyright 1998-2024 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 @@ -15,10 +15,42 @@ # ####################################################################### -# fl_debug_var - a macro to output debugging info +# fl_expand_name - a function to expand a variable name with spaces ####################################################################### # -# This macro displays the name and value of a CMake variable. +# This function returns a string comprising of the given name and +# enough spaces to have at least the given minimal length (min_len). +# Currently min_len must not be greater than 50. +# +# If the string is already at least min_len it is not changed, +# otherwise the string is returned to the given variable (out) +# in the parent scope. +# +# Syntax: +# fl_expand_name (out in min_len) +# +# Example: +# fl_expand_name (var WIN32 30) +# fl_expand_name (var UNIX 40) +# +####################################################################### + +function (fl_expand_name out in min_len) + string(LENGTH "${in}" len) + if(len LESS min_len) + set(spaces " ") + set(temp "${in}") + set(temp "${in}${spaces}${spaces}") + string(SUBSTRING "${temp}" 0 ${min_len} temp) + set(${out} "${temp}" PARENT_SCOPE) + endif() +endfunction (fl_expand_name) + +####################################################################### +# fl_debug_var - a function to output debugging info +####################################################################### +# +# This function displays the name and value of a CMake variable. # The variable name is expanded with spaces to be (at least) # (currently 30) characters wide for better readability. # VARNAME must be a string literal, e.g. WIN32 or "WIN32". @@ -32,15 +64,52 @@ # ####################################################################### -macro (fl_debug_var name) - set (min_len 32) - set (var "${name}") - string(LENGTH "${var}" len) - while (len LESS min_len) - # add one space until min_len is reached - # ** string(APPEND var " ") # requires CMake 3.4.x (otherwise loop...) - set (var "${var} ") - string(LENGTH "${var}" len) - endwhile (len LESS min_len) - message (STATUS "${var} = '${${name}}'") -endmacro (fl_debug_var) +function (fl_debug_var name) + set(var "${name}") + fl_expand_name(var "${name}" 40) + message(STATUS "${var} = '${${name}}'") +endfunction (fl_debug_var) + + +####################################################################### +# fl_debug_target - a function to output info about a target +####################################################################### +# +# This function displays properties of a CMake target. +# +# Currently there's a fixed number of properties. +# +# Syntax: +# fl_debug_target(target) +# +# Example: +# fl_debug_target(fltk) +# fl_debug_target(fluid) +# fl_debug_target(fltk_image) +# fl_debug_target(fltk::forms) +# +####################################################################### + +function (fl_debug_target name) + message(STATUS "+++ fl_debug_target (${name})") + set(var "${name}") + fl_expand_name(var "${name}" 40) + if(TARGET ${name}) + message(STATUS "${var} = ") + foreach(prop + ALIASED_TARGET + INTERFACE_INCLUDE_DIRECTORIES + INTERFACE_LINK_DIRECTORIES + INTERFACE_LINK_LIBRARIES) + get_target_property (${prop} ${name} ${prop}) + if(NOT ${prop}) + set(${prop} "") + endif() + fl_debug_var(${prop}) + endforeach() + else() + message(STATUS "${var} = ") + endif() + message(STATUS "") + +endfunction (fl_debug_target) -- cgit v1.2.3