Using CMake to build a user app under macOS

41 views
Skip to first unread message

Manolo

unread,
Sep 2, 2020, 5:02:08 AM9/2/20
to fltk.coredev

I'm trying to build a small FLTK-using app with cmake under macOS.
Following README.CMake.txt, section 3, I prepared this CMakeLists.txt:

cmake_minimum_required(VERSION 2.6.3)
project(small)
set(FLTK_DIR /Volumes/Extra) # the BUILD dir of FLTK
find_package(FLTK REQUIRED NO_MODULE)
add_executable(small MACOSX_BUNDLE small.cxx)
target_include_directories(small PUBLIC ${FLTK_INCLUDE_DIRS})
target_link_libraries(small fltk)

With it, the build fails at link step (compilation step is good) in that
all macOS-defined symbols are missing.
If I replace the last line of CMakeLists.txt by

      target_link_libraries(small fltk  "-framework Cocoa")

the build succeeds, and a functional macOS bundle is produced.

I had expected cmake to be smart enough to know from
find_package(FLTK REQUIRED NO_MODULE)
that "-framework Cocoa" was necessary in link commands.
Is that incorrect?

Albrecht Schlosser

unread,
Sep 2, 2020, 6:46:23 AM9/2/20
to fltkc...@googlegroups.com
On 9/2/20 11:02 AM Manolo wrote:
>
> I'm trying to build a small FLTK-using app with cmake under macOS.
> Following README.CMake.txt, section 3, I prepared this CMakeLists.txt:
>
> cmake_minimum_required(VERSION 2.6.3)
> project(small)
> set(FLTK_DIR /Volumes/Extra) # the BUILD dir of FLTK
> find_package(FLTK REQUIRED NO_MODULE)
> add_executable(small MACOSX_BUNDLE small.cxx)
> target_include_directories(small PUBLIC ${FLTK_INCLUDE_DIRS})
> target_link_libraries(small fltk)
>
> With it, the build fails at link step (compilation step is good) in that
> all macOS-defined symbols are missing.
> If I replace the last line of CMakeLists.txt by
>
>       target_link_libraries(small fltk  "-framework Cocoa")
>
> the build succeeds, and a functional macOS bundle is produced.

That's great (I mean, that it works so far as documented), however we
need to document this (for now, see below).

> I had expected cmake to be smart enough to know from
> find_package(FLTK REQUIRED NO_MODULE)
> that "-framework Cocoa" was necessary in link commands.
> Is that incorrect?

For now this is not possible. Our CMake code is still "classic" mode
which means that we can't (or do not (yet)) provide "interface
dependencies" of the FLTK libraries to the user.

In a (hopefully near) future version we may switch to "modern CMake"
which provides "targets" with link interface dependencies to the
consumer of the FLTK libs.

The prerequisite is CMake 3.0 or later (we're now at minimum 3.2.3 but
this may need to be changed) and the FLTK CMake code needs to be updated
in some parts. This is something I have on my todo list for the near
future. I'm still investigating what exactly we need to do though...

Manolo

unread,
Sep 2, 2020, 7:05:02 AM9/2/20
to fltk.coredev
On Wednesday, September 2, 2020 at 12:46:23 PM UTC+2 Albrecht Schlosser wrote:
On 9/2/20 11:02 AM Manolo wrote:

> I had expected cmake to be smart enough to know from
> find_package(FLTK REQUIRED NO_MODULE)
> that "-framework Cocoa" was necessary in link commands.
> Is that incorrect?

For now this is not possible. Our CMake code is still "classic" mode
which means that we can't (or do not (yet)) provide "interface
dependencies" of the FLTK libraries to the user.

Thanks for the explanation.
For now, it's also possible to build that app under macOS using the fltk-config script
CMake produced.

Greg Ercolano

unread,
Nov 1, 2020, 4:07:13 PM11/1/20
to fltkc...@googlegroups.com
On 2020-09-02 03:46, Albrecht Schlosser wrote:
>
> The prerequisite is CMake 3.0 or later (we're now at minimum 3.2.3 but
> this may need to be changed) and the FLTK CMake code needs to be updated
> in some parts.


    I updated the README.CMake.txt to reflect the current 3.2.3 requirement (commit 7d126461e)
    as I got caught by this doing some tests today.

Reply all
Reply to author
Forward
0 new messages