summaryrefslogtreecommitdiff
path: root/README.CMake.txt
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2024-02-07 18:30:11 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2024-02-07 18:37:34 +0100
commitfd5cd809356dc73d2ede5bb2f0db25098771cb8e (patch)
tree70c82946eb7d11eba910bb387dc3bcc20abfd42c /README.CMake.txt
parent1cf6fdfa8562fafa0566e1008f74ea94f71356e4 (diff)
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.
Diffstat (limited to 'README.CMake.txt')
-rw-r--r--README.CMake.txt856
1 files changed, 515 insertions, 341 deletions
diff --git a/README.CMake.txt b/README.CMake.txt
index 36276b1bd..f8768dc8b 100644
--- a/README.CMake.txt
+++ b/README.CMake.txt
@@ -6,52 +6,65 @@ README.CMake.txt - Building and using FLTK with CMake
==========
1 Introduction to CMake
+
2 Using CMake to Build FLTK
- 2.1 Prerequisites
- 2.2 Options
- 2.3 Building under Linux with Unix Makefiles
- 2.4 Building under Windows with Visual Studio [SUGGESTED DOCS -erco]
- 2.5 Building under Windows with MinGW using Makefiles
- 2.6 Building under MacOS with Xcode
- 2.7 Crosscompiling
+
+ 2.1 Prerequisites
+ 2.2 Options
+ 2.2.1 General CMake Options
+ 2.2.2 FLTK Specific Build Options
+ 2.2.3 Documentation Options
+ 2.2.4 Special Options
+ 2.3 Building under Linux with Unix Makefiles
+ 2.4 Building under Windows with Visual Studio and/or NMake
+ 2.4.1 Building under Windows with Visual Studio
+ 2.4.2 Building under Windows with NMake
+ 2.5 Building under Windows with MinGW using Makefiles
+ 2.6 Building under MacOS with Xcode
+ 2.7 Crosscompiling
+
3 Using CMake with FLTK
- 3.1 Library Names
- 3.2 Building a Simple "Hello World" Program with FLTK
- 3.3 Building a Program Using Fluid Files
- 3.4 Building a Program Using CMake's FetchContent Module
- 4 Document History
+
+ 3.1 Library Names
+ 3.2 Library Aliases
+ 3.3 Exported and Imported Targets
+ 3.4 Building a Simple "Hello World" Program with FLTK
+ 3.5 Building a Program Using Fluid Files
+ 3.6 Building a Program Using CMake's FetchContent Module
+ 4 FindFLTK.cmake and find_package(FLTK)
+
1. Introduction to CMake
===========================
CMake was designed to let you create build files for a project once and
then compile the project on multiple platforms.
-Using it on any platform consists of the same steps. Create the
-CMakeLists.txt build file(s). Run one of the CMake executables, picking
-your source directory, build directory, and build target. The "cmake"
+Using it on any platform consists of the same steps. Create the
+CMakeLists.txt build file(s). Run one of the CMake executables, picking
+your source directory, build directory, and build target. The "cmake"
executable is a one-step process with everything specified on the command
-line. The others let you select options interactively, then configure
-and generate your platform-specific target. You then run the resulting
+line. The others let you select options interactively, then configure
+and generate your platform-specific target. You then run the resulting
Makefile / project file / solution file as you normally would.
-CMake can be run in up to three ways, depending on your platform. "cmake"
-is the basic command line tool. "ccmake" is the curses based interactive
-tool. "cmake-gui" is the gui-based interactive tool. Each of these will
-take command line options in the form of -DOPTION=VALUE. ccmake and
+CMake can be run in up to three ways, depending on your platform. "cmake"
+is the basic command line tool. "ccmake" is the curses based interactive
+tool. "cmake-gui" is the gui-based interactive tool. Each of these will
+take command line options in the form of -DOPTION=VALUE. ccmake and
cmake-gui will also let you change options interactively.
-CMake not only supports, but works best with out-of-tree builds. This means
+CMake not only supports, but works best with out-of-tree builds. This means
that your build directory is not the same as your source directory or with a
-complex project, not the same as your source root directory. Note that the
+complex project, not the same as your source root directory. Note that the
build directory is where, in this case, FLTK will be built, not its final
-installation point. If you want to build for multiple targets, such as
+installation point. If you want to build for multiple targets, such as
VC++ and MinGW on Windows, or do some cross-compiling you must use out-of-tree
-builds exclusively. In-tree builds will gum up the works by putting a
+builds exclusively. In-tree builds will gum up the works by putting a
CMakeCache.txt file in the source root.
-More information on CMake can be found on its web site http://www.cmake.org.
+More information on CMake can be found on its web site https://www.cmake.org.
@@ -63,18 +76,19 @@ More information on CMake can be found on its web site http://www.cmake.org.
--------------------
The prerequisites for building FLTK with CMake are staightforward:
-CMake 3.2.3 or later and a recent FLTK 1.3 release, snapshot, or Git
-download (working copy). Installation of CMake is covered on its web site.
+CMake 3.15 or later and a recent FLTK release, snapshot, or Git download
+(working copy). Installation of CMake is covered on its web site.
This howto will cover building FLTK with the default options using CMake
under Linux and MinGW with Unix Makefiles. Chapter 2.5 shows how to use
a MinGW cross compiling toolchain to build a FLTK library for Windows
-under Linux. Other platforms are just as easy to use.
+under Linux. Other platforms are just as easy to use.
2.2 Options
--------------
-Options can be specified to cmake with the -D flag:
+
+Options can be specified to CMake with the -D flag:
cmake -D <OPTION_NAME>=<OPTION_VALUE>
@@ -82,8 +96,20 @@ Example:
cmake -D CMAKE_BUILD_TYPE=Debug
-All options have sensible defaults so you won't usually need to touch these.
-There are only two CMake options that you may want to specify:
+Notes: the space between '-D' and the option name can be omitted.
+Option values must be quoted if they contain spaces.
+
+Other CMake tools are `ccmake` and `cmake-gui` but these are not
+described here.
+
+All options have sensible defaults so you won't usually need to specify
+them explicitly.
+
+
+ 2.2.1 General CMake Options
+------------------------------
+
+There are only three CMake options that you may want to specify:
CMAKE_BUILD_TYPE
This specifies what kind of build this is i.e. Release, Debug...
@@ -91,7 +117,7 @@ CMAKE_BUILD_TYPE
by CMake depending on this value.
CMAKE_INSTALL_PREFIX
- Where everything will go on install. Defaults are /usr/local for Unix
+ Where everything will go on install. Defaults are /usr/local for Unix
and C:\Program Files\FLTK for Windows.
CMAKE_OSX_ARCHITECTURES (macOS only, ignored on other platforms)
@@ -100,168 +126,226 @@ CMAKE_OSX_ARCHITECTURES (macOS only, ignored on other platforms)
will either build Intel (x86_64) or Apple Silicon aka M1 (arm64) apps.
The default is to build for the host processor architecture.
-The following are the FLTK specific options. Platform specific options
-are ignored on other platforms.
-
-OPTION_OPTIM - default EMPTY
- Extra optimization flags for the C and C++ compilers, for instance
- "-Wall -Wno-deprecated-declarations".
-
-OPTION_ARCHFLAGS - default EMPTY
- Extra architecture flags.
+Note: the CMake variable BUILD_SHARED_LIBS is ignored by FLTK. FLTK builds
+ static libs by default and can optionally build shared libs as well.
+ Please see FLTK_BUILD_SHARED_LIBS instead.
-OPTION_APPLE_X11 - default OFF
- In case you want to use X11 on macOS.
- Use this only if you know what you do, and if you have installed X11.
-OPTION_USE_POLL - default OFF
- Don't use this one, it is deprecated.
+ 2.2.2 FLTK Specific Build Options
+------------------------------------
-OPTION_BUILD_SHARED_LIBS - default OFF
- Normally FLTK is built as static libraries which makes more portable
- binaries. If you want to use shared libraries, this will build them too.
+Following are the FLTK specific options. Platform specific options are
+ignored on other platforms. For convenience the list of options is ordered
+alphabetically except "Documentation Options" and "Special Options" that
+follow in their own sections below.
+
+
+FLTK_ABI_VERSION - default EMPTY
+ Use a numeric value corresponding to the FLTK ABI version you want to
+ build in the form 1xxyy for FLTK 1.x.y (xx and yy with leading zeroes).
+ The default ABI version is 1xx00 (the stable ABI throughout all patch
+ releases of one minor FLTK version). The highest ABI version you may
+ choose is 1xxyy for FLTK 1.x.y (again with leading zeroes).
+ Please see README.abi-version.txt for more information about which
+ ABI version to select.
+
+FLTK_ARCHFLAGS - default EMPTY
+ Extra "architecture" flags used as C and C++ compiler flags.
+ These flags are also "exported" to fltk-config.
+
+FLTK_BACKEND_WAYLAND - default ON (only Unix/Linux)
+ Enable the Wayland backend for all window operations, Cairo for all
+ graphics and Pango for text drawing (Linux+FreeBSD only). Resulting FLTK
+ apps use Wayland when a Wayland compositor is available at runtime,
+ and use X11 for their window operations otherwise (unless FLTK_BACKEND_X11
+ is OFF), but keep using Cairo and Pango - see README.Wayland.txt.
+ If FLTK_BACKEND_X11 has been turned OFF and there is no Wayland compositor
+ at runtime, then FLTK programs fail to start.
+
+FLTK_BACKEND_X11 - default ON on Unix/Linux, OFF elsewhere (Windows, macOS).
+ Enable or disable the X11 backend on platforms that support it.
+ - Unix/Linux: enable or disable the X11 backend when building with
+ Wayland (FLTK_BACKEND_WAYLAND), otherwise this option must be ON.
+ - macOS: enable the X11 backend instead of standard system graphics.
+ This requires XQuartz or a similar X11 installation. This option is
+ tested only with XQuartz by the FLTK team.
+ Use this only if you know what you do and if you have installed X11.
+ - Windows/Cygwin: enable X11 backend for Cygwin platforms. This option
+ is currently (as of FLTK 1.4.0) not supported on Windows.
+
+Note: On platforms that support Wayland you may set FLTK_BACKEND_WAYLAND=ON
+ (this is the default) and FLTK_BACKEND_X11=OFF to build a Wayland-only
+ library or vice versa for an X11-only library.
-FLTK_BUILD_FLUID - default ON
- Builds the Fast Light User-Interface Designer ("FLUID").
+FLTK_BUILD_EXAMPLES - default OFF
+ Build the example programs in the 'examples' directory.
FLTK_BUILD_FLTK_OPTIONS - default ON
- Builds the FLTK options editor ("fltk-options").
+ Build the FLTK options editor ("fltk-options").
-FLTK_BUILD_TEST - default ON
- Builds the test and demo programs in the 'test' directory.
-
-FLTK_BUILD_EXAMPLES - default OFF
- Builds the example programs in the 'examples' directory.
-
-FLTK_MSVC_RUNTIME_DLL - default ON (only for Visual Studio and NMake).
- Selects whether the build uses the MS runtime DLL or not.
- Default is ON: either /MD or /MDd for Release or Debug, respectively.
- Select OFF for either /MT or /MTd for Release or Debug, respectively.
-
-OPTION_CAIRO - default OFF
- Enables support of class Fl_Cairo_Window (all platforms, requires the
- Cairo library) - see README.Cairo.txt.
-
-OPTION_CAIROEXT - default OFF
- Enables extended libcairo support - see README.Cairo.txt.
-
-OPTION_USE_GL - default ON
- Enables OpenGL support.
-
-OPTION_USE_THREADS - default ON
- Enables multithreaded support.
-
-OPTION_LARGE_FILE - default ON
- Enables large file (>2G) support.
-
-OPTION_USE_SYSTEM_LIBJPEG - default ON (macOS: OFF)
-OPTION_USE_SYSTEM_LIBPNG - default ON (macOS: OFF)
-OPTION_USE_SYSTEM_ZLIB - default ON
- FLTK has built in jpeg, zlib, and png libraries. These options let you
- use system libraries instead, unless CMake can't find them. If you set
- any of these options to OFF, then the built in library will be used.
-
-OPTION_USE_SVG - default ON
- FLTK has a built-in SVG library and can create (write) SVG image files.
- Turning this option off disables SVG (read and write) support.
-
-OPTION_USE_XINERAMA - default ON
-OPTION_USE_XFT - default ON
-OPTION_USE_XCURSOR - default ON
-OPTION_USE_XRENDER - default ON
- These are X11 extended libraries. These libs are used if found on the
- build system unless the respective option is turned off.
-
-OPTION_USE_CAIRO - default OFF
- Makes all drawing operations use the Cairo library (rather than Xlib)
- producing antialiased graphics (X11 platform, implies OPTION_USE_PANGO).
-
-OPTION_USE_PANGO - default OFF (see note below)
- Enables use of the Pango library for drawing text. Pango supports all
- unicode-defined scripts and gives FLTK limited support of right-to-left
- scripts. This option makes sense only under X11 or Wayland, and also
- requires Xft.
- Note: Turned ON if Wayland or OPTION_USE_CAIRO is enabled.
-
-OPTION_USE_KDIALOG - default ON
- Under the KDE desktop, allows class Fl_Native_File_Chooser to use the
- kdialog utility program to construct its file dialog windows, when that
- utility is available at run time on the system. This option makes sense
- only under X11 or Wayland.
-
-OPTION_USE_WAYLAND - default ON
- Enables the use of Wayland for all window operations, of Cairo for all
- graphics and of Pango for text drawing (Linux+FreeBSD only). Resulting FLTK
- apps use Wayland when a Wayland compositor is available at run-time,
- and use X11 for their window operations otherwise, but keep using
- Cairo and Pango - see README.Wayland.txt.
-
-OPTION_WAYLAND_ONLY - default OFF
- In conjunction with OPTION_USE_WAYLAND, restricts FLTK to support the
- Wayland backend only.
-
-OPTION_ALLOW_GTK_PLUGIN - default ON
- Allow to use libdecor's GTK plugin to draw window titlebars (Wayland only).
- Otherwise, FLTK will not use GTK and apps will not need linking to GTK.
-
-OPTION_ABI_VERSION - default EMPTY
- Use a numeric value corresponding to the FLTK ABI version you want to
- build in the form 1xxyy for FLTK 1.x.y (xx and yy with leading zeroes).
- The default ABI version is 1xx00 (the stable ABI throughout all patch
- releases of one minor FLTK version). The highest ABI version you may
- choose is 1xxyy for FLTK 1.x.y (again with leading zeroes).
- Please see README.abi-version.txt for more information about which
- ABI version to select.
-
-OPTION_PRINT_SUPPORT - default ON
- When turned off, the Fl_Printer class does nothing and the
- Fl_PostScript_File_Device class cannot be used, but the FLTK library
- is somewhat smaller. This option makes sense only on the Unix/Linux
- platform or when OPTION_APPLE_X11 is ON.
-
-OPTION_USE_GDIPLUS - default ON
- Makes FLTK use GDI+ to draw oblique lines and curves resulting in
- antialiased graphics (Windows platform only).
-
-OPTION_USE_STD - default OFF
- This option allows FLTK to use some specific features of modern C++
- like std::string in the public API of FLTK 1.4.x. Users turning this
- option ON can benefit from some new functions and methods that return
- std::string or use std::string as input parameters.
- Note: this option will probably be removed in the next minor (1.5.0)
- or major (maybe 4.0.0) release which will default to use std::string
- and more modern C++ features.
-
-OPTION_USE_SYSTEM_LIBDECOR - default ON
- This option makes FLTK use package libdecor-0-dev to draw window titlebars
- under Wayland. When OFF or when this package has a version < 0.2.0, FLTK
- uses its bundled copy of libdecor to draw window titlebars.
- As of november 2023, version 0.2.0 of package libdecor-0-dev is available
- only in testing distributions.
-
-Documentation options: these options are only available if `doxygen' is
- installed and found by CMake. PDF related options require also `latex'.
-
-OPTION_BUILD_HTML_DOCUMENTATION - default ON
-OPTION_BUILD_PDF_DOCUMENTATION - default ON
- These options can be used to switch HTML documentation generation with
- doxygen on. If these are ON the build targets 'html', 'pdf', and 'docs'
- are generated but must be built explicitly. Technically the build targets
- are generated but excluded from 'ALL'. You can safely leave these two
- options ON if you want to save build time because the docs are not
- built automatically.
-
-OPTION_INCLUDE_DRIVER_DOCUMENTATION - default OFF
- This option adds driver documentation to HTML and PDF docs (if ON). This
- option is marked as "advanced" since it is only useful for FLTK developers
- and advanced users. It is only used if at least one of the documentation
- options above is ON as well.
-
-OPTION_INSTALL_HTML_DOCUMENTATION - default OFF
-OPTION_INSTALL_PDF_DOCUMENTATION - default OFF
- If these options are ON then the HTML and/or PDF docs are installed
- when the 'install' target is executed, e.g. with `make install'. You
- need to select above options OPTION_BUILD_*_DOCUMENTATION as well.
+FLTK_BUILD_FLUID - default ON
+ Build the Fast Light User-Interface Designer ("fluid").
+
+FLTK_BUILD_FORMS - default ON
+ Build the (X)Forms compatibility library. This option is ON by default
+ for backwards compatibility but can safely be turned OFF if you don't
+ need (X)Forms compatibility.
+
+FLTK_BUILD_GL - default ON
+ Build the OpenGL support library fltk_gl (fltk::gl) and enable OpenGL
+ support in user programs using fltk_gl.
+
+FLTK_BUILD_SHARED_LIBS - default OFF
+ Normally FLTK is built as static libraries which makes more portable
+ binaries. If you want to use shared libraries, this will build them too.
+ You can use shared FLTK libs in your own CMake projects by appending
+ "-shared" to FLTK target names as described in section 3.1 and 3.2.
+
+FLTK_BUILD_TEST - default ON in top-level build, OFF in sub-build
+ Build the test and demo programs in the 'test' directory. The default
+ is ON if the FLTK build is in a top-level project so all test and demo
+ programs are built. If FLTK is built as a subproject only the Library
+ and the tools (fluid and fltk-config) are built by default.
+
+FLTK_GRAPHICS_CAIRO - default OFF (Unix/Linux: X11 + Wayland only).
+ Make all drawing operations use the Cairo library (rather than Xlib),
+ producing antialiased graphics (X11 platform: implies FLTK_USE_PANGO).
+ When using Wayland this option is ignored (Wayland uses Cairo).
+
+FLTK_GRAPHICS_GDIPLUS - default ON (Windows only).
+ Make FLTK use GDI+ to draw oblique lines and curves resulting in
+ antialiased graphics. If this option is OFF standard GDI is used.
+
+FLTK_MSVC_RUNTIME_DLL - default ON (Windows only: Visual Studio and NMake).
+ Select whether the build uses the MS runtime DLL (ON) or not (OFF).
+ Default is ON: either /MD or /MDd for Release or Debug, respectively.
+ Select OFF for either /MT or /MTd for Release or Debug, respectively.
+
+FLTK_OPTION_CAIRO_EXT - default OFF
+ Enable extended libcairo support - see README.Cairo.txt.
+
+FLTK_OPTION_CAIRO_WINDOW - default OFF
+ Enable support of class Fl_Cairo_Window (all platforms, requires the
+ Cairo library) - see README.Cairo.txt.
+
+FLTK_OPTION_FILESYSTEM_SUPPORT - default ON
+
+FLTK_OPTION_LARGE_FILE - default ON
+ Enables large file (>2G) support.
+
+FLTK_OPTION_OPTIM - default EMPTY
+ Extra optimization flags for the C and C++ compilers, for instance
+ "-Wall -Wno-deprecated-declarations".
+
+FLTK_OPTION_PRINT_SUPPORT - default ON
+ When turned off, the Fl_Printer class does nothing and the
+ Fl_PostScript_File_Device class cannot be used, but the FLTK library
+ is somewhat smaller. This option makes sense only on the Unix/Linux
+ platform or on macOS when FLTK_BACKEND_X11 is ON.
+
+FLTK_OPTION_STD - default OFF
+ This option allows FLTK to use some specific features of modern C++
+ like std::string in the public API of FLTK 1.4.x. Users turning this
+ option ON can benefit from some new functions and methods that return
+ std::string or use std::string as input parameters.
+ Note: This option will be removed in the next minor (1.5.0) or major
+ release which will use std::string and other modern C++ features.
+
+FLTK_OPTION_SVG - default ON
+ FLTK has a built-in SVG library and can create (write) SVG image files.
+ Turning this option off disables SVG (read and write) support.
+
+FLTK_USE_KDIALOG - default ON
+ Under the KDE desktop, allows class Fl_Native_File_Chooser to use the
+ kdialog utility program to construct its file dialog windows, when that
+ utility is available at run time on the system. This option makes sense
+ only under X11 or Wayland.
+
+FLTK_USE_LIBDECOR_GTK - default ON (Wayland only).
+ Allow to use libdecor's GTK plugin to draw window titlebars. Otherwise
+ FLTK does not use GTK and apps will not need linking to GTK. This feature
+ is always 'ON' if FLTK_USE_SYSTEM_LIBDECOR is 'ON'.
+
+FLTK_USE_PANGO - default OFF (see note below)
+ Enables use of the Pango library for drawing text. Pango supports all
+ unicode-defined scripts and gives FLTK limited support of right-to-left
+ scripts. This option makes sense only under X11 or Wayland, and also
+ requires Xft.
+ This option is ignored (always enabled) if Wayland or FLTK_GRAPHICS_CAIRO
+ is ON.
+
+FLTK_USE_POLL - default OFF
+ Deprecated: don't turn this option ON.
+
+FLTK_USE_PTHREADS - default ON except on Windows.
+ Enables multithreaded support with pthreads if available.
+ This option is ignored (switched OFF internally) on Windows except
+ when using Cygwin.
+
+FLTK_USE_SYSTEM_LIBDECOR - default ON (Wayland only)
+ This option makes FLTK use package libdecor-0-dev to draw window titlebars
+ under Wayland. When OFF or when this package has a version < 0.2.0, FLTK
+ uses its bundled copy of libdecor to draw window titlebars.
+ As of november 2023, version 0.2.0 of package libdecor-0-dev is available
+ only in testing distributions.
+
+FLTK_USE_SYSTEM_LIBJPEG - default ON (macOS and Windows: OFF)
+FLTK_USE_SYSTEM_LIBPNG - default ON (macOS and Windows: OFF)
+FLTK_USE_SYSTEM_ZLIB - default ON (macOS and Windows: OFF)
+ FLTK has built in jpeg, zlib, and png libraries. These options let you
+ use system libraries instead, unless CMake can't find them. If you set
+ any of these options to OFF, then the built in library will be used.
+ The default is ON on Linux/Unix platforms but OFF on Windows and macOS
+ because of potential incompatibilities on Windows and macOS whereas
+ the system libraries can typically be used on Linux/Unix.
+ Note: if any one of libpng or zlib is not found on the system, both
+ libraries are built using the bundled ones and a warning is issued.
+
+FLTK_USE_XCURSOR - default ON
+FLTK_USE_XFIXES - default ON
+FLTK_USE_XFT - default ON
+FLTK_USE_XINERAMA - default ON
+FLTK_USE_XRENDER - default ON
+ These are X11 extended libraries. These libs are used if found on the
+ build system unless the respective option is turned off.
+
+
+ 2.2.3 Documentation Options
+------------------------------
+
+ These options are only available if `doxygen' is installed and found.
+ PDF related options require also `latex'.
+
+FLTK_BUILD_HTML_DOCS - default ON
+FLTK_BUILD_PDF_DOCS - default ON
+ These options can be used to enable HTML documentation generation with
+ doxygen. If these are ON the build targets 'html', 'pdf', and 'docs'
+ are generated but must be built explicitly. Technically the build targets
+ are generated but excluded from 'ALL'.
+ You can safely leave these two options ON if you want to save build time
+ because the docs are not built automatically.
+
+FLTK_INCLUDE_DRIVER_DOCS - default OFF
+ This option adds driver documentation to HTML and PDF docs (if ON). This
+ option is marked as "advanced" since it is only useful for FLTK developers
+ and advanced users. It is only used if at least one of the documentation
+ options above is ON as well.
+
+FLTK_INSTALL_HTML_DOCS - default OFF
+FLTK_INSTALL_PDF_DOCS - default OFF
+ If these options are ON then the HTML and/or PDF docs are installed
+ when the 'install' target is executed, e.g. with `make install'. You
+ need to select above options FLTK_BUILD_*_DOCS as well.
+
+
+ 2.2.4 Special Options
+------------------------
+
+FLTK_INSTALL_LINKS - default OFF
+ Deprecated: install "compatibility" links to compensate for typos in
+ include statements (for case sensitive file systems only).
+ You should not use this option, please fix the sources instead for
+ better cross-platform compatibility.
2.3 Building under Linux with Unix Makefiles
@@ -285,7 +369,7 @@ Some flags can be changed during the 'make' command, such as:
make VERBOSE=on
-..which builds in verbose mode, so you can see all the compile/link commands.
+which builds in verbose mode, so you can see all the compile/link commands.
Hint: if you intend to build several different versions of FLTK, e.g. a Debug
and a Release version, or multiple libraries with different ABI versions or
@@ -293,96 +377,117 @@ options, then use subdirectories in the build directory, like this:
mkdir build
cd build
- mkdir Debug
- cd Debug
+ mkdir debug
+ cd debug
cmake -D 'CMAKE_BUILD_TYPE=Debug' ../..
make
sudo make install (optional)
- 2.4 Building under Windows with Visual Studio
-------------------------------------------------
+ 2.4 Building under Windows with Visual Studio and/or NMake
+-------------------------------------------------------------
+
+Building with CMake under Visual Studio may require to specify the CMake
+generator with the -G"Visual Studio ..." command line switch, or the
+generator can be selected interactively in the GUI (cmake-gui). If you
+are not sure which one to select use `cmake --help` which lists all
+generators known to CMake on your system.
+
+
+ 2.4.1 Building under Windows with Visual Studio
+-------------------------------------------------
+
+CMake often finds an installed Visual Studio generator and uses it w/o
+using the commandline switch, particularly if you are using a special
+"Visual Studio Command Prompt":
+
+ - Hit the "Windows" key
+
+ - Type "developer command ..."
+ ... until you see something like "Developer Command Prompt for VS xxxx"
+ (replace 'xxxx' with your installed Visual Studio version)
-Building with CMake under Visual Studio requires the CMake generator with
-the -G command line switch, or the generator can be selected interactively
-in the GUI (cmake-gui).
+ - Activate the "app" to execute the command prompt (like an old "DOS" shell)
- 2.4.1 Visual Studio 7 / .NET
- ------------------------------
+ - Inside this command prompt window, run your installed `cmake` (command
+ line) or `cmake-gui` (GUI) program. You may need to specify the full path
+ to this program.
- 1) Open a "Visual Studio .NET command prompt" window, e.g.
+ If you use `cmake-gui` you can select the source and the build folders in
+ the GUI, otherwise change directory to where you downloaded and installed
+ the FLTK sources and execute:
- Start > All Programs > Microsoft Visual Studio .NET >
- Visual Studio .NET Tools > Command Prompt
+ `cmake` -G "Visual Studio xxx..." -B build
+ cd build
- 2) In the DOS window created above, change the current directory
- to where you've extracted an fltk distribution tar file (or
- snapshot tar file), and run the following commands:
+ This creates the Visual Studio project files (FLTK.sln and more) in the
+ 'build' directory.
- cd C:\fltk-1.4.x <-- change to your FLTK directory
- mkdir build <-- create an empty directory
- cd build
- cmake -G "Visual Studio 7" -D CMAKE_BUILD_TYPE=Release ..
+ Open Visual Studio, choose File -> Open -> Project, and pick the "FLTK.sln"
+ created in the previous step.
- IMPORTANT: The trailing ".." on the cmake command must be specified
- (it is NOT an ellipsis). ^^^^^^^^^^^^^^^^^
+ (Or, if only one version of the Visual Studio compiler is installed,
+ you can just run from DOS: .\FLTK.sln)
- This will create the file FLTK.sln in the current 'build' directory.
+ Make sure the pulldown menu has either "Release" or "Debug" selected
+ in the "Solution Configurations" pulldown menu.
- 3) Open Visual Studio 7, and choose File -> Open -> Project,
- and pick the "FLTK.sln" created by step #2 in the 'build' directory.
+ In the "Solution Explorer", right click on:
- (Or, if only one version of the Visual Studio compiler is installed,
- you can just run from DOS: .\FLTK.sln)
+ Solution 'FLTK' (## projects)
- 4) Make sure the pulldown menu has either "Release" or "Debug" selected
- in the "Solution Configurations" pulldown menu.
+ ... and in the popup menu, choose "Build Solution"
- 5) In the "Solution Explorer", right click on:
+ or choose 'Build/Build Solution' or 'Build/Rebuild Solution' from the
+ menu at the top of the window.
- Solution 'FLTK' (## projects)
+ That's it, that should build FLTK.
- ..and in the popup menu, choose "Build Solution"
+ The test programs (*.exe) can be found relative to the 'build' folder in
- 5) That's it, that should build FLTK.
+ build\bin\test\Release\*.exe
+ build\bin\test\Debug\*.exe
- The test programs (*.exe) can be found in e.g.
+ ... and the FLTK include files (*.H & *.h) your own apps can
+ compile with can be found in:
- Release: C:\fltk-1.4.x\build\bin\examples\release\*.exe
- Debug: C:\fltk-1.4.x\build\bin\examples\debug\*.exe
+ build\FL
- ..and the FLTK include files (*.H & *.h) your own apps can
- compile with can be found in:
+ *and* [1] in the source folder where you downloade FLTK, e.g. in
- Release & Debug: C:\fltk-1.4.x\build\FL
- *and* [1] in: C:\fltk-1.4.x\FL
+ C:\fltk-1.4.x\FL
- ..and the FLTK library files (*.lib) which your own apps can
- link with can be found in:
+ ... and the FLTK library files (*.lib) which your own apps can
+ link with can be found in:
- Release: C:\fltk-1.4.x\build\lib\release\*.lib
- Debug: C:\fltk-1.4.x\build\lib\debug\*.lib
+ Release: build\lib\Release\*.lib
+ Debug: build\lib\Debug\*.lib
- [1] If you want to build your own FLTK application directly using
- the build directories (i.e. without "installation") you need
- to include both the build tree (first) and then the FLTK source
- tree in the compiler's header search list.
+ [1] If you want to build your own FLTK application directly using
+ the build directories (i.e. without "installation") you need
+ to include both the build tree (first) and then the FLTK source
+ tree in the compiler's header search list.
- 2.4.2 Visual Studio 2019 / NMake
- --------------------------------------
- This uses cmake to generate + build FLTK in Release mode using nmake,
- using purely the command line (never need to open the Visual Studio IDE)
- using Multithreaded (/MT):
- mkdir build-nmake
- cd build-nmake
- cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=Release -D FLTK_MSVC_RUNTIME_DLL=off ..
- nmake
+ 2.4.2 Building under Windows with NMake
+-----------------------------------------
+
+ This example uses cmake to generate + build FLTK in Release mode using nmake,
+ using purely the command line (never need to open the Visual Studio IDE)
+ using Multithreaded (/MT):
+
+ mkdir build-nmake
+ cd build-nmake
+ cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=Release -D FLTK_MSVC_RUNTIME_DLL=off ..
+ nmake
+
+ which results in a colorful percentage output crawl similar to what we see
+ with unix 'make'.
+
+ Instead of running `nmake` directly you can also use cmake to build:
+
+ cmake --build .
- ..which results in a colorful percentage output crawl similar to what
- we see with unix 'make'.
- -erco@seriss.com
- Updated: Dec 8 2023
2.5 Building under Windows with MinGW using Makefiles
--------------------------------------------------------
@@ -437,13 +542,6 @@ of the cmake related files are updated, Xcode will rerun cmake for you.
5a) To build the Release version of FLTK, use
> cmake -G Xcode -D CMAKE_BUILD_TYPE=Release ../..
-5b) To create all included libraries instead of using those that come
- with MacOS, use:
- > cmake -G Xcode -D OPTION_USE_SYSTEM_LIBJPEG=Off \
- -D OPTION_USE_SYSTEM_ZLIB=Off \
- -D OPTION_USE_SYSTEM_LIBPNG=Off \
- ../..
-
6) Launch Xcode from the Finder or from the Terminal:
> open ./FLTK.xcodeproj
When Xcode starts, it asks if it should "Autocreate Schemes". Click on
@@ -463,9 +561,9 @@ of the cmake related files are updated, Xcode will rerun cmake for you.
---------------------
Once you have a crosscompiler going, to use CMake to build FLTK you need
-two more things. You need a toolchain file which tells CMake where your
-build tools are. The CMake website is a good source of information on
-this file. Here's one for MinGW (64-bit) under Linux.
+two more things. You need a toolchain file which tells CMake where your
+build tools are. The CMake website is a good source of information on
+this file. Here's one for MinGW (64-bit) under Linux.
----
# CMake Toolchain File for MinGW-w64 (64-bit) Cross Compilation
@@ -499,8 +597,8 @@ set(CMAKE_EXE_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++")
# end of toolchain file
----
-Not too tough. The other thing you need is a native installation of FLTK
-on your build platform. This is to supply the fluid executable which will
+Not too tough. The other thing you need is a native installation of FLTK
+on your build platform. This is to supply the fluid executable which will
compile the *.fl into C++ source and header files.
So, again from the FLTK tree root.
@@ -525,12 +623,12 @@ required.
===========================
The CMake Export/Import facility can be thought of as an automated
-fltk-config. For example, if you link your program to the FLTK
-library, it will automatically link in all of its dependencies. This
+fltk-config. For example, if you link your program to the FLTK
+library, it will automatically link in all of its dependencies. This
includes any special flags, i.e. on Linux it includes the -lpthread flag.
This howto assumes that you have FLTK libraries which were built using CMake,
-installed. Building them with CMake generates some CMake helper files which
+installed. Building them with CMake generates some CMake helper files which
are installed in standard locations, making FLTK easy to find and use.
In the following examples we set the CMake cache variable 'FLTK_DIR' so
@@ -549,69 +647,148 @@ Unix/Linux, for instance like this:
--------------------
When you use the target_link_libraries() command, CMake uses its own internal
-"target names" for libraries. The fltk library names are:
+"target names" for libraries. The original fltk library names in the build
+tree are:
fltk fltk_forms fltk_images fltk_gl
-and for the shared libraries (if built):
+The bundled image and zlib libraries (if built):
- fltk_SHARED fltk_forms_SHARED fltk_images_SHARED fltk_gl_SHARED
+ fltk_jpeg fltk_png fltk_z
-The built-in libraries (if built):
+Append suffix "-shared" for shared libraries (Windows: DLL's).
+
+These library names are used to construct the filename on disk with system
+specific prefixes and postfixes. For instance, on Linux/Unix 'fltk' is libfltk.a
+and the shared library (fltk-shared) is libfltk.so.1.4.0 (in FLTK 1.4.0) with
+additional system specific links.
+
+Note: since FLTK 1.4.0 the library fltk_cairo is no longer necessary and
+should be removed from CMake files of user projects. fltk_cairo is now an
+empty library solely for backwards compatibility and will be removed in the
+future.
+
+
+ 3.2 Library Aliases
+----------------------
+
+Since FLTK 1.4.0 "aliases" for all libraries in the FLTK build tree are
+created in the namespace "fltk::". These aliases should always be used by
+consumer projects (projects that use FLTK) for several reasons which are
+beyond the scope of this README file. The following table shows the FLTK
+libraries and their aliases in the FLTK build tree.
+
+ Library Name Alias Shared Library Alias Notes
+ --------------------------------------------------------------
+ fltk fltk::fltk fltk::fltk-shared [1]
+ fltk_forms fltk::forms fltk::forms-shared [2]
+ fltk_gl fltk::gl fltk::gl-shared [2]
+ fltk_images fltk::images fltk::images-shared [2]
+ fltk_jpeg fltk::jpeg fltk::jpeg-shared [3]
+ fltk_png fltk::png fltk::png-shared [3]
+ fltk_z fltk::z fltk::z-shared [3]
+
+ [1] The basic FLTK library. Use this if you don't need any of the other
+ libraries for your application.
+ [2] Use one or more of these libraries if you have specific needs,
+ e.g. if you need to read images (fltk::images), OpenGL (fltk::gl),
+ or (X)Forms compatibility (fltk::forms). If you use one of these
+ libraries in your CMakeLists.txt then fltk::fltk will be included
+ automatically.
+ [3] The bundled libraries are only built if requested and are usually
+ not needed in user projects. They are linked in with fltk::images
+ automatically if they were built with FLTK.
+ The only reason you may need them would be if you used libpng,
+ libjpeg, or zlib functions directly in your application and need
+ to use the bundled FLTK libs (e.g. on Windows).
+
+
+ 3.3 Exported and Imported Targets
+------------------------------------
- fltk_jpeg fltk_png fltk_z
+CMake terminology is to "export" and "import" library "targets". FLTK's
+CMake files export targets and its CONFIG module FLTKConfig.cmake imports
+targets so user projects can use them. Hence, if you use CMake's CONFIG
+mode to find FLTK all library targets will be defined using the namespace
+convention listed above in the "Alias" column. This is what user projects
+are intended to use.
+In addition to the library targets FLTK defines the "imported target"
+'fltk::fluid' which can be used to generate source (.cxx) and header (.h)
+files from fluid (.fl) files.
- 3.2 Building a Simple "Hello World" Program with FLTK
+Another target fltk::fltk-config can be used to set (e.g.) system or user
+specific FLTK options. This would usually be executed in the installation
+process of a user project but should rarely be needed and is beyound the
+scope of this documentation.
+
+
+ 3.4 Building a Simple "Hello World" Program with FLTK
--------------------------------------------------------
-Here is a basic CMakeLists.txt file using FLTK.
+Here is a basic CMakeLists.txt file using FLTK. It is important that
+this file can only be used as simple as it is if you use find_package()
+in `CONFIG` mode as shown below. This requires that the FLTK library
+itself has been built with CMake.
---
cmake_minimum_required(VERSION 3.15)
project(hello)
+# optional (see below):
set(FLTK_DIR "/path/to/fltk"
CACHE FILEPATH "FLTK installation or build directory")
-find_package(FLTK REQUIRED CONFIG)
-
-add_executable(hello WIN32 MACOSX_BUNDLE hello.cxx)
-if (APPLE)
- target_link_libraries (hello PRIVATE "-framework cocoa")
-endif (APPLE)
+find_package(FLTK CONFIG REQUIRED)
-target_include_directories (hello PRIVATE ${FLTK_INCLUDE_DIRS})
-
-target_link_libraries (hello PRIVATE fltk)
+add_executable (hello WIN32 MACOSX_BUNDLE hello.cxx)
+target_link_libraries(hello PRIVATE fltk::fltk)
---
-The set(FLTK_DIR ...) command is a superhint to the find_package command.
-This is very useful if you don't install or have a non-standard install.
-The find_package command tells CMake to find the package FLTK, REQUIRED
-means that it is an error if it's not found. CONFIG tells it to search
-only for the FLTKConfig file, not using the FindFLTK.cmake supplied with
-CMake, which doesn't work with this version of FLTK.
+We recommend to use `cmake_minimum_required(VERSION 3.15)` or higher for
+building projects that use FLTK. Lower CMake versions may work for user
+projects but this is not tested by FLTK developers.
-The "WIN32 MACOSX_BUNDLE" in the add_executable tells this is a GUI app.
-It is ignored on other platforms and should always be present with FLTK
-GUI programs for better portability - unless you explicitly need to build
-a "console program", e.g. on Windows.
+The optional `set(FLTK_DIR ...)` command is a superhint to the find_package
+command. This is very useful if you don't install or have a non-standard
+install location. The path you give to it must be that of a directory that
+contains the file FLTKConfig.cmake.
-Once the package is found the CMake variable FLTK_INCLUDE_DIRS is defined
-which can be used to add the FLTK include directories to the definitions
-used to compile your program using the `target_include_directories()` command.
+You can omit this statement if CMake finds the required FLTK version
+without it. This variable is stored in the CMake Cache so users can change
+it with the ususal CMake GUI interfaces (ccmake, cmake-gui) or on the
+CMake commandline (-D FLTK_DIR=...).
-The target_link_libraries() command is used to specify all necessary FLTK
-libraries. Thus, you may have to add fltk_images, fltk_gl, etc…
+The find_package command tells CMake to find the package FLTK, REQUIRED
+means that it is an error if it's not found. CONFIG tells it to search
+only for the FLTKConfig.cmake file, not using the FindFLTK.cmake "module"
+supplied with CMake, which doesn't work with this version of FLTK.
+
+"WIN32 MACOSX_BUNDLE" in the add_executable() command tells CMake that
+this is a GUI app. It is ignored on other platforms than Windows or macOS,
+respectively, and should always be present with FLTK GUI programs for
+better portability - unless you explicitly need to build a "console program"
+on Windows.
+
+Once the package is found (in CONFIG mode, as described above) all built
+FLTK libraries are "imported" as CMake "targets" or aliases and can be used
+directly. These CMake library targets contain all necessary informations to
+be used without having to know about additional include directories or
+other library dependencies. This is what is called "Modern CMake".
+
+Older FLTK versions required to use the variables FLTK_INCLUDE_DIRS and
+FLTK_LIBRARIES (among others). These variables and related commands are
+no longer necessary if your project (CMakeLists.txt) uses CMake's
+CONFIG mode as described in this file.
-Note: the variable FLTK_USE_FILE used to include another file in
-previous FLTK versions was deprecated since FLTK 1.3.4 and has been
-removed in FLTK 1.4.0.
+The target_link_libraries() command is used to specify all necessary FLTK
+libraries. Thus you may use fltk::fltk, fltk::images, fltk::gl, fltk::forms,
+or any combination. fltk::fltk is linked automatically if any of the other
+libs is included.
- 3.3 Building a Program Using Fluid Files
+ 3.5 Building a Program Using Fluid Files
-------------------------------------------
CMake has a command named fltk_wrap_ui which helps deal with fluid *.fl
@@ -619,6 +796,7 @@ files. Unfortunately it is broken in CMake 3.4.x but it seems to work in
3.5 and later CMake versions. We recommend to use add_custom_command()
to achieve the same result in a more explicit and well-defined way.
This is a more basic approach and should work for all CMake versions.
+It is described below.
Here is a sample CMakeLists.txt which compiles the CubeView example from
a directory you've copied the test/Cube* files to.
@@ -632,41 +810,40 @@ project(CubeView)
set(FLTK_DIR "/path/to/fltk"
CACHE FILEPATH "FLTK installation or build directory")
-find_package(FLTK REQUIRED CONFIG)
+find_package(FLTK CONFIG REQUIRED)
# run fluid -c to generate CubeViewUI.cxx and CubeViewUI.h files
add_custom_command(
OUTPUT "CubeViewUI.cxx" "CubeViewUI.h"
- COMMAND fluid -c ${CMAKE_CURRENT_SOURCE_DIR}/CubeViewUI.fl
+ COMMAND fltk::fluid -c ${CMAKE_CURRENT_SOURCE_DIR}/CubeViewUI.fl
)
add_executable(CubeView WIN32 MACOSX_BUNDLE
- CubeMain.cxx CubeView.cxx CubeViewUI.cxx)
-
-target_include_directories (CubeView PRIVATE ${FLTK_INCLUDE_DIRS})
+ CubeMain.cxx CubeView.cxx CubeViewUI.cxx)
-target_include_directories (CubeView PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-target_include_directories (CubeView PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
+target_include_directories(CubeView PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_include_directories(CubeView PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
-target_link_libraries (CubeView PRIVATE fltk fltk_gl)
+target_link_libraries (CubeView PRIVATE fltk::gl)
---
You can repeat the add_custom_command for each fluid file or if you
-have a large number of them see the CMake/FLTK-Functions.cmake function
-FLTK_RUN_FLUID for an example of how to run it in a loop.
+have a large number of them see the fltk_run_fluid() function in
+CMake/FLTK-Functions.cmake for an example of how to run it in a loop.
The two lines
- target_include_directories (CubeView PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
- target_include_directories (CubeView PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
+ target_include_directories(CubeView PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+ target_include_directories(CubeView PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
add the current build ("binary") and source directories as include directories.
This is necessary for the compiler to find the local header files since the
fluid-generated files (CubeViewUI.cxx and CubeViewUI.h) are created in the
-current build directory.
+current build directory and other header files may be in the source directory
+(depending on your project).
- 3.4 Building a Program Using CMake's FetchContent Module
+ 3.6 Building a Program Using CMake's FetchContent Module
-----------------------------------------------------------
FLTK can be downloaded and built within a user project using CMake's
@@ -680,41 +857,38 @@ project(hello)
include(FetchContent)
-set(FLTK_BUILD_TEST OFF CACHE BOOL "" FORCE)
-
FetchContent_Declare(FLTK
- GIT_REPOSITORY https://github.com/fltk/fltk
- GIT_SHALLOW TRUE
+ GIT_REPOSITORY https://github.com/fltk/fltk
+ GIT_TAG master
+ GIT_SHALLOW TRUE
)
-FetchContent_MakeAvailable(FLTK)
-add_executable(hello WIN32 MACOSX_BUNDLE hello.cxx)
+message(STATUS "Download and build FLTK if necessary, please wait...")
+FetchContent_MakeAvailable(FLTK)
+message(STATUS "Download and build FLTK - done.")
-target_include_directories(hello PRIVATE ${fltk_BINARY_DIR} ${fltk_SOURCE_DIR})
+add_executable (hello WIN32 MACOSX_BUNDLE hello.cxx)
+target_link_libraries(hello PRIVATE fltk::fltk)
+---
-# link as required: fltk fltk_gl fltk_images fltk_png fltk_jpeg fltk_z
-target_link_libraries(hello PRIVATE fltk)
+This is as simple as it can be. The CMake FetchContent module is used to
+download the FLTK sources from their Git repository and to build them.
+Note that this will download and build the FLTK library during the CMake
+configure phase which can take some time. Therefore the statement
+`FetchContent_MakeAvailable()` is wrapped in `message(STATUS "...")`
+commands to let the user know what's going on.
-if(APPLE)
- target_link_libraries(hello PRIVATE "-framework Cocoa") # needed for Darwin
-endif()
-if(WIN32)
- target_link_libraries(hello PRIVATE gdiplus)
-endif()
----
+ 4 FindFLTK.cmake and find_package(FLTK)
+==========================================
+The FindFLTK.cmake module provided by CMake which is also used in the
+CMake command find_package(FLTK) does not yet support FLTK's new "Modern
+CMake" features.
- 4 Document History
----------------------
+Unfortunately this module has to be used if the FLTK library wasn't built
+with CMake and thus CONFIG mode can't be used. In this case CMake falls back
+to MODULE mode and find_package() uses this old CMake module.
-Dec 20 2010 - matt: merged and restructured
-May 15 2013 - erco: small formatting tweaks, added some examples
-Feb 23 2014 - msurette: updated to reflect changes to the CMake files
-Apr 07 2015 - AlbrechtS: update use example and more docs
-Jan 31 2016 - msurette: custom command instead of fltk_wrap_ui
-Nov 01 2016 - AlbrechtS: add MinGW build
-Jul 05 2017 - matt: added instructions for macOS and Xcode
-Dec 29 2018 - AlbrechtS: add documentation option descriptions
-Apr 29 2021 - AlbrechtS: document macOS "universal apps" build setup
-Nov 01 2023 - AlbrechtS: improve build instructions for user programs
+There are plans to provide a FindFLTK.cmake module with FLTK 1.4.0 but this
+module is not yet written. Look here for further info if you need it...