Permalink
Browse files

Refactor cmake build into multiple files

  • Loading branch information...
jamiesnape committed Sep 16, 2016
1 parent e33c60a commit a3adb0d5d7a74209679a56c16290d50735ddb649
Showing with 104 additions and 54 deletions.
  1. +30 −48 CMakeLists.txt
  2. +7 −6 ccd.pc.in
  3. +67 −0 src/CMakeLists.txt
View
@@ -1,60 +1,42 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.8.11)
+
+if(POLICY CMP0042)
+ cmake_policy(SET CMP0042 NEW)
+endif()
+
project(libccd C)
-set(CCD_VERSION "2.0")
-set(CCD_SOVERSION "2")
-set(PKG_DESC "Library for collision detection between convex shapes")
+set(CCD_VERSION_MAJOR 2)
+set(CCD_VERSION_MINOR 0)
+set(CCD_VERSION ${CCD_VERSION_MAJOR}.${CCD_VERSION_MINOR})
+
+set(CCD_SOVERSION 2)
# Include GNUInstallDirs to get canonical paths
include(GNUInstallDirs)
-include_directories("src/")
-
-# make sure only DOUBLE or SINGLE is set; default to SINGLE
-if (${CCD_SINGLE})
- set(CCD_DOUBLE false)
-else()
- set(CCD_SINGLE true)
-endif()
-
-if (${CCD_DOUBLE})
- set(CCD_SINGLE false)
-endif()
+option(ENABLE_DOUBLE_PRECISION
+ "Enable double precision computations instead of single precision" OFF)
# set the default build type
-if (NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE Release)
-endif()
-
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/ccd/config.h.cmake.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/ccd/config.h")
-
-if(NOT WIN32)
- find_library(MATH m)
-else()
- set(MATH "")
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ set(CMAKE_BUILD_TYPE Release CACHE STRING
+ "Choose the type of build; options are Debug Release RelWithDebInfo MinSizeRel"
+ FORCE)
+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
+ STRINGS
+ Debug
+ Release
+ RelWithDebInfo
+ MinSizeRel)
endif()
-set(SOURCE_FILES
- src/ccd.c
- src/mpr.c
- src/polytope.c
- src/support.c
- src/vec3.c)
-
-add_library(ccd SHARED ${SOURCE_FILES})
-set_target_properties(ccd PROPERTIES VERSION ${CCD_VERSION} SOVERSION ${CCD_SOVERSION})
-
-target_link_libraries(ccd ${MATH})
-
-add_library(ccd_static STATIC ${SOURCE_FILES})
-set_target_properties(ccd_static PROPERTIES OUTPUT_NAME ccd)
-target_link_libraries(ccd_static ${MATH})
+add_subdirectory(src)
-set(pkg_conf_file "${CMAKE_CURRENT_SOURCE_DIR}/ccd.pc")
-configure_file("${pkg_conf_file}.in" "${pkg_conf_file}" @ONLY)
+set(CCD_PKGCONFIG_DESCRIPTION
+ "Library for collision detection between convex shapes")
+configure_file(ccd.pc.in ccd.pc @ONLY)
+install(FILES "${CMAKE_BINARY_DIR}/ccd.pc"
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
-install(TARGETS ccd ccd_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
-install(DIRECTORY src/ccd DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h")
-install(FILES "${pkg_conf_file}" DESTINATION
- ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT pkgconfig)
+install(FILES BSD-LICENSE DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/ccd")
View
@@ -1,12 +1,13 @@
-# This file was generated by CMake for @PROJECT_NAME@
+# Generated by CMake @CMAKE_VERSION@ for ccd
+
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
-libdir=@CMAKE_INSTALL_FULL_LIBDIR@
-includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
+libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: @PROJECT_NAME@
-Description: @PKG_DESC@
+Description: @CCD_PKGCONFIG_DESCRIPTION@
Version: @CCD_VERSION@
-Requires: @PKG_EXTERNAL_DEPS@
-Libs: -L${libdir} -lccd
+Requires: @CCD_PKGCONFIG_REQUIRES@
+Libs: -L${libdir} -lccd @CCD_PKGCONFIG_EXTRA_LIBS@
Cflags: -I${includedir}
View
@@ -0,0 +1,67 @@
+if(DEFINED CCD_SINGLE OR DEFINED CCD_DOUBLE)
+ # make sure only DOUBLE or SINGLE is set; default to SINGLE
+ if(CCD_SINGLE)
+ set(CCD_DOUBLE OFF)
+ else()
+ set(CCD_SINGLE ON)
+ endif()
+ if(CCD_DOUBLE)
+ set(CCD_SINGLE OFF)
+ endif()
+elseif(ENABLE_DOUBLE_PRECISION)
+ set(CCD_DOUBLE ON)
+ set(CCD_SINGLE OFF)
+else()
+ set(CCD_DOUBLE OFF)
+ set(CCD_SINGLE ON)
+endif()
+
+configure_file(ccd/config.h.cmake.in ccd/config.h)
+
+set(CCD_INCLUDES
+ ccd/ccd.h
+ ccd/compiler.h
+ ccd/quat.h
+ ccd/vec3.h
+ "${CMAKE_CURRENT_BINARY_DIR}/ccd/config.h")
+
+set(CCD_SOURCES
+ alloc.h
+ ccd.c
+ dbg.h
+ list.h
+ mpr.c
+ polytope.c
+ polytope.h
+ simplex.h
+ support.c
+ support.h
+ vec3.c)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
+
+add_library(ccd SHARED ${CCD_INCLUDES} ${CCD_SOURCES})
+set_target_properties(ccd PROPERTIES
+ PUBLIC_HEADER "${CCD_INCLUDES}"
+ SOVERSION ${CCD_SOVERSION}
+ VERSION ${CCD_VERSION})
+
+add_library(ccd_static STATIC ${CCD_INCLUDES} ${CCD_SOURCES})
+set_target_properties(ccd_static PROPERTIES
+ OUTPUT_NAME ccd
+ VERSION ${CCD_VERSION})
+
+if(NOT WIN32)
+ find_library(LIBM_LIBRARY NAMES m)
+ if(NOT LIBM_LIBRARY)
+ message(FATAL_ERROR "Could NOT find required library LibM")
+ endif()
+ target_link_libraries(ccd "${LIBM_LIBRARY}")
+ target_link_libraries(ccd_static "${LIBM_LIBRARY}")
+endif()
+
+install(TARGETS ccd ccd_static
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ccd"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

0 comments on commit a3adb0d

Please sign in to comment.