Okay, I'll try. But note that I don't have MacOS.
First of all, if you want to use FLTK in your project(s) with CMake then
the best bet is to build FLTK with CMake as well because it provides
FLTKConfig.cmake so you can easily "import" the FLTK include and library
definitions.
Whether you install FLTK somewhere (with make install) or use it
directly from its build directory you should always set FLTK_DIR to
point at the directory where FLTKConfig.cmake resides. Unfortunately
this is not consistent if you use the build directory or if you install
FLTK (the directory layout appears to be platform dependent, at least in
FLTK 1.3.4 - I'll take a look into it for FLTK 1.4.0 and later).
That said: in the build directory FLTKConfig.cmake must always be used
in the root of the build directory, hence FLTK_DIR must point at the
build root. The other FLTKConfig.cmake you may find
(<build>/etc/FLTKConfig.cmake) is for use when FLTK gets installed.
If FLTK was installed, look for FLTKConfig.cmake in or "below" the
install directory.
In my Linux system this is <prefix>/share/fltk/
(/usr/local/fltk-1.3.4/share/fltk/), under Windows this is obviously
different (:-(),
it's <prefix>/CMake.
That said, I have a (not that) simple CMakeLists.txt that builds the
CubeView test program. To do that I copied the necessary source files
and config.h (!) from the FLTK source/test and build directories, resp..
config.h is only necessary since the CubeView code uses it, but it is
not installed because it is a private FLTK file. Since this is a demo I
simply copied it. Note that config.h is only necessary if FLTK was
installed; the build works w/o it if the build uses the build directory
directly.
Here's my build environment and CMakeLists.txt:
$ ls
CMakeLists.txt config.h CubeMain.cxx CubeView.cxx CubeView.h
CubeViewUI.fl
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.6.3)
project(CubeView)
# change this to your fltk build directory
# set(FLTK_DIR ~/git/fltk-1.3/build/Debug/)
set(FLTK_DIR /usr/local/fltk-1.3.4/share/fltk/)
find_package(FLTK REQUIRED NO_MODULE)
include_directories(${FLTK_INCLUDE_DIRS})
#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
)
set (DEBUG_FLTK 1)
if (DEBUG_FLTK)
message(STATUS "FLTK_INCLUDE_DIRS = '${FLTK_INCLUDE_DIRS}'")
message(STATUS "CMAKE_SOURCE_DIR = '${CMAKE_SOURCE_DIR}'")
message(STATUS "CMAKE_CURRENT_SOURCE_DIR = '${CMAKE_CURRENT_SOURCE_DIR}'")
message(STATUS "CMAKE_BINARY_DIR = '${CMAKE_BINARY_DIR}'")
message(STATUS "CMAKE_CURRENT_BINARY_DIR = '${CMAKE_CURRENT_BINARY_DIR}'")
endif ()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(CubeView WIN32 CubeMain.cxx CubeView.cxx CubeViewUI.cxx)
target_link_libraries(CubeView fltk fltk_gl)
# End of CMakeLists.txt
$ mkdir build
$ cd build/
$ cmake ..
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- FLTK_INCLUDE_DIRS = '/usr/local/fltk-1.3.4/include'
-- CMAKE_SOURCE_DIR = '~/testprogramme/fltk-cubeview'
-- CMAKE_CURRENT_SOURCE_DIR = '~/testprogramme/fltk-cubeview'
-- CMAKE_BINARY_DIR = '~/testprogramme/fltk-cubeview/build'
-- CMAKE_CURRENT_BINARY_DIR = '~/testprogramme/fltk-cubeview/build'
-- Configuring done
-- Generating done
-- Build files have been written to: ~/testprogramme/fltk-cubeview/build
$ make
[ 25%] Generating CubeViewUI.cxx, CubeViewUI.h
Scanning dependencies of target CubeView
[ 50%] Building CXX object CMakeFiles/CubeView.dir/CubeMain.cxx.o
[ 75%] Building CXX object CMakeFiles/CubeView.dir/CubeView.cxx.o
[100%] Building CXX object CMakeFiles/CubeView.dir/CubeViewUI.cxx.o
Linking CXX executable CubeView
[100%] Built target CubeView
$
That's it. HTH