Index: CMake/export.cmake
===================================================================
--- CMake/export.cmake	(revision 10702)
+++ CMake/export.cmake	(working copy)
@@ -61,46 +61,17 @@
    @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 "\${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})
+set(LIBNAME "${libdir}/libfltk.a")
 
-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}")
-
 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 @@
    )
 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})
Index: CMake/install.cmake
===================================================================
--- CMake/install.cmake	(revision 10702)
+++ CMake/install.cmake	(working copy)
@@ -70,7 +70,27 @@
    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 "\${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}
 )
 
Index: CMake/options.cmake
===================================================================
--- CMake/options.cmake	(revision 10702)
+++ CMake/options.cmake	(working copy)
@@ -37,6 +37,7 @@
 #######################################################################
 if(UNIX)
    option(OPTION_CREATE_LINKS "create backwards compatibility links" OFF)
+   list(APPEND FLTK_LDLIBS -lm)
 endif(UNIX)
 
 #######################################################################
@@ -49,6 +50,12 @@
    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 @@
 
 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 @@
    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}")
Index: CMake/resources.cmake
===================================================================
--- CMake/resources.cmake	(revision 10702)
+++ CMake/resources.cmake	(working copy)
@@ -78,7 +78,6 @@
 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)
@@ -85,9 +84,6 @@
 
 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(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}")
Index: CMake/variables.cmake
===================================================================
--- CMake/variables.cmake	(revision 0)
+++ CMake/variables.cmake	(working copy)
@@ -0,0 +1,75 @@
+#
+# "$Id: variables.cmake 10681 2015-04-07 09:05:24Z manolo $"
+#
+# 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})
+set(SHAREDSUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 10702)
+++ CMakeLists.txt	(working copy)
@@ -45,6 +45,14 @@
 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
 #######################################################################
 include(CMake/export.cmake)
