On 15.08.2016 13:40 Ibrahim A wrote:
> I am trying to build a simple example for using fltk. The building works
> only when I use fltk-config but it does not work when I use cmake. I
> tried many google suggestions but I always get different types of
> errors. Your suggestion shall be appreciated.
First of all, FLTK's CMake support is still in development and not yet
officially supported. Particularly the latest stable release (1.3.3)
lacks many fixes that have been applied since in FLTK 1.3.4 (svn).
Please use a weekly tarball (snapshot) from the download page or use
current svn or git (github/fltk/test-only).
I tried your example with svn current, and I had to fix a few things in
CMakeLists.txt, but then I could build it. Note that your example does
not actually use OpenGL, so if you add OpenGL code there may be more to
change, but for now your example works for me with FLKT svn and this
CMake file:
#----------------------------------------------------------------------
# CMakeLists.txt
#----------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(ui)
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
set (FLTK_DIR "~/git/fltk/build/Debug") # use _your_ FLTK path here
FIND_PACKAGE(FLTK REQUIRED NO_MODULE) # must use "NO_MODULE"
# diagnostics (optional)
# message(STATUS "FLTK_INCLUDE_DIRS = '${FLTK_INCLUDE_DIRS}'")
# message(STATUS "FLTK_LIBRARIES = '${FLTK_LIBRARIES}'")
# message(STATUS "FLTK_FLUID_EXECUTABLE = '${FLTK_FLUID_EXECUTABLE}'")
include_directories(${FLTK_INCLUDE_DIRS})
link_directories(${FLTK_LIBRARY_DIRS})
add_definitions(${FLTK_DEFINITIONS})
ADD_EXECUTABLE( ui ui.cxx )
# Note: ${FLTK_LIBRARIES} is not yet defined in FLTK 1.3.x - to be fixed
later
# TARGET_LINK_LIBRARIES( ui ${FLTK_LIBRARIES} ${OPENGL_LIBRARIES})
# use the imported target 'fltk' instead:
TARGET_LINK_LIBRARIES( ui fltk ${OPENGL_LIBRARIES})
--- snip ---
Notes:
(1) See README.CMake.txt for more information how to use FLTK 1.3.x
with CMake, and see comments in my version of your CMakeLists.txt
file above.
(2) Particularly you *may* need to set FLTK_DIR to point CMake to
your FLTK version. Otherwise CMake might find another installed
Version, and this *will* not work.
(3) Please use NO_MODULE in FIND_PACKAGE. This ensures that the
Find_FLTK module bundled with CMake is NOT used (it is designed
for FLTK 1.1 and doesn't work with FLTK 1.3).
(4) FLTK's CMake setup file (FLTKConfig.cmake) obviously does
not yet set FLTK_LIBRARIES as expected. However we define an
imported target 'fltk' that can be used for now. This will
definitely be fixed in FLTK 1.4, but I don't know if this will
also be fixed in FLTK 1.3.4 (the next and last release in the
1.3.x series).