Skip to content

Commit

Permalink
Initial import of empty template project.
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Kirchner <[email protected]>
  • Loading branch information
mkirchner committed Jan 22, 2012
0 parents commit 08b7155
Show file tree
Hide file tree
Showing 22 changed files with 159,593 additions and 0 deletions.
267 changes: 267 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
PROJECT(LIBTEMPLATE)

# require at least cmake 2.8
cmake_minimum_required(VERSION 2.8)

#############################################################################
# include cmake scripts
#############################################################################
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros)

# require out-of-source build
INCLUDE(require_out_of_src_build)
MACRO_REQUIRE_OUT_OF_SRC_BUILD("LIBTEMPLATE requires out-of-source builds.")

# Git revision saved in variable LIBTEMPLATE_VERSION
INCLUDE(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC LIBTEMPLATE_VERSION)

#############################################################################
# Varaibles to upper string for easier comparisions
#############################################################################

IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "RelWithDebInfo")
ENDIF(NOT CMAKE_BUILD_TYPE)
STRING(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)

#############################################################################
# build libraries
#############################################################################
# require boost
#SET(Boost_USE_STATIC_LIBS OFF)
#SET(Boost_USE_MULTITHREAD OFF)
#make sure that at least version 1.46.0 is used
#SET(BOOST_MIN_VERSION "1.46.0")
#FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} COMPONENTS thread REQUIRED)

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})

#############################################################################
# compiler Flags
#############################################################################

# Set default compile flags for GCC
if(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wall -Wconversion -ggdb3")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -ftree-vectorize -msse2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3")
endif(CMAKE_COMPILER_IS_GNUCXX)

#############################################################################
# Cmake generated header files
#############################################################################
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/include/template/config.hpp.cmake
${LIBTEMPLATE_BINARY_DIR}/include/template/config.hpp
)

#############################################################################
# Cmake Options
#############################################################################

OPTION(ENABLE_TESTING "Compile tests" ON)
OPTION(ENABLE_COVERAGE "Enable GCov coverage analysis (defines a 'coverage' target and enforces static build of libtemplate)" OFF)
OPTION(ENABLE_EXAMPLES "Compile examples" OFF)
OPTION(ENABLE_THREADING "Enable threading" FALSE)

#############################################################################
# global include dirs
#############################################################################

INCLUDE_DIRECTORIES(
${LIBTEMPLATE_SOURCE_DIR}/include
${LIBTEMPLATE_BINARY_DIR}/include
)

#############################################################################
# messages and error handling
#############################################################################
MESSAGE(STATUS "libtemplate Git Commit: "${LIBTEMPLATE_VERSION})
MESSAGE(STATUS "Build type: "${CMAKE_BUILD_TYPE})
MESSAGE(STATUS "CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}")
IF(ENABLE_THREADING)
MESSAGE(STATUS "Threading enabled")
ELSE()
MESSAGE(STATUS "Threading disabled")
ENDIF()
IF(ENABLE_TESTING)
MESSAGE(STATUS "Testing enabled")
ELSE()
MESSAGE(STATUS "Testing disabled")
ENDIF()
IF(ENABLE_EXAMPLES)
MESSAGE(STATUS "Examples enabled")
ELSE()
MESSAGE(STATUS "Examples disabled")
ENDIF()
IF (ENABLE_COVERAGE)
IF(CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND ENABLE_TESTING)
MESSAGE(STATUS "Coverage enabled")
ELSEIF(NOT ENABLE_TESTING)
MESSAGE(FATAL_ERROR "Coverage analysis requires Testing Enabled")
ELSE()
MESSAGE(FATAL_ERROR "Coverage analysis requires DEBUG build")
ENDIF()
ELSE()
MESSAGE(STATUS "Coverage disabled")
ENDIF()


#############################################################################
# code coverage analysis
#############################################################################

IF (ENABLE_COVERAGE)
IF(CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND ENABLE_TESTING)
SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
CONFIGURE_FILE(${LIBTEMPLATE_SOURCE_DIR}/cmake/scripts/coverage.sh.in
${LIBTEMPLATE_BINARY_DIR}/cmake/scripts/coverage.sh
@ONLY IMMEDIATE
)
ADD_CUSTOM_TARGET(
coverage COMMAND /bin/bash ${LIBTEMPLATE_BINARY_DIR}/cmake/scripts/coverage.sh
)
ENDIF()
ENDIF(ENABLE_COVERAGE)


#############################################################################
# tests
#############################################################################

IF (ENABLE_TESTING)
INCLUDE(CTest)
ENABLE_TESTING()
ADD_SUBDIRECTORY(test)
ENDIF (ENABLE_TESTING)


#############################################################################
# build libtemplate
#############################################################################

ADD_SUBDIRECTORY(src)

############################################################################
# examples
############################################################################
#
#IF (ENABLE_EXAMPLES)
# ADD_SUBDIRECTORY(examples)
#ENDIF (ENABLE_EXAMPLES)

#############################################################################
# documentation
#############################################################################
# doxygen support
CONFIGURE_FILE(${LIBTEMPLATE_SOURCE_DIR}/doc/Doxyfile.cmake
${LIBTEMPLATE_BINARY_DIR}/doc/Doxyfile
@ONLY IMMEDIATE
)
CONFIGURE_FILE(${LIBTEMPLATE_SOURCE_DIR}/doc/libtemplate.png
${LIBTEMPLATE_BINARY_DIR}/doc/libtemplate.png
COPYONLY
)

FIND_PACKAGE(Doxygen)

# target for doxygen
ADD_CUSTOM_TARGET(doc COMMAND ${DOXYGEN} ${LIBTEMPLATE_BINARY_DIR}/doc/Doxyfile)

#############################################################################
# installation
#############################################################################
# location, location, location
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX
"/usr/local" CACHE PATH "libtemplate install prefix" FORCE
)
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# so that the dmg works also to the given location
SET(CPACK_PACKAGE_DEFAULT_LOCATION ${CMAKE_INSTALL_PREFIX})


# headers
INSTALL(DIRECTORY ${LIBTEMPLATE_SOURCE_DIR}/include/libtemplate
DESTINATION include
COMPONENT headers
REGEX "/.git$" EXCLUDE
PATTERN "config.hpp.cmake" EXCLUDE)

# config.h
INSTALL(FILES ${LIBTEMPLATE_BINARY_DIR}/include/libtemplate/config.hpp
DESTINATION include/libtemplate
COMPONENT headers)

# documentation
INSTALL(DIRECTORY ${LIBTEMPLATE_BINARY_DIR}/doc
DESTINATION share/libtemplate
COMPONENT documentation
PATTERN "Doxyfile" EXCLUDE)



##############################################################################
## exporting libtemplate
##############################################################################
get_target_property(LIBTEMPLATE_LIBRARY template LOCATION)

get_filename_component(LIBTEMPLATE_INSTALL_LIBRARY ${LIBTEMPLATE_LIBRARY} NAME)

set (LIBTEMPLATE_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/${LIBTEMPLATE_INSTALL_LIBRARY})
set (LIBTEMPLATE_INCLUDE ${CMAKE_INSTALL_PREFIX}/include)

configure_file(
"${PROJECT_SOURCE_DIR}/cmake/macros/libtemplateConfig.cmake.in"
"${PROJECT_BINARY_DIR}/InstallFiles/libtemplateConfig.cmake")

export(TARGETS template
FILE "${PROJECT_BINARY_DIR}/InstallFiles/libtemplateLibraryDepends.cmake")

export(PACKAGE template)

if (UNIX)
INSTALL(FILES "${PROJECT_BINARY_DIR}/InstallFiles/libtemplateConfig.cmake" DESTINATION /lib/libtemplate/)
INSTALL(FILES "${PROJECT_BINARY_DIR}/InstallFiles/libtemplateLibraryDepends.cmake" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/libtemplate/cmake/)
elseif(WIN32)
INSTALL(FILES "${PROJECT_BINARY_DIR}/InstallFiles/libtemplateConfig.cmake" DESTINATION /cmake/)
INSTALL(FILES "${PROJECT_BINARY_DIR}/InstallFiles/libtemplateLibraryDepends.cmake" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/libtemplate/cmake/)

endif()

##############################################################################
## packaging
##############################################################################
## FIXME: make sure that the documentation is compiled and pdfs are
## generated prior to packaging!
#
set(CPACK_PACKAGE_NAME "libtemplate")
set(CPACK_PACKAGE_VENDOR "kirchnerlab.org")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A library template; version "$LIBTEMPLATE_VERSION)

# CPack version strings
SET(CPACK_PACKAGE_VERSION_MAJOR 2)
SET(CPACK_PACKAGE_VERSION_MINOR 1)
SET(CPACK_PACKAGE_VERSION_PATCH 0)

SET(CPACK_RESOURCE_FILE_README "${LIBTEMPLATE_SOURCE_DIR}/README.txt")
SET(CPACK_RESOURCE_FILE_LICENSE "${LIBTEMPLATE_SOURCE_DIR}/LICENSE.txt")

set(CPACK_COMPONENTS_ALL libraries headers documentation examples)
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Development Headers")
set(CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "C++ Interface Documentation")
set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Compiled Examples")

set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION
"Compiled libraries.")
set(CPACK_COMPONENT_HEADERS_DESCRIPTION
"C++ header files for libtemplate development.")
set(CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION
"The C++ libtemplate interface documentation (Doxygen).")
set(CPACK_COMPONENT_EXAMPLES_DESCRIPTION
"Compiled examples.")

INCLUDE(CPack)
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
libtemplate, Copyright (c) 2012 User Name

This file is part of libtemplate.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Empty file added README.txt
Empty file.
104 changes: 104 additions & 0 deletions cmake/macros/GetGitRevisionDescription.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additonal arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additonal arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additonal arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)

# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)

function(get_git_head_revision _refspecvar _hashvar)
set(GIT_DIR "${CMAKE_SOURCE_DIR}/.git")
if(NOT EXISTS "${GIT_DIR}")
# not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)

configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" "${GIT_DATA}/grabRef.cmake" @ONLY)
include("${GIT_DATA}/grabRef.cmake")

set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()

function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()

# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()

#message(STATUS "Arguments to execute_process: ${ARGN}")

execute_process(COMMAND "${GIT_EXECUTABLE}" describe ${hash} ${ARGN}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()

set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
Loading

0 comments on commit 08b7155

Please sign in to comment.