Putting in many 'CMakeLists.txt' fixes per e-mail from John Tsiombikas dated February...
authorJohn F. Fay <johnffay@nettally.com>
Tue, 7 Feb 2012 01:56:50 +0000 (01:56 +0000)
committerJohn F. Fay <johnffay@nettally.com>
Tue, 7 Feb 2012 01:56:50 +0000 (01:56 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1075 7f0cb862-5218-0410-a997-914c9d46530a

CMakeLists.txt

index c42d14d..21d0439 100644 (file)
@@ -81,7 +81,8 @@ SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
 \r
 # BUILD_SHARED_LIBS is already a standard CMake variable, but we need to\r
 # re-declare it here so it will show up in the GUI.\r
-OPTION(BUILD_SHARED_LIBS "Build FreeGLUT as a shared library." ON)\r
+OPTION(BUILD_SHARED_LIBS "Build FreeGLUT shared library." ON)\r
+OPTION(BUILD_STATIC_LIBS "Build FreeGLUT static library." ON)\r
 \r
 FIND_PACKAGE(OpenGL REQUIRED)\r
 \r
@@ -92,10 +93,20 @@ IF(WIN32)
        ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)\r
 ENDIF()\r
 \r
-INCLUDE(CheckIncludeFiles)\r
+if(UNIX)\r
+       FIND_PACKAGE(X11 REQUIRED)\r
+       LIST(APPEND LIBS ${X11_LIBRARIES})\r
+       IF(X11_Xrandr_FOUND)\r
+               SET(HAVE_X11_EXTENSIONS_XRANDR_H TRUE)\r
+               LIST(APPEND LIBS ${X11_Xrandr_LIB})\r
+       ENDIF()\r
+       IF(X11_xf86vmode_FOUND)\r
+               SET(HAVE_X11_EXTENSIONS_XF86VMODE_H TRUE)\r
+               LIST(APPEND LIBS ${X11_xf86vmode_LIB})\r
+       ENDIF()\r
+ENDIF()\r
 \r
-CHECK_INCLUDE_FILES(X11/extensions/xf86vmode.h         HAVE_X11_EXTENSIONS_XF86VMODE_H)\r
-CHECK_INCLUDE_FILES(X11/extensions/Xrandr.h    HAVE_X11_EXTENSIONS_XRANDR_H)\r
+INCLUDE(CheckIncludeFiles)\r
 CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)\r
 CHECK_INCLUDE_FILES(unistd.h   HAVE_UNISTD_H)\r
 CHECK_INCLUDE_FILES(sys/time.h         HAVE_SYS_TIME_H)\r
@@ -113,33 +124,57 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})\r
 ADD_DEFINITIONS(-DHAVE_CONFIG_H)\r
 \r
+# by default, at least on UNIX, we want to build both\r
 IF(BUILD_SHARED_LIBS)\r
-       IF(WIN32)\r
+       ADD_LIBRARY(freeglut SHARED ${FREEGLUT_SRCS})\r
+ENDIF()\r
+IF(BUILD_STATIC_LIBS)\r
+       ADD_LIBRARY(freeglut_static STATIC ${FREEGLUT_SRCS})\r
+ENDIF()\r
+\r
+\r
+IF(WIN32)\r
+       IF(BUILD_SHARED_LIBS)\r
                LIST(APPEND FREEGLUT_SRCS src/Common/freeglutdll.def freeglut.rc)\r
+               # XXX I assume that if we want both shared and static this one is appropriate\r
+               ADD_DEFINITIONS(-DFREEGLUT_EXPORTS)\r
+       ELSE()\r
+               ADD_DEFINITIONS(-DFREEGLUT_STATIC)\r
        ENDIF()\r
-       ADD_DEFINITIONS(-DFREEGLUT_EXPORTS)\r
 ELSE()\r
-       ADD_DEFINITIONS(-DFREEGLUT_STATIC)\r
+       # on UNIX we need to make sure:\r
+       # - all shared libraries must have a soname/version\r
+       # - the output library should be named glut so it'll be linkable with -lglut\r
+       # - the shared library should link to the dependency libraries so that the user\r
+       #   won't have to link them explicitly (they shouldn't have to know that we depend\r
+       #   on Xrandr or Xxf86vm)\r
+       SET_TARGET_PROPERTIES(freeglut PROPERTIES VERSION 3.9.0 SOVERSION 3 OUTPUT_NAME glut)\r
+       SET_TARGET_PROPERTIES(freeglut_static PROPERTIES OUTPUT_NAME glut)\r
+       TARGET_LINK_LIBRARIES(freeglut ${LIBS})\r
 ENDIF()\r
 \r
-# The default library type is determined by BUILD_SHARED_LIBS\r
-ADD_LIBRARY(freeglut ${FREEGLUT_SRCS})\r
-\r
-IF(NOT BUILD_SHARED_LIBS)\r
-       SET_TARGET_PROPERTIES(freeglut PROPERTIES OUTPUT_NAME freeglut_static)\r
+IF(BUILD_SHARED_LIBS)\r
+       INSTALL(TARGETS freeglut DESTINATION lib)\r
+ENDIF()\r
+IF(BUILD_STATIC_LIBS)\r
+       INSTALL(TARGETS freeglut_static DESTINATION lib)\r
 ENDIF()\r
-\r
-INSTALL(TARGETS freeglut DESTINATION lib)\r
 INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL)\r
 \r
+\r
+\r
 # Optionally build demos, on by default.\r
 option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )\r
 \r
+SET(DEMO_LIBS ${OPENGL_LIBRARY} ${LIBS})\r
 MACRO(ADD_DEMO name)\r
        if( FREEGLUT_BUILD_DEMOS )\r
                ADD_EXECUTABLE(${name} ${ARGN})\r
-               TARGET_LINK_LIBRARIES(${name} freeglut)\r
-               INSTALL(TARGETS ${name} DESTINATION bin)\r
+               IF(BUILD_SHARED_LIBS)\r
+                       TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut)\r
+               ELSE()\r
+                       TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut_static)\r
+               ENDIF()\r
        endif()\r
 ENDMACRO()\r
 \r