[cmake-developers] Best practice for determining if a static library was found and other issues with FindFLTK.cmake
Richard Shaw
hobbes1069 at gmail.com
Wed Sep 3 09:48:29 EDT 2014
I'm probably going to end up taking over the module since it seems to be
un-maintained but I'm hesitant to make radical changes to it.
The module has several issues but a major one is that it doesn't add the
required linker flags when using static libraries instead of shared.
It also doesn't check for any required C flags but that's a lesser issue.
These may only be a problem for the autotools based fltk build as the
module uses a ConfigFLTK for CMake based builds.
I have the following config to work around the issue which I'd like to
ultimately get into the module and out of my cmake config:
find_package(FLTK REQUIRED)
if(${FLTK_FOUND})
include_directories(${FLTK_INCLUDE_DIRS})
# Set required CXX flags.
execute_process(COMMAND ${FLTK_CONFIG_SCRIPT} --cxxflags
OUTPUT_VARIABLE FLTK_CXXFLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLTK_CXXFLAGS}")
# FindFLTK does not properly handle ldflags for static libraries.
get_filename_component(FLTK_LIB_EXT ${FLTK_BASE_LIBRARY} EXT)
if(${FLTK_LIB_EXT} STREQUAL ${CMAKE_STATIC_LIBRARY_SUFFIX})
^^^ Is this the best way to determine if the library found was static or
shared? ^^^
message(STATUS "Using static FLTK libraries.")
execute_process(COMMAND ${FLTK_CONFIG_SCRIPT} --use-images
--ldstaticflags
OUTPUT_VARIABLE FLTK_LDFLAGS)
^^^ The module doesn't check if the library is static, and even then it
only ^^^
^^^ runs --ldflags for the fltk images library.
separate_arguments(FLTK_LDFLAGS)
foreach(_FLAG ${FLTK_LDFLAGS})
string(REGEX MATCH "^-l.+" _LDFLAG ${_FLAG})
string(STRIP "${_LDFLAG}" _LDFLAG)
list(APPEND FLTK_LIBRARIES ${_LDFLAG})
endforeach()
list(REMOVE_DUPLICATES FLTK_LIBRARIES)
^^^ This works, but is there a better way? ^^^
endif()
list(APPEND FLDIGI_LINK_LIBS ${FLTK_LIBRARIES})
So a broader question... Should we trust the output of a config program, in
this case, fltk-config? The writer of the module certainly doesn't. They
used the fltk-config program to find the base library, strip off the path
portion and then used it as a search path to find the libraries
independently.
I would like to update the module to use COMPONENTS, but the current
default is to find everything unless a "FLTK_SKIP_..." variable is set so I
assume there's a good way to keep backward compatibility.
Thanks,
Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20140903/87e265b2/attachment.html>
More information about the cmake-developers
mailing list