This commit is contained in:
Zbigniew Mandziejewicz 2015-10-13 04:38:48 +00:00
commit 75a1c67458
9 changed files with 135 additions and 100 deletions

17
.travis.yml Normal file
View File

@ -0,0 +1,17 @@
language: cpp
os:
- linux
- osx
env:
- BUILD_SHARED_LIBS=ON
- BUILD_SHARED_LIBS=OFF
sudo: false
addons:
apt:
sources:
- kubuntu-backports
packages:
- cmake
script:
- cmake -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} .
- cmake --build .

View File

@ -1,6 +1,7 @@
project(GLFW C) project(GLFW C)
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 2.8.12)
cmake_policy(SET CMP0022 NEW)
if (NOT CMAKE_VERSION VERSION_LESS "3.0") if (NOT CMAKE_VERSION VERSION_LESS "3.0")
# Until all major package systems have moved to CMake 3, # Until all major package systems have moved to CMake 3,
@ -468,41 +469,11 @@ else()
set(GLFW_LIB_NAME glfw3) set(GLFW_LIB_NAME glfw3)
endif() endif()
#--------------------------------------------------------------------
# Create generated files
#--------------------------------------------------------------------
include(CMakePackageConfigHelpers)
if (UNIX)
set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake/glfw3/")
else()
set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/")
endif()
configure_package_config_file("${GLFW_SOURCE_DIR}/src/glfw3Config.cmake.in"
"${GLFW_BINARY_DIR}/src/glfw3Config.cmake"
INSTALL_DESTINATION "${GLFW_CONFIG_PATH}"
PATH_VARS CMAKE_INSTALL_PREFIX
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file("${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake"
VERSION ${GLFW_VERSION_FULL}
COMPATIBILITY SameMajorVersion)
if (GLFW_BUILD_DOCS)
configure_file("${GLFW_SOURCE_DIR}/docs/Doxyfile.in"
"${GLFW_BINARY_DIR}/docs/Doxyfile" @ONLY)
endif()
configure_file("${GLFW_SOURCE_DIR}/src/glfw_config.h.in"
"${GLFW_BINARY_DIR}/src/glfw_config.h" @ONLY)
configure_file("${GLFW_SOURCE_DIR}/src/glfw3.pc.in"
"${GLFW_BINARY_DIR}/src/glfw3.pc" @ONLY)
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Add subdirectories # Add subdirectories
#-------------------------------------------------------------------- #--------------------------------------------------------------------
include(GNUInstallDirs)
add_subdirectory(src) add_subdirectory(src)
if (GLFW_BUILD_EXAMPLES) if (GLFW_BUILD_EXAMPLES)
@ -517,26 +488,75 @@ if (DOXYGEN_FOUND AND GLFW_BUILD_DOCS)
add_subdirectory(docs) add_subdirectory(docs)
endif() endif()
#--------------------------------------------------------------------
# Create generated files
#--------------------------------------------------------------------
include(CMakePackageConfigHelpers)
set(GLFW_INSTALL_CONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/glfw3")
set(GLFW_INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
write_basic_package_version_file(
glfw3ConfigVersion.cmake
VERSION ${GLFW_VERSION_FULL}
COMPATIBILITY SameMajorVersion)
# build tree package export
configure_file(
src/glfw3BuildConfig.cmake.in
glfw3Config.cmake
COPYONLY)
export(
TARGETS glfw
FILE glfw3Targets.cmake)
if (GLFW_BUILD_DOCS)
configure_file(docs/Doxyfile.in
docs/Doxyfile @ONLY)
endif()
configure_file(src/glfw_config.h.in
src/glfw_config.h @ONLY)
configure_file(src/glfw3.pc.in
src/glfw3.pc @ONLY)
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Install files other than the library # Install files other than the library
# The library is installed by src/CMakeLists.txt # The library is installed by src/CMakeLists.txt
#-------------------------------------------------------------------- #--------------------------------------------------------------------
if (GLFW_INSTALL) if (GLFW_INSTALL)
install(DIRECTORY include/GLFW DESTINATION include configure_package_config_file(src/glfw3Config.cmake.in
FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) ${GLFW_INSTALL_CONFIG_DIR}/glfw3Config.cmake
INSTALL_DESTINATION ${GLFW_INSTALL_CONFIG_DIR}
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" install(
"${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" DIRECTORY include/GLFW
DESTINATION lib${LIB_SUFFIX}/cmake/glfw) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN *.h)
install(EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}/cmake/glfw) install(
install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" FILES
DESTINATION lib${LIB_SUFFIX}/pkgconfig) ${GLFW_BINARY_DIR}/${GLFW_INSTALL_CONFIG_DIR}/glfw3Config.cmake
${GLFW_BINARY_DIR}/glfw3ConfigVersion.cmake
DESTINATION ${GLFW_INSTALL_CONFIG_DIR})
install(
EXPORT glfwTargets
FILE glfw3Targets.cmake
DESTINATION ${GLFW_INSTALL_CONFIG_DIR})
install(
FILES "${GLFW_BINARY_DIR}/src/glfw3.pc"
DESTINATION ${GLFW_INSTALL_PKGCONFIG_DIR})
# Only generate this target if no higher-level project already has # Only generate this target if no higher-level project already has
if (NOT TARGET uninstall) if (NOT TARGET uninstall)
configure_file("${GLFW_SOURCE_DIR}/cmake_uninstall.cmake.in" configure_file(cmake_uninstall.cmake.in
"${GLFW_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) cmake_uninstall.cmake IMMEDIATE @ONLY)
add_custom_target(uninstall add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_COMMAND}" -P

7
appveyor.yml Normal file
View File

@ -0,0 +1,7 @@
environment:
matrix:
- BUILD_SHARED_LIBS: ON
- BUILD_SHARED_LIBS: OFF
build_script:
- cmake -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% .
- cmake --build .

View File

@ -58,7 +58,7 @@ either be included _before_ the GLFW one, or the `GLFW_INCLUDE_NONE` macro
These macros may be defined before the inclusion of the GLFW header and affect These macros may be defined before the inclusion of the GLFW header and affect
its behavior. its behavior.
`GLFW_DLL` is required on Windows when using the GLFW DLL, to tell the compiler `GLFW_DLL` is required on Windows (GLFW before 3.2) when using the GLFW DLL, to tell the compiler
that the GLFW functions are defined in a DLL. that the GLFW functions are defined in a DLL.
The following macros control which OpenGL or OpenGL ES API header is included. The following macros control which OpenGL or OpenGL ES API header is included.
@ -165,26 +165,40 @@ compiler where to find it.
include_directories(path/to/glfw/include) include_directories(path/to/glfw/include)
@endcode @endcode
Once GLFW has been added to the project, the `GLFW_LIBRARIES` cache variable You need to link against glfw library and its transitive dependencies.
contains all link-time dependencies of GLFW as it is currently configured. To
link against GLFW, link against them and the `glfw` target.
@code{.cmake} @code{.cmake}
target_link_libraries(myapp glfw ${GLFW_LIBRARIES}) target_link_libraries(myapp glfw)
@endcode @endcode
Note that `GLFW_LIBRARIES` does not include GLU, as GLFW does not use it. If Note that glfw transitive dependencies do not include GLU, as GLFW does not use
your application needs GLU, you can add it to the list of dependencies with the it. If your application needs GLU, you can add it to the list of dependencies
`OPENGL_glu_LIBRARY` cache variable, which is implicitly created when the GLFW with the `OPENGL_glu_LIBRARY` cache variable, which is implicitly created when
CMake files look for OpenGL. the GLFW CMake files look for OpenGL.
@code{.cmake} @code{.cmake}
target_link_libraries(myapp glfw ${OPENGL_glu_LIBRARY} ${GLFW_LIBRARIES}) target_link_libraries(myapp glfw ${OPENGL_glu_LIBRARY})
@endcode @endcode
@subsection build_link_cmake With CMake and installed GLFW binaries
CMake can import settings from CMake package file, which GLFW supports.
@code{.cmake}
find_package(glfw3 REQUIRED)
@endcode
This registers glfw imported target in your build.
You need to link against glfw library and its transitive dependencies.
@code{.cmake}
target_link_libraries(simple glfw)
@endcode
@subsection build_link_cmake_pkgconfig With CMake on Unix and installed GLFW binaries @subsection build_link_cmake_pkgconfig With CMake on Unix and installed GLFW binaries
@deprecated Since GLFW 3.2 it is recommended to use @ref build_link_cmake
"native CMake configuration files"
CMake can import settings from pkg-config, which GLFW supports. When you CMake can import settings from pkg-config, which GLFW supports. When you
installed GLFW, the pkg-config file `glfw3.pc` was installed along with it. installed GLFW, the pkg-config file `glfw3.pc` was installed along with it.
@ -223,9 +237,11 @@ If you are using the static library version of GLFW, use the
target_link_libraries(simple ${GLFW_STATIC_LIBRARIES}) target_link_libraries(simple ${GLFW_STATIC_LIBRARIES})
@endcode @endcode
@subsection build_link_pkgconfig With pkg-config on OS X or other Unix @subsection build_link_pkgconfig With pkg-config on OS X or other Unix
@deprecated Since GLFW 3.2 it is recommended to use @ref build_link_cmake
"native CMake configuration files"
GLFW supports [pkg-config](http://www.freedesktop.org/wiki/Software/pkg-config/), GLFW supports [pkg-config](http://www.freedesktop.org/wiki/Software/pkg-config/),
and the `glfw3.pc` pkf-config file is generated when the GLFW library is built and the `glfw3.pc` pkf-config file is generated when the GLFW library is built
and is installed along with it. A pkg-config file describes all necessary and is installed along with it. A pkg-config file describes all necessary

View File

@ -1,19 +1,5 @@
link_libraries(glfw) link_libraries(glfw)
include_directories(${GLFW_SOURCE_DIR}/deps)
if (BUILD_SHARED_LIBS)
add_definitions(-DGLFW_DLL)
link_libraries("${OPENGL_gl_LIBRARY}" "${MATH_LIBRARY}")
else()
link_libraries(${glfw_LIBRARIES})
endif()
include_directories("${GLFW_SOURCE_DIR}/include"
"${GLFW_SOURCE_DIR}/deps")
if ("${OPENGL_INCLUDE_DIR}")
include_directories("${OPENGL_INCLUDE_DIR}")
endif()
set(GLAD "${GLFW_SOURCE_DIR}/deps/glad/glad.h" set(GLAD "${GLFW_SOURCE_DIR}/deps/glad/glad.h"
"${GLFW_SOURCE_DIR}/deps/glad.c") "${GLFW_SOURCE_DIR}/deps/glad.c")
@ -56,4 +42,3 @@ if (APPLE)
MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL} MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL}
MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in")
endif() endif()

View File

@ -1,10 +1,3 @@
include_directories("${GLFW_SOURCE_DIR}/src"
"${GLFW_BINARY_DIR}/src"
${glfw_INCLUDE_DIRS})
add_definitions(-D_GLFW_USE_CONFIG_H)
set(common_HEADERS internal.h set(common_HEADERS internal.h
"${GLFW_BINARY_DIR}/src/glfw_config.h" "${GLFW_BINARY_DIR}/src/glfw_config.h"
"${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h"
@ -58,15 +51,28 @@ if (APPLE)
endif() endif()
add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS})
target_link_libraries(glfw ${glfw_LIBRARIES})
target_include_directories(glfw
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
PRIVATE
"${GLFW_SOURCE_DIR}/src"
"${GLFW_BINARY_DIR}/src"
${glfw_INCLUDE_DIRS})
target_compile_definitions(glfw PRIVATE -D_GLFW_USE_CONFIG_H)
set_target_properties(glfw PROPERTIES set_target_properties(glfw PROPERTIES
OUTPUT_NAME "${GLFW_LIB_NAME}" OUTPUT_NAME "${GLFW_LIB_NAME}"
VERSION ${GLFW_VERSION} VERSION ${GLFW_VERSION}
SOVERSION ${GLFW_VERSION_MAJOR} SOVERSION ${GLFW_VERSION_MAJOR}
POSITION_INDEPENDENT_CODE ON POSITION_INDEPENDENT_CODE ON
FOLDER "GLFW3") FOLDER "GLFW3"
DEBUG_POSTFIX d)
if (BUILD_SHARED_LIBS) if (BUILD_SHARED_LIBS)
if (WIN32) if (WIN32)
target_compile_definitions(glfw INTERFACE -DGLFW_DLL)
# The GLFW DLL needs a special compile-time macro and import library name # The GLFW DLL needs a special compile-time macro and import library name
set_target_properties(glfw PROPERTIES PREFIX "" IMPORT_PREFIX "") set_target_properties(glfw PROPERTIES PREFIX "" IMPORT_PREFIX "")
@ -86,11 +92,8 @@ if (BUILD_SHARED_LIBS)
COMPILE_FLAGS "${glfw_CFLAGS} -fno-common" COMPILE_FLAGS "${glfw_CFLAGS} -fno-common"
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
endif() endif()
target_link_libraries(glfw ${glfw_LIBRARIES})
endif() endif()
if (GLFW_INSTALL) if (GLFW_INSTALL)
install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX})
endif() endif()

View File

@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake")

View File

@ -8,8 +8,8 @@ set(GLFW3_VERSION "@GLFW_VERSION_FULL@")
@PACKAGE_INIT@ @PACKAGE_INIT@
set_and_check(GLFW3_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/include") set_and_check(GLFW3_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@") set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
find_library(GLFW3_LIBRARY "@GLFW_LIB_NAME@" HINTS ${GLFW3_LIBRARY_DIR})
include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake")
set(GLFW3_LIBRARY glfw)

View File

@ -1,19 +1,5 @@
link_libraries(glfw) link_libraries(glfw)
include_directories(${GLFW_SOURCE_DIR}/deps)
if (BUILD_SHARED_LIBS)
add_definitions(-DGLFW_DLL)
link_libraries("${OPENGL_gl_LIBRARY}" "${MATH_LIBRARY}")
else()
link_libraries(${glfw_LIBRARIES})
endif()
include_directories("${GLFW_SOURCE_DIR}/include"
"${GLFW_SOURCE_DIR}/deps")
if ("${OPENGL_INCLUDE_DIR}")
include_directories("${OPENGL_INCLUDE_DIR}")
endif()
set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h"
"${GLFW_SOURCE_DIR}/deps/getopt.c") "${GLFW_SOURCE_DIR}/deps/getopt.c")