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
|
|
|
|
==========
|
|
|
|
|
2015-04-07 18:18:35 +03:00
|
|
|
1 INTRODUCTION TO CMAKE
|
|
|
|
2 USING CMAKE TO BUILD FLTK
|
2010-12-20 23:00:44 +03:00
|
|
|
2.1 Prerequisites
|
|
|
|
2.2 Options
|
|
|
|
2.3 Building under Linux with Unix Makefiles
|
|
|
|
2.4 Crosscompiling
|
2015-04-07 18:18:35 +03:00
|
|
|
3 USING CMAKE WITH FLTK
|
2010-12-20 23:00:44 +03:00
|
|
|
3.1 Library names
|
|
|
|
3.2 Using Fluid files
|
2015-04-07 18:18:35 +03:00
|
|
|
4 DOCUMENT HISTORY
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
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
|
|
|
|
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-gui will also let you change options interactively.
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
CMakeCache.txt file in the source root.
|
|
|
|
|
|
|
|
More information on CMake can be found on its web site http://www.cmake.org.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
USING CMAKE TO BUILD FLTK
|
|
|
|
===========================
|
|
|
|
|
|
|
|
|
|
|
|
PREREQUISITES
|
|
|
|
---------------
|
|
|
|
|
|
|
|
The prerequisites for building FLTK with CMake are staightforward:
|
2015-04-07 18:18:35 +03:00
|
|
|
CMake 2.6 or later and a recent FLTK 1.3 release, snapshot, or subversion
|
|
|
|
download (working copy). Installation of CMake is covered on its web site.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
This howto will cover building FLTK with the default options using cmake
|
|
|
|
under Linux with both the default Unix Makefiles and a MinGW cross compiling
|
|
|
|
toolchain. Other platforms are just as easy to use.
|
|
|
|
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
---------
|
2013-05-16 17:29:49 +04:00
|
|
|
Options can be specified to cmake with the -D flag:
|
|
|
|
|
|
|
|
cmake -D <OPTION_NAME>=<OPTION_VALUE>
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
cmake -D CMAKE_BUILD_TYPE=Debug
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
All options have sensible defaults so you won't usually need to touch these.
|
2013-05-16 17:29:49 +04:00
|
|
|
There are only two 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
|
2013-05-16 17:29:49 +04:00
|
|
|
Where everything will go on install. Defaults are /usr/local for unix
|
|
|
|
and C:\Program Files\FLTK for Windows.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
The following are the FLTK specific options. Platform specific options
|
|
|
|
are ignored on other platforms.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
OPTION_OPTIM
|
|
|
|
Extra optimization flags.
|
2013-05-16 17:29:49 +04:00
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
OPTION_ARCHFLAGS
|
|
|
|
Extra architecture flags.
|
|
|
|
|
|
|
|
OPTION_APPLE_X11 - default OFF
|
2015-12-31 09:19:59 +03:00
|
|
|
In case you want to use X11 on OSX.
|
|
|
|
Use this only if you know what you do, and if you have installed X11.
|
2013-05-16 17:29:49 +04:00
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
OPTION_USE_POLL - default OFF
|
|
|
|
Don't use this one either.
|
|
|
|
|
|
|
|
OPTION_BUILD_SHARED_LIBS - default OFF
|
|
|
|
Normally FLTK is built as static libraries which makes more portable
|
2013-05-16 17:29:49 +04:00
|
|
|
binaries. If you want to use shared libraries, this will build them too.
|
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
OPTION_BUILD_EXAMPLES - default ON
|
|
|
|
Builds the many fine example programs.
|
|
|
|
|
|
|
|
OPTION_CAIRO - default OFF
|
|
|
|
Enables libcairo support
|
2013-05-16 17:29:49 +04:00
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
OPTION_CAIROEXT - default OFF
|
|
|
|
Enables extended libcairo support
|
|
|
|
|
|
|
|
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
|
|
|
|
OPTION_USE_SYSTEM_ZLIB - default ON
|
|
|
|
OPTION_USE_SYSTEM_LIBPNG - default ON
|
2015-04-07 18:18:35 +03:00
|
|
|
FLTK has built in jpeg, zlib, and png libraries. These 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.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
OPTION_USE_XINERAMA - default ON
|
|
|
|
OPTION_USE_XFT - default ON
|
|
|
|
OPTION_USE_XDBE - default ON
|
2013-05-16 17:29:49 +04:00
|
|
|
These are X11 extended libraries.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
BUILDING UNDER LINUX WITH UNIX MAKEFILES
|
|
|
|
------------------------------------------
|
|
|
|
|
|
|
|
After untaring the FLTK source, go to the root of the FLTK tree and type
|
|
|
|
the following.
|
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ..
|
|
|
|
make
|
|
|
|
sudo make install
|
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
|
|
|
|
|
|
|
|
..which builds in verbose mode, so you can see all the compile/link commands.
|
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
CROSSCOMPILING
|
|
|
|
----------------
|
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
Once you have a crosscompiler going, to use CMake to build FLTK you need
|
2010-12-20 23:00:44 +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 mine for MinGW under Linux.
|
|
|
|
|
2013-05-16 17:29:49 +04: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
|
|
|
|
set(CMAKE_C_COMPILER /usr/bin/i486-mingw32-gcc)
|
|
|
|
set(CMAKE_CXX_COMPILER /usr/bin/i486-mingw32-g++)
|
|
|
|
|
|
|
|
# here is where the target environment located
|
|
|
|
set(CMAKE_FIND_ROOT_PATH /usr/i486-mingw32)
|
|
|
|
|
|
|
|
# adjust the default behaviour of the FIND_XXX() commands:
|
|
|
|
# search programs in the host environment
|
|
|
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
|
|
|
# search headers and libraries in the target environment,
|
|
|
|
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")
|
|
|
|
----
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
|
|
This will create a default configuration FLTK suitable for mingw/msys and
|
|
|
|
install it in the /usr/i486-mingw32/usr tree.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
USING CMAKE WITH FLTK
|
|
|
|
=======================
|
|
|
|
|
2014-09-27 04:41:06 +04:00
|
|
|
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
|
|
|
|
includes any special flags. ie on Linux it includes the -lpthread flag.
|
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
This howto assumes that you have FLTK libraries which were built using
|
|
|
|
CMake, installed. Building them with CMake generates some CMake helper
|
|
|
|
files which are installed in standard locations, making FLTK easy to find
|
|
|
|
and use.
|
|
|
|
|
|
|
|
Here is a basic CMakeLists.txt file using FLTK.
|
|
|
|
|
|
|
|
------
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 2.6)
|
|
|
|
|
|
|
|
project(hello)
|
|
|
|
|
2015-04-07 18:18:35 +03:00
|
|
|
# The following line is required only if (a) you didn't install FLTK
|
|
|
|
# or if (b) find_package can't find your installation directory because
|
|
|
|
# you installed FLTK in a non-standard location. It points to
|
|
|
|
# (a) the base folder of the build directory, or
|
|
|
|
# (b) <fltk-install-prefix>/share/fltk
|
|
|
|
# resp., where <fltk-install-prefix> is the installation prefix you
|
|
|
|
# used to install FLTK.
|
|
|
|
# (The file FLTKConfig.cmake and others must be found in that path.)
|
|
|
|
|
2014-09-27 04:41:06 +04:00
|
|
|
set(FLTK_DIR /path/to/fltk)
|
|
|
|
|
2010-12-20 23:00:44 +03:00
|
|
|
find_package(FLTK REQUIRED NO_MODULE)
|
|
|
|
include(${FLTK_USE_FILE})
|
|
|
|
|
|
|
|
add_executable(hello WIN32 hello.cxx)
|
|
|
|
|
|
|
|
target_link_libraries(hello fltk)
|
|
|
|
|
|
|
|
------
|
|
|
|
|
2014-09-27 04:41:06 +04:00
|
|
|
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.
|
2010-12-20 23:00:44 +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. NO_MODULE 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.
|
|
|
|
|
|
|
|
Once the package is found we include the ${FLTK_USE_FILE} which adds the
|
2014-09-27 04:41:06 +04:00
|
|
|
FLTK include directories to its knowledge base. After that your programs
|
|
|
|
will be able to find FLTK headers.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
The WIN32 in the add_executable tells your Windows compiler that this is
|
|
|
|
a gui app. It is ignored on other platforms.
|
|
|
|
|
|
|
|
LIBRARY NAMES
|
|
|
|
---------------
|
|
|
|
|
|
|
|
When you use the target_link_libraries command, CMake uses it's own
|
|
|
|
internal names for libraries. The fltk library names are:
|
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
fltk fltk_forms fltk_images fltk_gl
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
and for the shared libraries (if built):
|
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
fltk_SHARED fltk_forms_SHARED fltk_images_SHARED fltk_gl_SHARED
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
The built-in libraries (if built):
|
|
|
|
|
2013-05-16 17:29:49 +04:00
|
|
|
fltk_jpeg fltk_png fltk_z
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
USING FLUID FILES
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
CMake has a command named fltk_wrap_ui which helps deal with fluid *.fl
|
2016-02-02 03:46:43 +03:00
|
|
|
files. Unfortunately it is broken in CMake 3.4.x. You can however use
|
|
|
|
add_custom_command to achieve the same result.
|
|
|
|
This is a more basic approach and should work for all CMake versions.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2016-02-02 03:46:43 +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:46:43 +03:00
|
|
|
---
|
|
|
|
cmake_minimum_required(VERSION 2.6)
|
|
|
|
|
|
|
|
project(CubeView)
|
|
|
|
|
|
|
|
# change this to your fltk buid directory
|
|
|
|
set(FLTK_DIR /home/msurette/build/fltk-release/)
|
|
|
|
|
|
|
|
find_package(FLTK REQUIRED NO_MODULE)
|
|
|
|
include(${FLTK_USE_FILE})
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2016-02-02 03:46:43 +03:00
|
|
|
#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
|
|
|
|
)
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2016-02-02 03:46:43 +03:00
|
|
|
include_directories(${CMAKE_BINARY_DIR})
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR})
|
|
|
|
add_executable(CubeView WIN32 CubeMain.cxx CubeView.cxx CubeViewUI.cxx)
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2016-02-02 03:46:43 +03:00
|
|
|
target_link_libraries(CubeView fltk fltk_gl)
|
|
|
|
---
|
2010-12-20 23:00:44 +03:00
|
|
|
|
2016-02-02 03:46:43 +03:00
|
|
|
You can repeat the add_custom_command for each fluid file or if you have
|
|
|
|
a large number of them see the CMake/macros.cmake function FLTK_RUN_FLUID
|
|
|
|
for an example of how to run it in a loop.
|
2010-12-20 23:00:44 +03:00
|
|
|
|
|
|
|
DOCUMENT HISTORY
|
|
|
|
==================
|
|
|
|
|
|
|
|
Dec 20 2010 - matt: merged and restructures
|
2013-05-16 17:29:49 +04:00
|
|
|
May 15 2013 - erco: small formatting tweaks, added some examples
|
2014-09-27 04:41:06 +04:00
|
|
|
Feb 23 2014 - msurette: updated to reflect changes to the CMake files
|
2015-04-07 18:18:35 +03:00
|
|
|
Apr 07 2015 - AlbrechtS: update use example and more docs
|
2016-02-02 03:46:43 +03:00
|
|
|
Jan 31 2016 - msurette: custom command instead of fltk_wrap_ui
|