cmake find_package causes error

56 views
Skip to first unread message

supsm17

unread,
Mar 25, 2022, 4:03:06 AM3/25/22
to fltk.general
Hello,
Currently I am using FLTK in my cmake project. I would like to use a preexisting install if found, and build from source if it isn't found. To do this I added the following code to my CMakeLists.txt:
find_package(FLTK 1.3.6 EXACT) # Removing this line will make the error disappear if (NOT FLTK_FOUND) set(FLTK_BUILD_TEST FALSE CACHE BOOL "Build test/demo programs" FORCE) # Don't tmake fltk build tests set(OPTION_BUILD_HTML_DOCUMENTATION FALSE CACHE BOOL "build html docs" FORCE) # Don't build fltk docs add_subdirectory("lib/fltk/fltk-1.3.6") endif ()
This works fine on a system with fltk installed, but if it isn't installed and I try to configure, it prints all the usual "checking size of..." etc then outputs this error:
CMake Error at lib/fltk/fltk-1.3.6/CMake/export.cmake:46 (export): export given target "FLTK_IMAGES_LIBRARY-NOTFOUND" which is not built by this project. Call Stack (most recent call first): lib/fltk/fltk-1.3.6/CMakeLists.txt:119 (include)
My guess would be that find_packages has set some environment variable that's messing with the fltk CMake. How could I go about fixing this?

Ian MacArthur

unread,
Mar 25, 2022, 4:34:46 AM3/25/22
to fltk.general
Hmm, I'm not strong on cmake (Albrecht probably has better ideas on this topic) but I'd caution that fltk-1.3 in general (including 1.3.6) has somewhat "provisional" cmake support and it is entirely possible that the problems you are seeing stem from that - which is to say it make be because the fltk-1.3 cmake scripts are not doing quite what is expected of them...

 But I do not know...

Albrecht Schlosser

unread,
Mar 25, 2022, 8:34:09 AM3/25/22
to fltkg...@googlegroups.com
On 3/25/22 06:55 supsm17 wrote:
Currently I am using FLTK in my cmake project. I would like to use a preexisting install if found, and build from source if it isn't found. To do this I added the following code to my CMakeLists.txt:
find_package(FLTK 1.3.6 EXACT) # Removing this line will make the error disappear

First of all, this statement is not the recommended way to find FLTK with CMake since 1.3.x (see README.CMake.txt), and I'm not sure it will find the correct version of FLTK anyway.

But putting this aside I suggest to upgrade to 1.3.8 rather than using 1.3.6 anyway.


if (NOT FLTK_FOUND) set(FLTK_BUILD_TEST FALSE CACHE BOOL "Build test/demo programs" FORCE) # Don't tmake fltk build tests set(OPTION_BUILD_HTML_DOCUMENTATION FALSE CACHE BOOL "build html docs" FORCE) # Don't build fltk docs add_subdirectory("lib/fltk/fltk-1.3.6") endif ()
This works fine on a system with fltk installed, but if it isn't installed and I try to configure, it prints all the usual "checking size of..." etc then outputs this error:
CMake Error at lib/fltk/fltk-1.3.6/CMake/export.cmake:46 (export): export given target "FLTK_IMAGES_LIBRARY-NOTFOUND" which is not built by this project. Call Stack (most recent call first): lib/fltk/fltk-1.3.6/CMakeLists.txt:119 (include)

I can't find the relevant statement at line 46 in CMake/export.cmake, neither in 1.3.6 nor 1.3.8 nor git branch-1.3, but I assume it is line 44 in current git: export(TARGETS ${FLUID} ${FLTK_LIBRARIES} FILE ${CMAKE_CURRENT_BINARY_DIR}/FLTK-Targets.cmake) Can you confirm that this is the offending statement in your version?
My guess would be that find_packages has set some environment variable that's messing with the fltk CMake. How could I go about fixing this?

If my assumption above is true then you might succeed if you set 'FLTK_LIBRARIES' to an empty string before you use 'add_subdirectory("lib/fltk/fltk-1.3.6")' as described above. This is based on the fact that we add our libraries to this variable but I don't see that it is initialized - and thus it may use the result set by 'find_package(FLTK 1.3.6 EXACT)' which *might* set this variable. If this doesn't help you can use a simple statement to add some debugging info to our FLTK CMake files (using a defined macro), like fl_debug_var(FLTK_LIBRARIES) in appropriate places to debug this further. Note that you use the variable name as a string. In your own CMake part you can use standard 'message(STATUS ...)' CMake commands instead. If you can confirm that this fixes the issue for you then I can add the missing initialization to the FLTK CMake files. Thanks for pointing this out.

supsm17

unread,
Mar 26, 2022, 6:29:25 AM3/26/22
to fltk.general
Yes that is the correct line. Also, adding set(FLTK_LIBRARIES "") before add_subdirectory works. Thanks for the help.

Albrecht Schlosser

unread,
Mar 28, 2022, 4:02:28 PM3/28/22
to fltkg...@googlegroups.com
On 3/26/22 01:41 supsm17 wrote:
Yes that is the correct line. Also, adding set(FLTK_LIBRARIES "") before add_subdirectory works. Thanks for the help.

Fixed in FLTK 1.4.0, git commit 3fb66056d6b9d95e4332be38d55e52e83190400f.



On Friday, March 25, 2022 at 5:34:09 AM UTC-7 Albrecht Schlosser wrote:
On 3/25/22 06:55 supsm17 wrote:
Currently I am using FLTK in my cmake project. I would like to use a preexisting install if found, and build from source if it isn't found. To do this I added the following code to my CMakeLists.txt:
find_package(FLTK 1.3.6 EXACT) # Removing this line will make the error disappear
...

if (NOT FLTK_FOUND) set(FLTK_BUILD_TEST FALSE CACHE BOOL "Build test/demo programs" FORCE) # Don't tmake fltk build tests set(OPTION_BUILD_HTML_DOCUMENTATION FALSE CACHE BOOL "build html docs" FORCE) # Don't build fltk docs add_subdirectory("lib/fltk/fltk-1.3.6") endif ()
This works fine on a system with fltk installed, but if it isn't installed and I try to configure, it prints all the usual "checking size of..." etc then outputs this error:
CMake Error at lib/fltk/fltk-1.3.6/CMake/export.cmake:46 (export): export given target "FLTK_IMAGES_LIBRARY-NOTFOUND" which is not built by this project. Call Stack (most recent call first): lib/fltk/fltk-1.3.6/CMakeLists.txt:119 (include)
... you might succeed if you set 'FLTK_LIBRARIES' to an empty string before you use 'add_subdirectory("lib/fltk/fltk-1.3.6")' as described above. This is based on the fact that we add our libraries to this variable but I don't see that it is initialized - and thus it may use the result set by 'find_package(FLTK 1.3.6 EXACT)' which *might* set this variable.

Reply all
Reply to author
Forward
0 new messages