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.
This commit is contained in:
Albrecht Schlosser
2024-02-07 18:30:11 +01:00
parent 1cf6fdfa85
commit fd5cd80935
53 changed files with 3571 additions and 2749 deletions
+69 -68
View File
@@ -14,37 +14,37 @@
# https://www.fltk.org/bugs.php
#
set (DOCS)
set (GENERATE_DOCS FALSE)
set (GIT_REVISION "")
set (YEAR "")
set (CURRENT_DATE "")
set(DOCS)
set(GENERATE_DOCS FALSE)
set(GIT_REVISION "")
set(YEAR "")
set(CURRENT_DATE "")
if (OPTION_BUILD_HTML_DOCUMENTATION OR OPTION_BUILD_PDF_DOCUMENTATION)
set (GENERATE_DOCS TRUE)
endif ()
if(FLTK_BUILD_HTML_DOCS OR FLTK_BUILD_PDF_DOCS)
set(GENERATE_DOCS TRUE)
endif()
if (OPTION_INCLUDE_DRIVER_DOCUMENTATION)
set (DRIVER_DOCS "DriverDev")
else ()
set (DRIVER_DOCS "")
endif ()
if(FLTK_INCLUDE_DRIVER_DOCS)
set(DRIVER_DOCS "DriverDev")
else()
set(DRIVER_DOCS "")
endif()
#------------------------------------------------
# generate files used for both HTML and PDF docs
#------------------------------------------------
if (GENERATE_DOCS)
if(GENERATE_DOCS)
# create required variables
execute_process (COMMAND date "+%Y"
execute_process(COMMAND date "+%Y"
OUTPUT_VARIABLE YEAR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# note: current locale is used for abbreviated month
execute_process (COMMAND date "+%b %d, %Y"
execute_process(COMMAND date "+%b %d, %Y"
OUTPUT_VARIABLE CURRENT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
@@ -56,16 +56,17 @@ if (GENERATE_DOCS)
# In the future tarball/zip generation should create a file
# that contains the git revision.
execute_process (COMMAND
git --git-dir=${FLTK_SOURCE_DIR}/.git rev-parse --short=10 HEAD
execute_process(COMMAND
git rev-parse --short=10 HEAD
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${FLTK_SOURCE_DIR}
ERROR_QUIET
)
# set to "'unkown'" if git is not available
if (GIT_REVISION STREQUAL "")
set (GIT_REVISION "'unkown'")
if(GIT_REVISION STREQUAL "")
set(GIT_REVISION "'unkown'")
endif()
# Find "short" doxygen version if it was built from Git
@@ -75,56 +76,56 @@ if (GENERATE_DOCS)
# code once we require this as our minimal version and replace the
# variable DOXYGEN_VERSION_SHORT with DOXYGEN_VERSION below.
if (DOXYGEN_FOUND)
if(DOXYGEN_FOUND)
# strip trailing git revision if doxygen was built from source
string (REGEX REPLACE " .*$" "" DOXYGEN_VERSION_SHORT ${DOXYGEN_VERSION})
endif (DOXYGEN_FOUND)
string(REGEX REPLACE " .*$" "" DOXYGEN_VERSION_SHORT ${DOXYGEN_VERSION})
endif(DOXYGEN_FOUND)
# configure copyright.dox (includes current year)
configure_file (
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/copyright.dox.in
${CMAKE_CURRENT_BINARY_DIR}/copyright.dox
@ONLY
)
# configure generated.dox (includes date and versions)
configure_file (
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/generated.dox.in
${CMAKE_CURRENT_BINARY_DIR}/generated.dox
@ONLY
)
if (0) # debug
fl_debug_var (YEAR)
fl_debug_var (CURRENT_DATE)
fl_debug_var (GIT_REVISION)
fl_debug_var (DOXYGEN_FOUND)
fl_debug_var (DOXYGEN_EXECUTABLE)
fl_debug_var (DOXYGEN_VERSION)
fl_debug_var (DOXYGEN_VERSION_SHORT)
endif ()
if(0) # debug
fl_debug_var(YEAR)
fl_debug_var(CURRENT_DATE)
fl_debug_var(GIT_REVISION)
fl_debug_var(DOXYGEN_FOUND)
fl_debug_var(DOXYGEN_EXECUTABLE)
fl_debug_var(DOXYGEN_VERSION)
fl_debug_var(DOXYGEN_VERSION_SHORT)
endif()
endif (GENERATE_DOCS)
endif(GENERATE_DOCS)
#--------------------------
# build html documentation
#--------------------------
if (OPTION_BUILD_HTML_DOCUMENTATION)
if(FLTK_BUILD_HTML_DOCS)
list (APPEND DOCS html)
list(APPEND DOCS html)
# generate Doxygen file "Doxyfile"
set (GENERATE_HTML YES)
set (GENERATE_LATEX NO)
set (LATEX_HEADER "")
set (DOXYFILE "Doxyfile")
set (LOGFILE "${CMAKE_CURRENT_BINARY_DIR}/${DOXYFILE}_error.log")
set(GENERATE_HTML YES)
set(GENERATE_LATEX NO)
set(LATEX_HEADER "")
set(DOXYFILE "Doxyfile")
set(LOGFILE "${CMAKE_CURRENT_BINARY_DIR}/${DOXYFILE}_error.log")
# configure Doxygen input file for HTML docs (Doxyfile.in)
configure_file (
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/${DOXYFILE}.in
@ONLY
@@ -132,7 +133,7 @@ if (OPTION_BUILD_HTML_DOCUMENTATION)
# convert Doxyfile to used doxygen version
add_custom_command (
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${DOXYFILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/convert_doxyfile
@@ -146,34 +147,34 @@ if (OPTION_BUILD_HTML_DOCUMENTATION)
# generate HTML documentation
add_custom_target (html
add_custom_target(html
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${DOXYFILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating HTML documentation" VERBATIM
)
endif (OPTION_BUILD_HTML_DOCUMENTATION)
endif(FLTK_BUILD_HTML_DOCS)
#--------------------------
# build pdf documentation
#--------------------------
if (OPTION_BUILD_PDF_DOCUMENTATION)
if(FLTK_BUILD_PDF_DOCS)
list (APPEND DOCS pdf)
list(APPEND DOCS pdf)
# generate Doxygen input file "Doxybook"
set (GENERATE_HTML NO)
set (GENERATE_LATEX YES)
set (LATEX_HEADER "${CMAKE_CURRENT_BINARY_DIR}/fltk-book.tex")
set (DOXYFILE "Doxybook")
set (LOGFILE "${CMAKE_CURRENT_BINARY_DIR}/${DOXYFILE}_error.log")
set(GENERATE_HTML NO)
set(GENERATE_LATEX YES)
set(LATEX_HEADER "${CMAKE_CURRENT_BINARY_DIR}/fltk-book.tex")
set(DOXYFILE "Doxybook")
set(LOGFILE "${CMAKE_CURRENT_BINARY_DIR}/${DOXYFILE}_error.log")
# configure Doxygen input file for PDF docs (Doxybook.in)
configure_file (
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/${DOXYFILE}.in
@ONLY
@@ -181,7 +182,7 @@ if (OPTION_BUILD_PDF_DOCUMENTATION)
# convert Doxybook to current doxygen version
add_custom_command (
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${DOXYFILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/convert_doxyfile
@@ -195,7 +196,7 @@ if (OPTION_BUILD_PDF_DOCUMENTATION)
# generate LaTeX title fltk-title.tex
configure_file (
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/fltk-title.tex.in
${CMAKE_CURRENT_BINARY_DIR}/fltk-title.tex
@ONLY
@@ -203,7 +204,7 @@ if (OPTION_BUILD_PDF_DOCUMENTATION)
# generate fltk.pdf
add_custom_command (
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fltk.pdf
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/make_header
${DOXYGEN_EXECUTABLE}
@@ -220,40 +221,40 @@ if (OPTION_BUILD_PDF_DOCUMENTATION)
# add target 'pdf'
add_custom_target (pdf
add_custom_target(pdf
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/fltk.pdf
)
endif (OPTION_BUILD_PDF_DOCUMENTATION)
endif(FLTK_BUILD_PDF_DOCS)
#----------------------------------
# add target 'docs' for all docs
#----------------------------------
if (DOCS)
if(DOCS)
add_custom_target (docs
add_custom_target(docs
DEPENDS ${DOCS}
)
endif (DOCS)
endif(DOCS)
#----------------------------------
# install html + pdf documentation
#----------------------------------
if (OPTION_INSTALL_HTML_DOCUMENTATION AND OPTION_BUILD_HTML_DOCUMENTATION)
if(FLTK_INSTALL_HTML_DOCS AND FLTK_BUILD_HTML_DOCS)
install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
DESTINATION ${FLTK_DATADIR}/doc/fltk
)
endif (OPTION_INSTALL_HTML_DOCUMENTATION AND OPTION_BUILD_HTML_DOCUMENTATION)
endif(FLTK_INSTALL_HTML_DOCS AND FLTK_BUILD_HTML_DOCS)
if (OPTION_INSTALL_PDF_DOCUMENTATION AND OPTION_BUILD_PDF_DOCUMENTATION)
if(FLTK_INSTALL_PDF_DOCS AND FLTK_BUILD_PDF_DOCS)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/fltk.pdf
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/fltk.pdf
DESTINATION ${FLTK_DATADIR}/doc/fltk/
)
endif (OPTION_INSTALL_PDF_DOCUMENTATION AND OPTION_BUILD_PDF_DOCUMENTATION)
endif(FLTK_INSTALL_PDF_DOCS AND FLTK_BUILD_PDF_DOCS)
+1 -1
View File
@@ -140,7 +140,7 @@ uninstall-linux uninstall-osx:
# Note that Doxyfile.in is shared with CMake to configure these files.
# Note: There's no way to enable the "Driver Documentation" via configure+make,
# please use CMake 'OPTION_INCLUDE_DRIVER_DOCUMENTATION' instead.
# please use CMake 'FLTK_INCLUDE_DRIVER_DOCS' instead.
# Alternatively (if you really need it) edit this Makefile and
# replace the two lines below containing "@DRIVER_DOCS@" to read:
# -e's, @DRIVER_DOCS@, DriverDev,' \
+4 -4
View File
@@ -106,15 +106,15 @@ required software packages (doxygen, LaTeX) installed. You can
always leave them ON because the documentation is not built
automatically (it is excluded from the default target "ALL").
- OPTION_BUILD_HTML_DOCUMENTATION:BOOL=ON target: html
- OPTION_BUILD_PDF_DOCUMENTATION:BOOL=ON target: pdf
- FLTK_BUILD_HTML_DOCS:BOOL=ON target: html
- FLTK_BUILD_PDF_DOCS:BOOL=ON target: pdf
The following two options default to OFF and can be switched ON.
They are only used when installing the software ('make install')
and the corresponding build options are ON.
- OPTION_INSTALL_HTML_DOCUMENTATION:BOOL=OFF
- OPTION_INSTALL_PDF_DOCUMENTATION:BOOL=OFF
- FLTK_INSTALL_HTML_DOCS:BOOL=OFF
- FLTK_INSTALL_PDF_DOCS:BOOL=OFF
If you switch one or both of the first two options ON, then the build
targets 'html' and/or 'pdf' are generated, respectively. Target 'docs'
+1 -1
View File
@@ -863,7 +863,7 @@ requires 4 bytes to store a Unicode character.
FLTK can draw accurately any Unicode-supported script for which the system
contains relevant fonts. Under X11 platforms, this requires
to build the library with the OPTION_USE_PANGO CMake option turned On
to build the library with the FLTK_USE_PANGO CMake option turned On
(or with configure --enable-pango).
Plain text drawing starting at a user-given coordinate
+123
View File
@@ -180,6 +180,129 @@ Code example in header file:
Note the \p 'const' attribute \b and the \p FL_OVERRIDE macro.
\section migration_1_4_modern_cmake Modern CMake
FLTK 1.4.0 supports "modern" CMake rather than old or "classic" CMake
which was used in FLTK 1.3.x. Modern CMake was introduced in CMake 3.0
(~ 2014) and further developed in later CMake versions. FLTK 1.4.0 requires
at least CMake 3.15 (~ 2019) as of Febrary 2024.
There are a lot of advantages that motivated this transition (mentioning
only some):
- easier to use for projects using FLTK
- better structure
- uses CMake targets rather than variables
- embeddable in user projects via FetchContent() etc.
- embeddable in user projects via add_subdirectory()
- better coexistence with main projects if built as a subproject
Note that CMake targets can provide all required build flags and build
dependencies which is the main advantage for user projects. For instance,
instead of linking both fltk and fltk_images you need only fltk_images
and fltk is linked in automatically.
Unfortunately there is one drawback you may encounter: Several CMake build
option names have been changed, compared to FLTK 1.3.x. This is due to the
fact that CMake cache variables are shared between the main (aka superbuild)
project and all subprojects. Therefore all FLTK options are now prefixed
with FLTK_.
This feature is now CMake standard and very common in newer projects. The
CMake developers recommend strongly to use modern CMake.
We took the opportunity to redesign all CMake related options and target
names for FLTK 1.4.0 to avoid changing these names later. Note that CMake
support in 1.3.x was only experimental and the one in FLTK 1.4 (Git) up to
the official release was beta state by definition. We apologize for all
inconveniencies, hope that this is one of the rare exceptions in FLTK
development, and that the new names are now stable as usual.
Changes in Detail:
Since FLTK 1.4.0 CMake target names are "namespaced", i.e. they are created
with the prefix 'fltk::' and the old prefix 'fltk_' has been stripped off
as far as the CMakeLists.txt file of user projects is concerned. The known
filenames on disk did not change though.
The shared library target names use the common suffix "-shared" rather
than "_SHARED".
The library 'fltk_cairo' is no longer used. Its functionality has been included
in libfltk. FLTK 1.4.0 creates a dummy (empty) libfltk_cairo for backwards
compatibility only. Please remove fltk_cairo from your projects and use only
'fltk::fltk' and/or the other libraries instead.
For more information and documentation of all options please refer to the
file README.CMake.txt in the FLTK root directory.
Old and New Library Targets:
Library | Old Target | New Target | Shared Library Target
----------------|--------------|-----------------|-----------------------
fltk | fltk | fltk::fltk | fltk::fltk-shared
fltk_forms | fltk_forms | fltk::forms | fltk::forms-shared
fltk_gl | fltk_gl | fltk::gl | fltk::gl-shared
fltk_images | fltk_images | fltk::images | fltk::images-shared
fltk_jpeg | fltk_jpeg | fltk::jpeg | fltk::jpeg-shared
fltk_png | fltk_png | fltk::png | fltk::png-shared
fltk_z | fltk_z | fltk::z | fltk::z-shared
fluid | fluid | fltk::fluid | n/a
For project developers used to the old (1.3.x) names the following table can
assist to find the new option names. This table is ordered alphabetically
by the old option name. Note that some option names did not change and
some of the "old" names have been introduced in early 1.4.0 development.
Old Option Name (FLTK 1.3.x) | New Option Name (FLTK 1.4.x)
-------------------------------------|------------------------------------
FLTK_BUILD_EXAMPLES | FLTK_BUILD_EXAMPLES
FLTK_BUILD_FLTK_OPTIONS | FLTK_BUILD_FLTK_OPTIONS
FLTK_BUILD_FLUID | FLTK_BUILD_FLUID
FLTK_BUILD_FORMS | FLTK_BUILD_FORMS
FLTK_BUILD_TEST | FLTK_BUILD_TEST
FLTK_MSVC_RUNTIME_DLL | FLTK_MSVC_RUNTIME_DLL
OPTION_ABI_VERSION | FLTK_ABI_VERSION
OPTION_ALLOW_GTK_PLUGIN | FLTK_USE_LIBDECOR_GTK
OPTION_APPLE_X11 | FLTK_BACKEND_X11
OPTION_ARCHFLAGS | FLTK_ARCHFLAGS
OPTION_BUILD_HTML_DOCUMENTATION | FLTK_BUILD_HTML_DOCS
OPTION_BUILD_PDF_DOCUMENTATION | FLTK_BUILD_PDF_DOCS
OPTION_BUILD_SHARED_LIBS | FLTK_BUILD_SHARED_LIBS
OPTION_CAIRO | FLTK_OPTION_CAIRO_WINDOW
OPTION_CAIROEXT | FLTK_OPTION_CAIRO_EXT
OPTION_CREATE_LINKS | FLTK_INSTALL_LINKS
OPTION_FILESYSTEM_SUPPORT | FLTK_OPTION_FILESYSTEM_SUPPORT
OPTION_INCLUDE_DRIVER_DOCUMENTATION | FLTK_INCLUDE_DRIVER_DOCS
OPTION_INSTALL_HTML_DOCUMENTATION | FLTK_INSTALL_HTML_DOCS
OPTION_INSTALL_PDF_DOCUMENTATION | FLTK_INSTALL_PDF_DOCS
OPTION_LARGE_FILE | FLTK_OPTION_LARGE_FILE
OPTION_OPTIM | FLTK_OPTION_OPTIM
OPTION_PRINT_SUPPORT | FLTK_OPTION_PRINT_SUPPORT
OPTION_USE_CAIRO | FLTK_GRAPHICS_CAIRO
OPTION_USE_GDIPLUS | FLTK_GRAPHICS_GDIPLUS
OPTION_USE_GL | FLTK_BUILD_GL
OPTION_USE_KDIALOG | FLTK_USE_KDIALOG
OPTION_USE_PANGO | FLTK_USE_PANGO
OPTION_USE_POLL | FLTK_USE_POLL
OPTION_USE_STD | FLTK_OPTION_STD
OPTION_USE_SVG | FLTK_OPTION_SVG
OPTION_USE_SYSTEM_LIBDECOR | FLTK_USE_SYSTEM_LIBDECOR
OPTION_USE_SYSTEM_LIBJPEG | FLTK_USE_SYSTEM_LIBJPEG
OPTION_USE_SYSTEM_LIBPNG | FLTK_USE_SYSTEM_LIBPNG
OPTION_USE_SYSTEM_ZLIB | FLTK_USE_SYSTEM_ZLIB
OPTION_USE_THREADS | FLTK_USE_PTHREADS
OPTION_USE_WAYLAND | FLTK_BACKEND_WAYLAND
OPTION_USE_XCURSOR | FLTK_USE_XCURSOR
OPTION_USE_XFIXES | FLTK_USE_XFIXES
OPTION_USE_XFT | FLTK_USE_XFT
OPTION_USE_XINERAMA | FLTK_USE_XINERAMA
OPTION_USE_XRENDER | FLTK_USE_XRENDER
OPTION_WAYLAND_ONLY | FLTK_BACKEND_X11=OFF
\htmlonly
<hr>
<table summary="navigation bar" width="100%" border="0">
+3 -3
View File
@@ -191,7 +191,7 @@ without any other change in the source code nor to the application's environment
In special situations, such as with embedded systems equipped with the Wayland software but lacking
the X11 library, it's possible to build the FLTK library such as it contains only the Wayland backend.
This is achieved building FLTK with <tt>cmake -DOPTION_WAYLAND_ONLY=on</tt> or with
This is achieved building FLTK with <tt>cmake -DFLTK_BACKEND_X11=OFF</tt> or with
<tt>configure --disable-x11</tt>. In that case, FL/fl_config.h does not define
\c FLTK_USE_X11.
@@ -1120,7 +1120,7 @@ build system, preprocessor variable \c USE_SYSTEM_LIBDECOR is 1,
and both \c libdecor and its plugin are loaded at run-time from shared libraries.
When these packages are not available or are at an earlier version, FLTK uses the bundled
copy of \c libdecor.
When CMake \c OPTION_USE_SYSTEM_LIBDECOR is OFF, FLTK uses the bundled \c libdecor copy
When CMake \c FLTK_USE_SYSTEM_LIBDECOR is OFF, FLTK uses the bundled \c libdecor copy
even if shared libraries \c libdecor.so and \c libdecor-gtk.so are installed.
This option is ON by default.
@@ -1133,7 +1133,7 @@ However, if environment variable \c LIBDECOR_FORCE_CSD is defined to value \c 1
FLTK app runs, \c libdecor instructs an SSD-able compositor to refrain from decorating its
windows and decorates windows itself.
Whatever the value of \c OPTION_USE_SYSTEM_LIBDECOR, FLTK and \c libdecor use environment variable
Whatever the value of \c FLTK_USE_SYSTEM_LIBDECOR, FLTK and \c libdecor use environment variable
\c LIBDECOR_PLUGIN_DIR as follows: if this variable is defined and points to the name of a directory,
this directory is searched for a potential \c libdecor plugin in the form of a shared library;
if one is found, FLTK and \c libdecor load it and use it.