[CMake] Fix CMake build's fltk-config (STR #3217).

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10716 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser 2015-04-25 13:50:27 +00:00
parent d2b7b5b24a
commit e23bf0b768
7 changed files with 133 additions and 469 deletions

View File

@ -61,46 +61,17 @@ configure_file(
@ONLY
)
# generate config.h
configure_file(
"${FLTK_SOURCE_DIR}/configh.cmake.in"
"${FLTK_BINARY_DIR}/config.h"
@ONLY
)
# generate fltk-config for build directory use
set(prefix ${FLTK_BINARY_DIR})
set(exec_prefix "\${prefix}")
set(includedir "${FLTK_SOURCE_DIR}")
set(libdir "\${exec_prefix}/lib")
set(srcdir ".")
# generate fltk-config
# Set install locations; this could be shortened with a foreach loop...
if(IS_ABSOLUTE ${FLTK_INSTALL_BINDIR})
set(FLTK_FULL_BINDIR ${FLTK_BINDIR})
else()
set(FLTK_FULL_BINDIR ${CMAKE_INSTALL_PREFIX}/${FLTK_BINDIR})
endif(IS_ABSOLUTE ${FLTK_INSTALL_BINDIR})
if(IS_ABSOLUTE ${FLTK_INCLUDEDIR})
set(FLTK_FULL_INCLUDEDIR ${FLTK_INCLUDEDIR})
else()
set(FLTK_FULL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${FLTK_INCLUDEDIR})
endif(IS_ABSOLUTE ${FLTK_INCLUDEDIR})
if(IS_ABSOLUTE ${FLTK_LIBDIR})
set(FLTK_FULL_LIBDIR ${FLTK_LIBDIR})
else()
set(FLTK_FULL_LIBDIR ${CMAKE_INSTALL_PREFIX}/${FLTK_LIBDIR})
endif(IS_ABSOLUTE ${FLTK_LIBDIR})
# set compiler
get_filename_component(CC ${CMAKE_C_COMPILER} NAME)
get_filename_component(CXX ${CMAKE_CXX_COMPILER} NAME)
string(REPLACE ";" " " C_FLAGS "${FLTK_CFLAGS}")
if(X11_Xext_FOUND)
list(APPEND FLTK_LDLIBS -lXext)
endif(X11_Xext_FOUND)
string(REPLACE ";" " " LD_LIBS "${FLTK_LDLIBS}")
set(LIBNAME "${libdir}/libfltk.a")
configure_file(
"${FLTK_SOURCE_DIR}/fltk-config.cmake.in"
"${FLTK_SOURCE_DIR}/fltk-config.in"
"${FLTK_BINARY_DIR}/fltk-config"
@ONLY
)
@ -110,6 +81,13 @@ if(UNIX)
)
endif(UNIX)
# generate config.h
configure_file(
"${FLTK_SOURCE_DIR}/configh.cmake.in"
"${FLTK_BINARY_DIR}/config.h"
@ONLY
)
if(OPTION_CREATE_LINKS)
# Set PREFIX_INCLUDE to the proper value.
if(IS_ABSOLUTE ${FLTK_INCLUDEDIR})

View File

@ -70,7 +70,27 @@ install(FILES ${FLTK_BINARY_DIR}/etc/UseFLTK.cmake
DESTINATION ${FLTK_CONFIG_PATH}
)
install(PROGRAMS ${FLTK_BINARY_DIR}/fltk-config
# generate fltk-config
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(srcdir ".")
set(LIBNAME "${libdir}/libfltk.a")
configure_file(
"${FLTK_SOURCE_DIR}/fltk-config.in"
"${FLTK_BINARY_DIR}/bin/fltk-config"
@ONLY
)
if(UNIX)
execute_process(COMMAND chmod 755 fltk-config
WORKING_DIRECTORY "${FLTK_BINARY_DIR}/bin"
)
endif(UNIX)
install(PROGRAMS ${FLTK_BINARY_DIR}/bin/fltk-config
DESTINATION ${FLTK_BINDIR}
)

View File

@ -37,6 +37,7 @@ add_definitions(${OPTION_ARCHFLAGS})
#######################################################################
if(UNIX)
option(OPTION_CREATE_LINKS "create backwards compatibility links" OFF)
list(APPEND FLTK_LDLIBS -lm)
endif(UNIX)
#######################################################################
@ -49,6 +50,12 @@ if((NOT APPLE OR OPTION_APPLE_X11) AND NOT WIN32)
if(X11_FOUND)
set(USE_X11 1)
list(APPEND FLTK_LDLIBS -lX11)
if (X11_Xext_FOUND)
list(APPEND FLTK_LDLIBS -lXext)
endif(X11_Xext_FOUND)
if(X11_Xrender_FOUND)
list(APPEND FLTK_LDLIBS -lXrender)
endif(X11_Xrender_FOUND)
endif(X11_FOUND)
endif((NOT APPLE OR OPTION_APPLE_X11) AND NOT WIN32)
@ -108,7 +115,7 @@ endif(OPTION_USE_GL)
if(OPENGL_FOUND)
set(CMAKE_REQUIRED_INCLUDES ${OPENGL_INCLUDE_DIR}/GL)
set(CMAKE_REQUIRED_LIBRARIES -lGLU -lGL)
set(GLLIB "-lGLU -lGL")
CHECK_FUNCTION_EXISTS(glXGetProcAddressARB HAVE_GLXGETPROCADDRESSARB)
set(FLTK_GL_FOUND TRUE)
else()
@ -298,30 +305,3 @@ else()
set(FLTK_XDBE_FOUND FALSE)
endif(OPTION_USE_XDBE AND HAVE_XDBE_H)
#######################################################################
# add several libraries (STR #3011)
# FIXME: libraries may need reordering, and this version does not yet
# correctly support static linking and local zlib, png, and jpeg libs.
if(LIB_fontconfig)
list(APPEND FLTK_LDLIBS -lfontconfig)
endif(LIB_fontconfig)
if(HAVE_DLSYM)
list(APPEND FLTK_LDLIBS -ldl)
endif(HAVE_DLSYM)
if(LIB_png)
list(APPEND IMAGELIBS -lpng)
endif(LIB_png)
if(LIB_zlib)
list(APPEND IMAGELIBS -lz)
endif(LIB_zlib)
if(LIB_jpeg)
list(APPEND IMAGELIBS -ljpeg)
endif(LIB_jpeg)
string(REPLACE ";" " " IMAGELIBS "${IMAGELIBS}")
set(STATICIMAGELIBS "${IMAGELIBS}")

View File

@ -78,16 +78,12 @@ mark_as_advanced(LIB_jpeg LIB_png LIB_zlib)
include(CheckFunctionExists)
if(HAVE_DLFCN_H)
set(CMAKE_REQUIRED_LIBRARIES dl)
set(HAVE_DLFCN_H 1)
endif(HAVE_DLFCN_H)
CHECK_FUNCTION_EXISTS(dlsym HAVE_DLSYM)
CHECK_FUNCTION_EXISTS(localeconv HAVE_LOCALECONV)
if(LIB_png)
set(CMAKE_REQUIRED_LIBRARIES png)
endif(LIB_png)
CHECK_FUNCTION_EXISTS(png_get_valid HAVE_PNG_GET_VALID)
CHECK_FUNCTION_EXISTS(png_set_tRNS_to_alpha HAVE_PNG_SET_TRNS_TO_ALPHA)
@ -105,8 +101,6 @@ CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
CHECK_FUNCTION_EXISTS(strlcpy HAVE_STRLCPY)
CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
set(CMAKE_REQUIRED_LIBRARIES)
if(HAVE_SCANDIR AND NOT HAVE_SCANDIR_POSIX)
set(MSG "POSIX compatible scandir")
message(STATUS "Looking for ${MSG}")

81
CMake/variables.cmake Normal file
View File

@ -0,0 +1,81 @@
#
# "$Id$"
#
# This file sets variables for common use in export.cmake and install.cmake
# Written by Michael Surette
#
# Copyright 1998-2015 by Bill Spitzak and others.
#
# This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file. If this
# file is missing or damaged, see the license at:
#
# http://www.fltk.org/COPYING.php
#
# Please report all bugs and problems on the following page:
#
# http://www.fltk.org/str.php
#
#######################################################################
set(FL_MAJOR_VERSION ${FLTK_VERSION_MAJOR})
set(FL_MINOR_VERSION ${FLTK_VERSION_MINOR})
set(FL_PATCH_VERSION ${FLTK_VERSION_PATCH})
#######################################################################
# add several libraries (STR #3011)
# FIXME: libraries may need reordering, and this version does not yet
# correctly support static linking and local zlib, png, and jpeg libs.
if(LIB_fontconfig)
list(APPEND FLTK_LDLIBS -lfontconfig)
endif(LIB_fontconfig)
if(HAVE_DLSYM)
list(APPEND FLTK_LDLIBS -ldl)
endif(HAVE_DLSYM)
if(LIB_png)
list(APPEND IMAGELIBS -lpng)
endif(LIB_png)
if(LIB_zlib)
list(APPEND IMAGELIBS -lz)
endif(LIB_zlib)
if(LIB_jpeg)
list(APPEND IMAGELIBS -ljpeg)
endif(LIB_jpeg)
string(REPLACE ";" " " IMAGELIBS "${IMAGELIBS}")
set(STATICIMAGELIBS "${IMAGELIBS}")
#######################################################################
set(CC ${CMAKE_C_COMPILER})
set(CXX ${CMAKE_CXX_COMPILER})
set(ARCHFLAGS ${OPTION_ARCHFLAGS})
string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_UPPER)
if(${BUILD_UPPER})
set(CFLAGS "${CMAKE_C_FLAGS_${BUILD_UPPER}} ${CFLAGS}")
endif(${BUILD_UPPER})
set(CFLAGS "${OPTION_OPTIM} ${CMAKE_C_FLAGS} ${CFLAGS}")
foreach(arg ${FLTK_CFLAGS})
set(CFLAGS "${CFLAGS} ${arg}")
endforeach(arg ${FLTK_CFLAGS})
set(CXXFLAGS ${CFLAGS})
foreach(arg ${FLTK_LDLIBS})
set(LINK_LIBS "${LINK_LIBS} ${arg}")
endforeach(arg ${FLTK_LDLIBS})
set(LIBS ${LINK_LIBS})
# FIXME: The only case `configure' would set the "SHAREDSUFFIX"
# variable is to "_s" if OS == "aix", hence we do NOT (yet) set it here.
# This is for fltk-config only, so it doesn't matter much anyway.
# ${CMAKE_SHARED_LIBRARY_SUFFIX} would be ".so" under Linux.
# * do not * set(SHAREDSUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(SHAREDSUFFIX "")

View File

@ -44,6 +44,14 @@ include(CMake/resources.cmake)
#######################################################################
include(CMake/options.cmake)
#######################################################################
# variables shared by export and install
# export.cmake creates configuration files for direct use in a built but uninstalled FLTK
# install.cmake creates these files for an installed FLTK
# these two would only differ in paths, so common variables are set here
#######################################################################
include(CMake/variables.cmake)
#######################################################################
# final config and export
#######################################################################

View File

@ -1,397 +0,0 @@
#!/bin/sh
#
# "$Id$"
#
# FLTK configuration utility.
#
# Copyright 2000-2015 by Bill Spitzak and others.
# Original version Copyright 2000 by James Dean Palmer
# Adapted by Vincent Penne and Michael Sweet
#
# This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file. If this
# file is missing or damaged, see the license at:
#
# http://www.fltk.org/COPYING.php
#
# Please report all bugs and problems on the following page:
#
# http://www.fltk.org/str.php
#
MAJOR_VERSION=@FLTK_VERSION_MAJOR@
MINOR_VERSION=@FLTK_VERSION_MINOR@
PATCH_VERSION=@FLTK_VERSION_PATCH@
VERSION=@FLTK_VERSION_FULL@
APIVERSION=@FLTK_VERSION@
### BEGIN fltk-config
selfdir=`dirname "$0"`
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
exec_prefix_set=no
includedir=@FLTK_FULL_INCLUDEDIR@
libdir=@FLTK_FULL_LIBDIR@
srcdir=.
# compiler names
CC="@CC@"
CXX="@CXX@"
# flags for C++ compiler:
ARCHFLAGS="@OPTION_ARCHFLAGS@"
CFLAGS="@C_FLAGS@"
CXXFLAGS="@CAIROFLAGS@@C_FLAGS@"
LDFLAGS="@LDFLAGS@"
LDLIBS="@LD_LIBS@"
OPTIM="@OPTION_OPTIM@"
CAIROFLAGS="@CAIROFLAGS@"
# Check for local invocation, and update paths accordingly...
if test -f "$selfdir/config.h"; then
includedir="@FLTK_SOURCE_DIR@"
libdir="$selfdir/lib"
if test -f "$libdir/libfltk_jpeg.a"; then
CFLAGS="-I$includedir/jpeg $CFLAGS"
CXXFLAGS="-I$includedir/jpeg $CXXFLAGS"
fi
if test -f "$libdir/libfltk_z.a"; then
CFLAGS="-I$includedir/zlib $CFLAGS"
CXXFLAGS="-I$includedir/zlib $CXXFLAGS"
fi
if test -f "$libdir/libfltk_png.a"; then
CFLAGS="-I$includedir/png $CFLAGS"
CXXFLAGS="-I$includedir/png $CXXFLAGS"
fi
fi
if test -d $includedir/FL/images; then
CFLAGS="-I$includedir/FL/images $CFLAGS"
CXXFLAGS="-I$includedir/FL/images $CXXFLAGS"
fi
if test -f "$libdir/libfltk_cairo.a"; then
CFLAGS="$CAIROFLAGS $CFLAGS"
CXXFLAGS="$CAIROFLAGS $CXXFLAGS"
fi
# libraries to link with:
LIBNAME="@LIBNAME@"
DSONAME="@DSONAME@"
DSOLINK="@DSOLINK@"
IMAGELIBS="@IMAGELIBS@"
STATICIMAGELIBS="@STATICIMAGELIBS@"
CAIROLIBS="@CAIROLIBS@"
SHAREDSUFFIX="@SHAREDSUFFIX@"
usage ()
{
echo "Usage: fltk-config [OPTIONS]
Options:
[--version]
[--api-version]
Options telling what we are doing:
[--use-gl] use GL
[--use-images] use extra image formats (PNG, JPEG)
[--use-glut] use glut compatibility layer
[--use-forms] use forms compatibility layer
[--use-cairo] use cairo graphics lib
Options telling what information we request:
[--cc] return C compiler used to compile FLTK
[--cxx] return C++ compiler used to compile FLTK
[--optim] return compiler optimization used to compile FLTK
[--cflags] return flags to compile C using FLTK
[--cxxflags] return flags to compile C++ using FLTK
[--ldflags] return flags to link against FLTK
[--ldstaticflags] return flags to link against static FLTK library
even if there are DSOs installed
[--libs] return FLTK libraries full path for dependencies
[--prefix] return FLTK install time --prefix directory
[--includedir] return FLTK install time include directory
Options to compile and link an application:
[-g] compile the program with debugging information
[-Dname[=value]] compile the program with the given define
[--compile program.cxx]
[--post program] prepare the program for desktop use
"
exit $1
}
if test $# -eq 0; then
usage 1
fi
no_plugins=no
compile=
post=
debug=
# Parse command line options
while test $# -gt 0
do
case "$1" in
-*=*)
optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
;;
*)
optarg=
;;
esac
case $1 in
--version)
echo $VERSION
;;
--api-version)
echo $APIVERSION
;;
--cc)
echo $CC
;;
--cxx)
echo $CXX
;;
--optim)
echo_optim=yes
;;
--use-gl | --use-glut)
use_gl=yes
;;
--use-forms)
use_forms=yes
;;
--use-images)
use_images=yes
;;
--use-cairo)
use_cairo=yes
;;
--cflags)
echo_cflags=yes
;;
--cxxflags)
echo_cxxflags=yes
;;
--ldflags)
echo_ldflags=yes
;;
--ldstaticflags)
echo_ldstaticflags=yes
;;
--libs)
echo_libs=yes
;;
--prefix)
echo_prefix=yes
;;
--includedir)
echo_includedir=yes
;;
-g)
debug=-g
;;
-D*)
CXXFLAGS="$CXXFLAGS $1"
;;
--compile)
compile="$2"
shift
;;
--post)
post="$2"
shift
;;
*)
echo_help=yes
;;
esac
shift
done
if test "$includedir" != /usr/include; then
includes=-I$includedir
else
includes=
fi
if test "$libdir" != /usr/lib -a "$libdir" != /usr/lib32; then
libs=-L$libdir
else
libs=
fi
# Calculate needed libraries
LDSTATIC="$libdir/libfltk.a $LDLIBS"
LDLIBS="-lfltk$SHAREDSUFFIX $LDLIBS"
if test x$use_forms = xyes; then
LDLIBS="-lfltk_forms$SHAREDSUFFIX $LDLIBS"
LDSTATIC="$libdir/libfltk_forms.a $LDSTATIC"
fi
if test x$use_gl = xyes; then
LDLIBS="-lfltk_gl$SHAREDSUFFIX @GLLIB@ $LDLIBS"
LDSTATIC="$libdir/libfltk_gl.a @GLLIB@ $LDSTATIC"
fi
if test x$use_images = xyes; then
LDLIBS="-lfltk_images$SHAREDSUFFIX $IMAGELIBS $LDLIBS"
LDSTATIC="$libdir/libfltk_images.a $STATICIMAGELIBS $LDSTATIC"
fi
if test x$use_cairo = xyes; then
LDLIBS="-lfltk_cairo$SHAREDSUFFIX $CAIROLIBS $LDLIBS"
LDSTATIC="$libdir/libfltk_cairo.a $CAIROLIBS $LDSTATIC"
fi
LDLIBS="$DSOLINK $LDFLAGS $libs $LDLIBS"
LDSTATIC="$LDFLAGS $LDSTATIC"
# Answer to user requests
if test -n "$echo_help"; then
usage 1
fi
if test -n "$compile"; then
case "$compile" in
*.cxx)
prog="`basename \"$compile\" .cxx`"
;;
*.cpp)
prog="`basename \"$compile\" .cpp`"
;;
*.cc)
prog="`basename \"$compile\" .cc`"
;;
*.C)
prog="`basename \"$compile\" .C`"
;;
*)
echo "ERROR: Unknown/bad C++ source file extension on \"$compile\"!"
exit 1
;;
esac
post="$prog"
echo $CXX $ARCHFLAGS $includes $CXXFLAGS $debug -o "'$prog'" "'$compile'" $LDSTATIC
$CXX $ARCHFLAGS $includes $CXXFLAGS $debug -o "$prog" "$compile" $LDSTATIC || exit 1
fi
if test -n "$post"; then
case "`uname`" in
Darwin)
echo Creating "'$post.app'" bundle for desktop...
id=`echo $post | tr ' ' '_'`
# Make the bundle directory and move the executable there
rm -rf "$post.app/Contents/MacOS"
mkdir -p "$post.app/Contents/MacOS"
mv "$post" "$post.app/Contents/MacOS"
# Make a shell script that runs the bundled executable
echo "#!/bin/sh" >"$post"
echo 'dir="`dirname '"'"'$0'"'"'`"' >>"$post"
echo 'exec "$dir/'"$post.app/Contents/MacOS/$post"'" "$@"' >>"$post"
chmod +x "$post"
# Make the simplest Info.plist needed for an application
cat >"$post.app/Contents/Info.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<plist version="0.9">
<dict>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleExecutable</key>
<string>$post</string>
<key>CFBundleIdentifier</key>
<string>org.fltk.$id</string>
<key>CFBundleName</key>
<string>$post</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
EOF
;;
esac
fi
if test "$echo_cflags" = "yes"; then
echo $includes $CFLAGS
fi
if test "$echo_cxxflags" = "yes"; then
echo $includes $CXXFLAGS
fi
if test "$echo_optim" = "yes"; then
echo $OPTIM
fi
if test "$echo_ldflags" = "yes"; then
my_libs=
libdirs=$libs
for i in $LDLIBS ; do
if test $i != -L$libdir ; then
if test -z "$my_libs" ; then
my_libs="$i"
else
my_libs="$my_libs $i"
fi
fi
done
echo $libdirs $my_libs
fi
if test "$echo_ldstaticflags" = "yes"; then
echo $LDSTATIC
fi
if test "$echo_libs" = "yes"; then
USELIBS="$libdir/libfltk.a"
if test x$use_forms = xyes; then
USELIBS="$libdir/libfltk_forms.a $USELIBS"
fi
if test x$use_gl = xyes; then
USELIBS="$libdir/libfltk_gl.a $USELIBS"
fi
if test x$use_cairo = xyes; then
USELIBS="$libdir/libfltk_cairo.a $USELIBS"
fi
if test x$use_images = xyes; then
USELIBS="$libdir/libfltk_images.a $USELIBS"
for lib in fltk_jpeg fltk_png fltk_z; do
if test -f $libdir/lib$lib.a; then
USELIBS="$libdir/lib$lib.a $USELIBS"
fi
done
fi
echo $USELIBS
fi
if test "$echo_prefix" = "yes"; then
echo $prefix
fi
if test "$echo_includedir" = "yes"; then
echo $includedir
fi
#
# End of "$Id$".
#