2015-04-07 18:18:35 +03:00
|
|
|
README.CMake.txt - Building and using FLTK with CMake
|
|
|
|
-----------------------------------------------------
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
CONTENTS
|
|
|
|
==========
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
1 Introduction to CMake
|
2024-02-07 20:30:11 +03:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
2 Using CMake to Build FLTK
|
2024-02-07 20:30:11 +03:00
|
|
|
|
|
|
|
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
|
2024-07-29 14:05:23 +03:00
|
|
|
2.6 Building under Windows WSL with Clang using Makefiles
|
|
|
|
2.7 Building under MacOS with Xcode
|
|
|
|
2.8 Crosscompiling
|
2024-02-07 20:30:11 +03:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
3 Using CMake with FLTK
|
2024-02-07 20:30:11 +03:00
|
|
|
|
|
|
|
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
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
4 FindFLTK.cmake and find_package(FLTK)
|
|
|
|
|
2023-10-31 18:04:31 +03:00
|
|
|
1. Introduction to CMake
|
2016-11-01 18:18:31 +03:00
|
|
|
===========================
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
CMake was designed to let you create build files for a project once and
|
|
|
|
then compile the project on multiple platforms.
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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"
|
2010-12-20 23:00:44 +03:00
|
|
|
executable is a one-step process with everything specified on the command
|
2024-02-07 20:30:11 +03:00
|
|
|
line. The others let you select options interactively, then configure
|
|
|
|
and generate your platform-specific target. You then run the resulting
|
2010-12-20 23:00:44 +03:00
|
|
|
Makefile / project file / solution file as you normally would.
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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
|
2010-12-20 23:00:44 +03:00
|
|
|
cmake-gui will also let you change options interactively.
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
CMake not only supports, but works best with out-of-tree builds. This means
|
2010-12-20 23:00:44 +03:00
|
|
|
that your build directory is not the same as your source directory or with a
|
2024-02-07 20:30:11 +03:00
|
|
|
complex project, not the same as your source root directory. Note that the
|
2010-12-20 23:00:44 +03:00
|
|
|
build directory is where, in this case, FLTK will be built, not its final
|
2024-02-07 20:30:11 +03:00
|
|
|
installation point. If you want to build for multiple targets, such as
|
2010-12-20 23:00:44 +03:00
|
|
|
VC++ and MinGW on Windows, or do some cross-compiling you must use out-of-tree
|
2024-02-07 20:30:11 +03:00
|
|
|
builds exclusively. In-tree builds will gum up the works by putting a
|
2010-12-20 23:00:44 +03:00
|
|
|
CMakeCache.txt file in the source root.
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
More information on CMake can be found on its web site https://www.cmake.org.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-01 18:18:31 +03:00
|
|
|
2. Using CMake to Build FLTK
|
|
|
|
===============================
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
2016-11-01 18:18:31 +03:00
|
|
|
2.1 Prerequisites
|
|
|
|
--------------------
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
The prerequisites for building FLTK with CMake are staightforward:
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2016-11-01 18:18:31 +03:00
|
|
|
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
|
2024-02-07 20:30:11 +03:00
|
|
|
under Linux. Other platforms are just as easy to use.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
2016-11-01 18:18:31 +03:00
|
|
|
2.2 Options
|
|
|
|
--------------
|
2024-02-07 20:30:11 +03:00
|
|
|
|
|
|
|
Options can be specified to CMake with the -D flag:
|
2013-05-16 17:29:49 +04:00
|
|
|
|
|
|
|
cmake -D <OPTION_NAME>=<OPTION_VALUE>
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
cmake -D CMAKE_BUILD_TYPE=Debug
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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:
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
CMAKE_BUILD_TYPE
|
2013-05-16 17:29:49 +04:00
|
|
|
This specifies what kind of build this is i.e. Release, Debug...
|
|
|
|
Platform specific compile/link flags/options are automatically selected
|
|
|
|
by CMake depending on this value.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
CMAKE_INSTALL_PREFIX
|
2024-02-07 20:30:11 +03:00
|
|
|
Where everything will go on install. Defaults are /usr/local for Unix
|
2013-05-16 17:29:49 +04:00
|
|
|
and C:\Program Files\FLTK for Windows.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2021-04-29 19:32:19 +03:00
|
|
|
CMAKE_OSX_ARCHITECTURES (macOS only, ignored on other platforms)
|
|
|
|
Set this to either "arm64", "x86_64", or a list of both "arm64;x86_64".
|
|
|
|
The latter will build "universal apps" on macOS, whereas the former
|
|
|
|
will either build Intel (x86_64) or Apple Silicon aka M1 (arm64) apps.
|
|
|
|
The default is to build for the host processor architecture.
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
2.2.2 FLTK Specific Build Options
|
|
|
|
------------------------------------
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2013-05-16 17:29:49 +04:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
FLTK_BUILD_EXAMPLES - default OFF
|
|
|
|
Build the example programs in the 'examples' directory.
|
2022-11-13 22:16:54 +03:00
|
|
|
|
2023-01-21 19:14:41 +03:00
|
|
|
FLTK_BUILD_FLTK_OPTIONS - default ON
|
2024-02-07 20:30:11 +03:00
|
|
|
Build the FLTK options editor ("fltk-options").
|
2023-01-21 19:14:41 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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
|
2024-06-25 07:14:51 +03:00
|
|
|
"-Wall -Wno-deprecated-declarations". Example:
|
|
|
|
cmake -D FLTK_BUILD_EXAMPLES=on -D FLTK_OPTION_OPTIM="-Wall -Wextra -pedantic" ..
|
2024-02-07 20:30:11 +03:00
|
|
|
|
|
|
|
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_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)
|
2024-09-23 20:41:44 +03:00
|
|
|
This option is highly recommended under X11 if FLTK is expected to draw
|
|
|
|
text that does not use the latin alphabet.
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
|
|
|
|
2024-04-18 20:32:47 +03:00
|
|
|
FLTK_USE_SYSTEM_LIBDECOR - default ON (Wayland only)
|
2024-02-07 20:30:11 +03:00
|
|
|
This option makes FLTK use package libdecor-0-dev to draw window titlebars
|
2024-04-18 20:32:47 +03:00
|
|
|
under Wayland. When OFF or when this package has a version < 0.2.0, FLTK
|
2024-02-07 20:30:11 +03:00
|
|
|
uses its bundled copy of libdecor to draw window titlebars.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2024-04-17 18:51:32 +03:00
|
|
|
FLTK_BUILD_FLUID_DOCS - default OFF
|
2024-06-21 19:10:33 +03:00
|
|
|
If this option is ON, the FLUID user documentation will be built. If
|
2024-04-17 18:51:32 +03:00
|
|
|
FLTK_BUILD_PDF_DOCS is ON, the FLUID documentation will be generated
|
|
|
|
in PDF forma. To generate the screen shots used in the handbook,
|
|
|
|
the CMake build mode must be set to "Debug".
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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
|
2024-04-17 18:51:32 +03:00
|
|
|
FLTK_INSTALL_FLUID_DOCS - default OFF
|
2024-02-07 20:30:11 +03:00
|
|
|
FLTK_INSTALL_PDF_DOCS - default OFF
|
2024-04-17 18:51:32 +03:00
|
|
|
If these options are ON then the HTML, FLUID, and/or PDF docs are installed
|
2024-06-21 19:10:33 +03:00
|
|
|
when the 'install' target is executed, e.g. with `make install'. You
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2018-12-29 22:04:38 +03:00
|
|
|
|
2023-10-03 10:19:36 +03:00
|
|
|
|
2016-11-01 18:18:31 +03:00
|
|
|
2.3 Building under Linux with Unix Makefiles
|
|
|
|
-----------------------------------------------
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2017-07-05 20:15:16 +03:00
|
|
|
After unpacking the FLTK source, go to the root of the FLTK tree and type
|
2010-12-20 23:00:44 +03:00
|
|
|
the following.
|
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ..
|
|
|
|
make
|
2016-08-01 15:50:15 +03:00
|
|
|
sudo make install (optional)
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2017-09-06 01:37:07 +03:00
|
|
|
IMPORTANT: The trailing ".." on the cmake command must be specified
|
2020-01-18 16:29:01 +03:00
|
|
|
(it is NOT an ellipsis). ^^^^^^^^^^^^^^^^^
|
2017-09-06 01:37:07 +03:00
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
This will build and install a default configuration FLTK.
|
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
Some flags can be changed during the 'make' command, such as:
|
|
|
|
|
|
|
|
make VERBOSE=on
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
which builds in verbose mode, so you can see all the compile/link commands.
|
2013-05-16 17:29:49 +04:00
|
|
|
|
2016-08-01 15:50:15 +03:00
|
|
|
Hint: if you intend to build several different versions of FLTK, e.g. a Debug
|
2017-07-05 20:15:16 +03:00
|
|
|
and a Release version, or multiple libraries with different ABI versions or
|
|
|
|
options, then use subdirectories in the build directory, like this:
|
2016-08-01 15:50:15 +03:00
|
|
|
|
|
|
|
mkdir build
|
|
|
|
cd build
|
2024-02-07 20:30:11 +03:00
|
|
|
mkdir debug
|
|
|
|
cd debug
|
2017-07-05 20:15:16 +03:00
|
|
|
cmake -D 'CMAKE_BUILD_TYPE=Debug' ../..
|
2016-08-01 15:50:15 +03:00
|
|
|
make
|
|
|
|
sudo make install (optional)
|
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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)
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
- Activate the "app" to execute the command prompt (like an old "DOS" shell)
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
- 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.
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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:
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
`cmake` -G "Visual Studio xxx..." -B build
|
|
|
|
cd build
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
This creates the Visual Studio project files (FLTK.sln and more) in the
|
|
|
|
'build' directory.
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
Open Visual Studio, choose File -> Open -> Project, and pick the "FLTK.sln"
|
|
|
|
created in the previous step.
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
(Or, if only one version of the Visual Studio compiler is installed,
|
|
|
|
you can just run from DOS: .\FLTK.sln)
|
2017-09-06 01:37:07 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
Make sure the pulldown menu has either "Release" or "Debug" selected
|
|
|
|
in the "Solution Configurations" pulldown menu.
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
In the "Solution Explorer", right click on:
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
Solution 'FLTK' (## projects)
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
... and in the popup menu, choose "Build Solution"
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
or choose 'Build/Build Solution' or 'Build/Rebuild Solution' from the
|
|
|
|
menu at the top of the window.
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
That's it, that should build FLTK.
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
The test programs (*.exe) can be found relative to the 'build' folder in
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
build\bin\test\Release\*.exe
|
|
|
|
build\bin\test\Debug\*.exe
|
2017-07-05 20:15:16 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
... and the FLTK include files (*.H & *.h) your own apps can
|
|
|
|
compile with can be found in:
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
build\FL
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
*and* [1] in the source folder where you downloade FLTK, e.g. in
|
2017-07-05 20:15:16 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
C:\fltk-1.4.x\FL
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
... and the FLTK library files (*.lib) which your own apps can
|
|
|
|
link with can be found in:
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
Release: build\lib\Release\*.lib
|
|
|
|
Debug: build\lib\Debug\*.lib
|
2017-03-30 04:52:39 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
[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.
|
2017-07-05 20:15:16 +03:00
|
|
|
|
2022-10-19 09:23:58 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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 .
|
2022-10-19 09:23:58 +03:00
|
|
|
|
2017-03-30 04:52:39 +03:00
|
|
|
|
|
|
|
2.5 Building under Windows with MinGW using Makefiles
|
2016-11-01 18:18:31 +03:00
|
|
|
--------------------------------------------------------
|
|
|
|
|
|
|
|
Building with CMake under MinGW requires you to specify the CMake Generator
|
|
|
|
with the -G command line switch. Using
|
|
|
|
|
|
|
|
cmake -G "Unix Makefiles" /path/to/fltk
|
|
|
|
|
|
|
|
is recommended by the FLTK team if you have installed MinGW with the MSYS
|
|
|
|
environment. You can use the stock Windows CMake executables, but you must
|
|
|
|
run the CMake executables from within the MinGW environment so CMake can
|
|
|
|
use your MinGW PATH to find the compilers and build tools. Example:
|
|
|
|
|
|
|
|
alias cmake='/c/CMake/bin/cmake'
|
|
|
|
alias cmake-gui='/c/CMake/bin/cmake-gui'
|
|
|
|
|
|
|
|
mkdir build
|
|
|
|
cd build
|
2017-07-05 20:15:16 +03:00
|
|
|
cmake -G "Unix Makefiles" -D 'CMAKE_BUILD_TYPE=Debug' ..
|
2016-11-01 18:18:31 +03:00
|
|
|
|
|
|
|
Note the path to FLTK ".." in the last command line. Depending on where you
|
|
|
|
installed CMake you may need to adjust the path's in the alias commands.
|
|
|
|
|
|
|
|
|
2024-07-29 14:05:23 +03:00
|
|
|
2.6 Building under Windows WSL with Clang and Makefiles
|
|
|
|
----------------------------------------------------------
|
|
|
|
|
2024-08-10 21:32:19 +03:00
|
|
|
WSL, the Windows Subsystem for Linux allows developers to run a Linux
|
2024-07-29 14:05:23 +03:00
|
|
|
environment without the need for a separate virtual machine or dual booting.
|
2024-08-10 21:32:19 +03:00
|
|
|
WSL 2 runs inside a managed virtual machine that implements the full
|
2024-07-29 14:05:23 +03:00
|
|
|
Linux kernel. WSL requires Windows 11.
|
|
|
|
|
|
|
|
FLTK apps generated using WSL are Linux compatible binaries. To run those
|
2024-08-10 21:32:19 +03:00
|
|
|
binaries on Windows, WSL comes with a limited built-in X11 server. Third
|
2024-07-29 14:05:23 +03:00
|
|
|
party X11 servers can be installed that better support all features of FLTK.
|
|
|
|
|
2024-08-10 21:32:19 +03:00
|
|
|
1) Install WSL from PowerShell with admin privileges:
|
2024-07-29 14:05:23 +03:00
|
|
|
> wsl --install
|
|
|
|
|
|
|
|
2) Reboot and open the Linux terminal. You will need to install the following
|
|
|
|
Linux apps to compile FLTK
|
|
|
|
> sudo apt update
|
|
|
|
> sudo apt install clang cmake freeglut3-dev
|
|
|
|
|
|
|
|
3) Change to the directory containing the FLTK project. For example:
|
|
|
|
> cd ~/dev/fltk-1.4.x
|
|
|
|
|
|
|
|
4) Use CMake to configure the build system
|
|
|
|
> cmake -B build
|
|
|
|
|
|
|
|
5) Use CMake to build the demo app and all dependencies
|
|
|
|
> cmake --build build
|
|
|
|
|
|
|
|
6) Run the demo app
|
|
|
|
> ./build/bin/test/demo
|
|
|
|
|
|
|
|
|
|
|
|
2.7 Building under MacOS with Xcode
|
|
|
|
--------------------------------------
|
2017-07-05 18:02:43 +03:00
|
|
|
|
|
|
|
Building with CMake under Xcode requires the CMake generator
|
|
|
|
with the -G command line switch. This step need to be done only once. If any
|
2017-07-07 21:28:10 +03:00
|
|
|
of the cmake related files are updated, Xcode will rerun cmake for you.
|
2017-07-05 18:02:43 +03:00
|
|
|
|
|
|
|
1) Open the MacOS Terminal
|
|
|
|
|
|
|
|
2) Change to the directory containing the FLTK project. For example:
|
|
|
|
> cd ~/dev/fltk-1.4.x
|
|
|
|
|
|
|
|
3) Create a build directory
|
|
|
|
> mkdir build
|
|
|
|
> cd build
|
|
|
|
|
|
|
|
4) If you plan different build versions, it is useful to create another
|
|
|
|
subdirectory level
|
|
|
|
> mkdir Xcode
|
|
|
|
> cd Xcode
|
|
|
|
|
2017-07-07 21:28:10 +03:00
|
|
|
5) Let CMake create the required IDE files
|
2017-07-05 18:02:43 +03:00
|
|
|
> cmake -G Xcode ../..
|
|
|
|
This step should end in the message:
|
|
|
|
-- Build files have been written to: .../dev/fltk-1.4.x/build/Xcode
|
|
|
|
|
|
|
|
5a) To build the Release version of FLTK, use
|
|
|
|
> cmake -G Xcode -D CMAKE_BUILD_TYPE=Release ../..
|
|
|
|
|
2017-07-07 21:28:10 +03:00
|
|
|
6) Launch Xcode from the Finder or from the Terminal:
|
2017-07-05 18:02:43 +03:00
|
|
|
> open ./FLTK.xcodeproj
|
2017-07-07 21:28:10 +03:00
|
|
|
When Xcode starts, it asks if it should "Autocreate Schemes". Click on
|
2017-07-05 18:02:43 +03:00
|
|
|
"Automatically Create Schemes" to confirm.
|
|
|
|
|
|
|
|
7) To build and test FLTK, select the scheme "ALL_BUILD" and hit Cmd-B to
|
|
|
|
build. Then select the scheme "demo" and hit Cmd-R to run the FLTK Demo.
|
|
|
|
|
2017-07-07 21:28:10 +03:00
|
|
|
8) The interactive user interface tool "Fluid" will be located in
|
|
|
|
build/Xcode/bin/Debug. The example apps are in .../bin/examples/Debug.
|
2017-07-05 18:02:43 +03:00
|
|
|
Static libraries are in .../lib/Debug/
|
|
|
|
|
|
|
|
9) The "install" Scheme currently fails because it is run with user permission.
|
|
|
|
|
|
|
|
|
2024-07-29 14:05:23 +03:00
|
|
|
2.8 Crosscompiling
|
2016-11-01 18:18:31 +03:00
|
|
|
---------------------
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
Once you have a crosscompiler going, to use CMake to build FLTK you need
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
----
|
2020-01-18 16:29:01 +03:00
|
|
|
# CMake Toolchain File for MinGW-w64 (64-bit) Cross Compilation
|
2019-07-03 14:41:42 +03:00
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
# the name of the target operating system
|
|
|
|
set(CMAKE_SYSTEM_NAME Windows)
|
|
|
|
|
|
|
|
# which tools to use
|
2020-01-18 16:29:01 +03:00
|
|
|
set(CMAKE_C_COMPILER /usr/bin/x86_64-w64-mingw32-gcc)
|
|
|
|
set(CMAKE_CXX_COMPILER /usr/bin/x86_64-w64-mingw32-g++)
|
|
|
|
set(CMAKE_RC_COMPILER /usr/bin/x86_64-w64-mingw32-windres)
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
# here is where the target environment located
|
2020-01-18 16:29:01 +03:00
|
|
|
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
|
|
|
|
|
|
|
|
# adjust the default behavior of the FIND_XXX() commands:
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
# search programs in the host environment
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
2020-01-18 16:29:01 +03:00
|
|
|
|
|
|
|
# search headers and libraries in the target environment
|
2010-12-20 23:00:44 +03:00
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
|
|
|
|
|
|
set(CMAKE_INSTALL_PREFIX ${CMAKE_FIND_ROOT_PATH}/usr CACHE FILEPATH
|
|
|
|
"install path prefix")
|
2019-07-03 14:41:42 +03:00
|
|
|
|
|
|
|
# initialize required linker flags
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++")
|
|
|
|
|
|
|
|
# end of toolchain file
|
2010-12-20 23:00:44 +03:00
|
|
|
----
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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
|
2010-12-20 23:00:44 +03:00
|
|
|
compile the *.fl into C++ source and header files.
|
|
|
|
|
|
|
|
So, again from the FLTK tree root.
|
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
mkdir mingw
|
|
|
|
cd mingw
|
|
|
|
cmake -DCMAKE_TOOLCHAIN_FILE=~/projects/toolchain/Toolchain-mingw32.cmake ..
|
|
|
|
make
|
|
|
|
sudo make install
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2017-09-06 01:37:07 +03:00
|
|
|
IMPORTANT: The trailing ".." on the cmake command must be specified
|
2020-01-18 16:29:01 +03:00
|
|
|
(it is NOT an ellipsis). ^^^^^^^^^^^^^^^^^
|
2017-09-06 01:37:07 +03:00
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
This will create a default configuration FLTK suitable for mingw/msys and
|
2020-01-18 16:29:01 +03:00
|
|
|
install it in the /usr/x86_64-w64-mingw32/usr tree.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2020-01-18 16:29:01 +03:00
|
|
|
Note: replace 'x86_64-w64-mingw32' with your cross toolchain location as
|
|
|
|
required.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
2016-11-01 18:18:31 +03:00
|
|
|
3. Using CMake with FLTK
|
|
|
|
===========================
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2014-09-27 04:41:06 +04:00
|
|
|
The CMake Export/Import facility can be thought of as an automated
|
2024-02-07 20:30:11 +03:00
|
|
|
fltk-config. For example, if you link your program to the FLTK
|
|
|
|
library, it will automatically link in all of its dependencies. This
|
2016-11-01 18:18:31 +03:00
|
|
|
includes any special flags, i.e. on Linux it includes the -lpthread flag.
|
2014-09-27 04:41:06 +04:00
|
|
|
|
2023-10-31 18:04:31 +03:00
|
|
|
This howto assumes that you have FLTK libraries which were built using CMake,
|
2024-02-07 20:30:11 +03:00
|
|
|
installed. Building them with CMake generates some CMake helper files which
|
2023-10-31 18:04:31 +03:00
|
|
|
are installed in standard locations, making FLTK easy to find and use.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2023-10-31 18:04:31 +03:00
|
|
|
In the following examples we set the CMake cache variable 'FLTK_DIR' so
|
|
|
|
CMake knows where to find the FLTK configuration file 'FLTKConfig.cmake'.
|
|
|
|
It is important (recommended practice) to set this as a CMake cache variable
|
|
|
|
which enables the user executing 'cmake' to override this path either on the
|
|
|
|
commandline or interactively using the CMake GUI 'cmake-gui' or 'ccmake' on
|
|
|
|
Unix/Linux, for instance like this:
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2023-10-31 18:04:31 +03:00
|
|
|
$ mkdir build
|
|
|
|
$ cd build
|
|
|
|
$ cmake -G "Unix Makefiles" -S.. -D "FLTK_DIR=/home/me/fltk"
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
2023-10-31 18:04:31 +03:00
|
|
|
3.1 Library Names
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
When you use the target_link_libraries() command, CMake uses its own internal
|
2024-02-07 20:30:11 +03:00
|
|
|
"target names" for libraries. The original fltk library names in the build
|
|
|
|
tree are:
|
2023-10-31 18:04:31 +03:00
|
|
|
|
|
|
|
fltk fltk_forms fltk_images fltk_gl
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
The bundled image and zlib libraries (if built):
|
2023-10-31 18:04:31 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
fltk_jpeg fltk_png fltk_z
|
2023-10-31 18:04:31 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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
|
|
|
|
------------------------------------
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2015-04-07 18:18:35 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2014-09-27 04:41:06 +04:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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
|
2023-10-31 18:04:31 +03:00
|
|
|
--------------------------------------------------------
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2023-10-31 18:04:31 +03:00
|
|
|
|
|
|
|
---
|
|
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
|
|
|
|
project(hello)
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
# optional (see below):
|
2023-10-31 18:04:31 +03:00
|
|
|
set(FLTK_DIR "/path/to/fltk"
|
|
|
|
CACHE FILEPATH "FLTK installation or build directory")
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
find_package(FLTK CONFIG REQUIRED)
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
add_executable (hello WIN32 MACOSX_BUNDLE hello.cxx)
|
|
|
|
target_link_libraries(hello PRIVATE fltk::fltk)
|
2023-10-31 18:04:31 +03:00
|
|
|
---
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2020-11-23 19:22:45 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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=...).
|
2020-11-23 19:22:45 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2016-11-01 18:18:31 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
3.5 Building a Program Using Fluid Files
|
2023-10-31 18:04:31 +03:00
|
|
|
-------------------------------------------
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
CMake has a command named fltk_wrap_ui which helps deal with fluid *.fl
|
2021-04-29 19:32:19 +03:00
|
|
|
files. Unfortunately it is broken in CMake 3.4.x but it seems to work in
|
2023-10-31 18:04:31 +03:00
|
|
|
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.
|
2024-02-07 20:30:11 +03:00
|
|
|
It is described below.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2016-02-02 03:49:51 +03:00
|
|
|
Here is a sample CMakeLists.txt which compiles the CubeView example from
|
|
|
|
a directory you've copied the test/Cube* files to.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2016-02-02 03:49:51 +03:00
|
|
|
---
|
2023-10-31 18:04:31 +03:00
|
|
|
cmake_minimum_required(VERSION 3.15)
|
2016-02-02 03:49:51 +03:00
|
|
|
|
|
|
|
project(CubeView)
|
|
|
|
|
2016-08-01 15:50:15 +03:00
|
|
|
# change this to your fltk build directory
|
2023-10-31 18:04:31 +03:00
|
|
|
set(FLTK_DIR "/path/to/fltk"
|
|
|
|
CACHE FILEPATH "FLTK installation or build directory")
|
2016-02-02 03:49:51 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
find_package(FLTK CONFIG REQUIRED)
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2023-10-31 18:04:31 +03:00
|
|
|
# run fluid -c to generate CubeViewUI.cxx and CubeViewUI.h files
|
2016-02-02 03:49:51 +03:00
|
|
|
add_custom_command(
|
2023-10-31 18:04:31 +03:00
|
|
|
OUTPUT "CubeViewUI.cxx" "CubeViewUI.h"
|
2024-02-07 20:30:11 +03:00
|
|
|
COMMAND fltk::fluid -c ${CMAKE_CURRENT_SOURCE_DIR}/CubeViewUI.fl
|
2016-02-02 03:49:51 +03:00
|
|
|
)
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2023-10-31 18:04:31 +03:00
|
|
|
add_executable(CubeView WIN32 MACOSX_BUNDLE
|
2024-02-07 20:30:11 +03:00
|
|
|
CubeMain.cxx CubeView.cxx CubeViewUI.cxx)
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
target_include_directories(CubeView PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
target_include_directories(CubeView PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
2023-10-31 18:04:31 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
target_link_libraries (CubeView PRIVATE fltk::gl)
|
2016-02-02 03:49:51 +03:00
|
|
|
---
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2020-06-13 16:19:27 +03:00
|
|
|
You can repeat the add_custom_command for each fluid file or if you
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2016-11-01 23:45:42 +03:00
|
|
|
The two lines
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
target_include_directories(CubeView PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
target_include_directories(CubeView PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
2016-11-01 23:45:42 +03:00
|
|
|
|
|
|
|
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
|
2024-02-07 20:30:11 +03:00
|
|
|
current build directory and other header files may be in the source directory
|
|
|
|
(depending on your project).
|
2016-11-01 23:45:42 +03:00
|
|
|
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
3.6 Building a Program Using CMake's FetchContent Module
|
2023-10-31 18:04:31 +03:00
|
|
|
-----------------------------------------------------------
|
|
|
|
|
|
|
|
FLTK can be downloaded and built within a user project using CMake's
|
|
|
|
FetchContent module. A sample CMakeLists.txt file follows.
|
|
|
|
|
|
|
|
You may need to adjust it to your configuration.
|
|
|
|
|
|
|
|
---
|
|
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
project(hello)
|
|
|
|
|
|
|
|
include(FetchContent)
|
|
|
|
|
|
|
|
FetchContent_Declare(FLTK
|
2024-02-07 20:30:11 +03:00
|
|
|
GIT_REPOSITORY https://github.com/fltk/fltk
|
|
|
|
GIT_TAG master
|
|
|
|
GIT_SHALLOW TRUE
|
2023-10-31 18:04:31 +03:00
|
|
|
)
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
message(STATUS "Download and build FLTK if necessary, please wait...")
|
|
|
|
FetchContent_MakeAvailable(FLTK)
|
|
|
|
message(STATUS "Download and build FLTK - done.")
|
2023-10-31 18:04:31 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
add_executable (hello WIN32 MACOSX_BUNDLE hello.cxx)
|
|
|
|
target_link_libraries(hello PRIVATE fltk::fltk)
|
|
|
|
---
|
2023-10-31 18:04:31 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2023-10-31 18:04:31 +03:00
|
|
|
|
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
4 FindFLTK.cmake and find_package(FLTK)
|
|
|
|
==========================================
|
2023-10-31 18:04:31 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2023-10-31 18:04:31 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2024-02-07 20:30:11 +03:00
|
|
|
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...
|