Clean up CMake scripts
authorJames Le Cuirot <chewi@aura-online.co.uk>
Sun, 1 Jun 2014 21:13:04 +0000 (1 22:13 +0100)
committerJames Le Cuirot <chewi@aura-online.co.uk>
Sun, 1 Jun 2014 21:58:59 +0000 (1 22:58 +0100)
A lot of it was redundant. Lowercased function names seem to be the
norm now. Static build is now optional. Documentation now
installs. Added CMake finder script.

.gitignore [new file with mode: 0644]
CMakeLists.txt
FindGLPNG.cmake.in [new file with mode: 0644]
cmake/FindZlib.cmake [deleted file]
src/CMakeLists.txt

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..05a3d44
--- /dev/null
@@ -0,0 +1,10 @@
+*.a
+*.so
+*.so.*
+
+Makefile
+CMakeFiles
+CMakeCache.txt
+cmake_install.cmake
+
+/FindGLPNG.cmake
dissimilarity index 99%
index 47aaf4f..6bd9d50 100644 (file)
@@ -1,31 +1,21 @@
-# Created by Tomas Chvatal (Scarabeus IV)
-###############################################################################
-# sdlpango/CMakeLists.txt
-###############################################################################
-SET ( VERSION "1.45" CACHE STRING "Version" ) # this is redefine able
-SET ( SONAME_VERSION "1" CACHE STRING "SONAME Version" )
-SET ( CMAKE_INSTALL_PREFIX "/usr/local/" CACHE PATH "Install path prefix" )
-SET ( CMAKE_INSTALL_LIBDIR lib )
-SET ( WORKDIR ${CMAKE_SOURCE_DIR}/src )
-###############################################################################
-
-PROJECT ( glpng C )
-SET ( APPNAME glpng )
-CMAKE_MINIMUM_REQUIRED ( VERSION 2.6.0 )
-CMAKE_MINIMUM_REQUIRED ( VERSION 2.6.0 FATAL_ERROR )
-IF ( COMMAND cmake_policy )
-       cmake_policy( SET CMP0003 NEW )
-ENDIF ( COMMAND cmake_policy )
-SET ( CMAKE_COLOR_MAKEFILE ON )
-SET ( CMAKE_BUILD_TYPE_SHARED_LIBS ON )
-# uninstall
-###############################################################################
-SET ( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" )
-FIND_PACKAGE ( Zlib REQUIRED)
-FIND_PACKAGE ( PNG REQUIRED )
-FIND_PACKAGE ( OpenGL REQUIRED )
-ADD_SUBDIRECTORY ( src )
-ADD_SUBDIRECTORY ( Example )
-# install include files
-FILE ( GLOB files "${CMAKE_SOURCE_DIR}/include/GL/*.h" )
-INSTALL ( FILES ${files} DESTINATION include/GL/ )
+cmake_minimum_required(VERSION 2.8.5 FATAL_ERROR)
+
+project(glpng C)
+include(GNUInstallDirs)
+
+set(SONAME_VERSION 1)
+set(MINOR_VERSION 45)
+set(VERSION ${SONAME_VERSION}.${MINOR_VERSION})
+
+set(BUILD_STATIC_LIBS ON CACHE BOOL "Set to ON to build static libraries")
+
+find_package(ZLIB REQUIRED)
+find_package(PNG REQUIRED)
+find_package(OpenGL REQUIRED)
+
+add_subdirectory(src)
+configure_file(FindGLPNG.cmake.in FindGLPNG.cmake @ONLY)
+
+install(FILES include/GL/glpng.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GL/)
+install(FILES glpng.htm DESTINATION ${CMAKE_INSTALL_DOCDIR})
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FindGLPNG.cmake DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/Modules)
diff --git a/FindGLPNG.cmake.in b/FindGLPNG.cmake.in
new file mode 100644 (file)
index 0000000..c7ab95d
--- /dev/null
@@ -0,0 +1,21 @@
+# - Try to find glpng
+# Once done this will define
+#
+#  GLPNG_FOUND - system has glpng
+#  GLPNG_INCLUDE_DIRS - the glpng include directories
+#  GLPNG_LIBRARIES - link these to use glpng
+
+find_path(GLPNG_INCLUDE_DIR GL/glpng.h)
+find_library(GLPNG_LIBRARY NAMES glpng)
+
+set(GLPNG_INCLUDE_DIRS ${GLPNG_INCLUDE_DIR})
+set(GLPNG_LIBRARIES ${GLPNG_LIBRARY})
+
+set(GLPNG_VERSION @VERSION@)
+set(GLPNG_VERSION_MAJOR @SONAME_VERSION@)
+set(GLPNG_VERSION_MINOR @MINOR_VERSION@)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(GLPNG DEFAULT_MSG GLPNG_LIBRARY GLPNG_INCLUDE_DIR)
+
+mark_as_advanced(GLPNG_INCLUDE_DIR GLPNG_LIBRARY)
diff --git a/cmake/FindZlib.cmake b/cmake/FindZlib.cmake
deleted file mode 100644 (file)
index f5c1497..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-# - Find zlib
-# Find the native ZLIB includes and library
-#
-#  ZLIB_INCLUDE_DIR - where to find zlib.h, etc.
-#  ZLIB_LIBRARIES   - List of libraries when using zlib.
-#  ZLIB_FOUND       - True if zlib found.
-#
-#  Modified by Nicolas Schlumberger, (c) 2007
-#  to make it work on the Tardis Infrastucture of the ETH Zurich
-#
-IF(UNIX)
-  IF (ZLIB_INCLUDE_DIR)
-  # Already in cache, be silent
-    SET(ZLIB_FIND_QUIETLY TRUE)
-  ENDIF (ZLIB_INCLUDE_DIR)
-  FIND_PATH(ZLIB_INCLUDE_DIR zlib.h
-    /usr/pack/zziplib-0.13.49-sd/include/
-    /usr/local/include
-    /usr/include
-  )
-  SET(ZLIB_NAMES z zlib zdll)
-  FIND_LIBRARY(ZLIB_LIBRARY
-    NAMES ${ZLIB_NAMES}
-    PATHS /usr/pack/zziplib-0.13.49-sd/i686-debian-linux3.1/lib/ /usr/lib /usr/local/lib
-  )
-  IF (ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
-    SET(ZLIB_FOUND TRUE)
-      SET( ZLIB_LIBRARIES ${ZLIB_LIBRARY} )
-  ELSE (ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
-    SET(ZLIB_FOUND FALSE)
-    SET( ZLIB_LIBRARIES )
-  ENDIF (ZLIB_INCLUDE_DIR AND ZLIB_LIBRARY)
-  IF (ZLIB_FOUND)
-    IF (NOT ZLIB_FIND_QUIETLY)
-      MESSAGE(STATUS "Found ZLIB: ${ZLIB_LIBRARY}")
-    ENDIF (NOT ZLIB_FIND_QUIETLY)
-  ELSE (ZLIB_FOUND)
-    IF (ZLIB_FIND_REQUIRED)
-        MESSAGE(STATUS "Looked for Z libraries named ${ZLIBS_NAMES}.")
-        MESSAGE(FATAL_ERROR "Could NOT find z library")
-    ENDIF (ZLIB_FIND_REQUIRED)
-  ENDIF (ZLIB_FOUND)
-  MARK_AS_ADVANCED(
-    ZLIB_LIBRARY
-    ZLIB_INCLUDE_DIR
-  )
-ENDIF(UNIX)
-IF(WIN32)
-  IF(EXISTS "../libs/ogre/Dependencies/lib/Release")
-    SET (ZLIB_LIBRARY_DIR "../libs/ogre/Dependencies/lib/Release")
-  ENDIF(EXISTS "../libs/ogre/Dependencies/lib/Release")
-  FIND_PATH(ZLIB_INCLUDE_DIR zlib.h
-    ../libs/ogre/Dependencies/include
-  )
-  FIND_LIBRARY(ZLIB_LIBRARY
-    NAMES zlib
-    PATHS ${ZLIB_LIBRARY_DIR}
-  )
-  IF(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR)
-    MESSAGE(STATUS "Zlib was found.")
-  ELSE(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR)
-    MESSAGE(FATAL_ERROR "Zlib was NOT found.")
-  ENDIF(ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR)
-ENDIF(WIN32)
dissimilarity index 99%
index f58df8d..5ff3e4a 100644 (file)
@@ -1,24 +1,22 @@
-# Created by Tomas Chvatal (Scarabeus IV)
-###############################################################################
-# sdlpango/src/CMakeLists.txt
-###############################################################################
-INCLUDE_DIRECTORIES ( ${ZLIB_INCLUDE_DIR} ${PNG_INCLUDE_DIR}
-               ${OPENGL_INCLUDE_DIR}  ${CMAKE_SOURCE_DIR}/include/ )
-LINK_LIBRARIES ( ${CMAKE_DL_LIBS} ${ZLIB_LIBRARIES} ${PNG_LIBRARY}
-               ${OPENGL_gl_LIBRARY} )
-SET ( SRCS ${APPNAME}.c
-)
-SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
-SET(CMAKE_STATIC_LIBRARY_C_FLAG "-Wl," )
-ADD_LIBRARY ( shared SHARED ${SRCS} )
-ADD_LIBRARY ( static STATIC ${SRCS} )
-SET_TARGET_PROPERTIES(shared static PROPERTIES OUTPUT_NAME glpng)
-SET_TARGET_PROPERTIES (shared PROPERTIES VERSION ${VERSION} SOVERSION ${SONAME_VERSION})
-#INCLUDE(MacroCreateLibtoolFile.cmake)
-#CREATE_LIBTOOL_FILE(pango-shared "/${CMAKE_INSTALL_LIBDIR}")
-INSTALL ( TARGETS shared
-       LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
-INSTALL ( TARGETS static
-       ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
-
-
+include_directories(
+       ${ZLIB_INCLUDE_DIR}
+       ${PNG_INCLUDE_DIR}
+       ${OPENGL_INCLUDE_DIR}
+       ${CMAKE_SOURCE_DIR}/include/
+)
+
+link_libraries(
+       ${ZLIB_LIBRARIES}
+       ${PNG_LIBRARY}
+       ${OPENGL_gl_LIBRARY}
+)
+
+add_library(glpng SHARED glpng.c)
+set_target_properties(glpng PROPERTIES VERSION ${VERSION} SOVERSION ${SONAME_VERSION})
+install(TARGETS glpng DESTINATION ${CMAKE_INSTALL_LIBDIR})
+
+if(BUILD_STATIC_LIBS)
+       add_library(glpng-static STATIC glpng.c)
+       set_target_properties(glpng-static PROPERTIES OUTPUT_NAME glpng)
+       install(TARGETS glpng-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
+endif(BUILD_STATIC_LIBS)