Put platform detection in a single place.

This commit is contained in:
Camilla Berglund 2012-03-25 16:51:24 +02:00
parent 20e685d37b
commit bd8eb1399a
2 changed files with 21 additions and 22 deletions

View File

@ -23,13 +23,25 @@ if (CMAKE_COMPILER_IS_GNUCC)
endif() endif()
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Set up GLFW for Win32 and WGL on Windows # Detect and select target platform
#-------------------------------------------------------------------- #--------------------------------------------------------------------
if (WIN32) if (WIN32)
message(STATUS "Building GLFW for WGL on a Win32 system")
# Define the platform identifier
set(_GLFW_WIN32_WGL 1) set(_GLFW_WIN32_WGL 1)
message(STATUS "Building GLFW for WGL on a Win32 system")
elseif (UNIX AND APPLE)
set(_GLFW_COCOA_NSGL 1)
message(STATUS "Building GLFW for X11 and GLX on a Unix-like system")
elseif (UNIX AND NOT APPLE)
set(_GLFW_X11_GLX 1)
message(STATUS "Building GLFW for Cocoa and NSOpenGL on Mac OS X")
else()
message(FATAL_ERROR "No supported platform was detected")
endif()
#--------------------------------------------------------------------
# Set up GLFW for Win32 and WGL on Windows
#--------------------------------------------------------------------
if (_GLFW_WIN32_WGL)
# Set up library and include paths # Set up library and include paths
list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR})
@ -43,11 +55,7 @@ endif()
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Set up GLFW for Xlib and GLX on Unix-like systems with X Windows # Set up GLFW for Xlib and GLX on Unix-like systems with X Windows
#-------------------------------------------------------------------- #--------------------------------------------------------------------
if (UNIX AND NOT APPLE) if (_GLFW_X11_GLX)
message(STATUS "Building GLFW for X11 and GLX on a Unix-like system")
# Define the platform identifier
set(_GLFW_X11_GLX 1)
find_package(X11 REQUIRED) find_package(X11 REQUIRED)
@ -131,11 +139,7 @@ endif()
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Set up GLFW for Cocoa and NSOpenGL on Mac OS X # Set up GLFW for Cocoa and NSOpenGL on Mac OS X
#-------------------------------------------------------------------- #--------------------------------------------------------------------
if (UNIX AND APPLE) if (_GLFW_COCOA_NSGL)
message(STATUS "Building GLFW for Cocoa and NSOpenGL on Mac OS X")
# Define the platform identifier
set(_GLFW_COCOA_NSGL 1)
option(GLFW_BUILD_UNIVERSAL "Build GLFW as a Universal Binary" OFF) option(GLFW_BUILD_UNIVERSAL "Build GLFW as a Universal Binary" OFF)

View File

@ -1,5 +1,5 @@
if (UNIX) if (_GLFW_X11_GLX)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake
${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc
@ -30,24 +30,20 @@ elseif (_GLFW_X11_GLX)
x11_init.c x11_input.c x11_joystick.c x11_init.c x11_input.c x11_joystick.c
x11_keysym2unicode.c x11_opengl.c x11_time.c x11_keysym2unicode.c x11_opengl.c x11_time.c
x11_window.c) x11_window.c)
else()
message(FATAL_ERROR "No supported platform was selected")
endif() endif()
add_library(glfw ${glfw_SOURCES}) add_library(glfw ${glfw_SOURCES})
if (BUILD_SHARED_LIBS) if (BUILD_SHARED_LIBS)
if (WIN32) if (_GLFW_WIN32_WGL)
# 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 set_target_properties(glfw PROPERTIES
COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM"
PREFIX "" PREFIX ""
IMPORT_PREFIX "" IMPORT_PREFIX ""
IMPORT_SUFFIX "dll.lib") IMPORT_SUFFIX "dll.lib")
endif() elseif (_GLFW_COCOA_NSGL)
if (APPLE)
# Append -fno-common to the compile flags to work around a bug in the Apple GCC # Append -fno-common to the compile flags to work around a bug in the Apple GCC
get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS) get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS)
if (NOT glfw_CFLAGS) if (NOT glfw_CFLAGS)
@ -59,7 +55,6 @@ if (BUILD_SHARED_LIBS)
target_link_libraries(glfw ${glfw_LIBRARIES}) target_link_libraries(glfw ${glfw_LIBRARIES})
target_link_libraries(glfw LINK_INTERFACE_LIBRARIES) target_link_libraries(glfw LINK_INTERFACE_LIBRARIES)
endif() endif()
install(TARGETS glfw DESTINATION lib) install(TARGETS glfw DESTINATION lib)