3
0
mirror of https://github.com/triqs/dft_tools synced 2024-07-11 05:43:48 +02:00

[cmake] streamline top-level cmake

* enforces major.minor version check against triqs
* adds header boilerplate
* minor cleaning
This commit is contained in:
Philipp D 2019-06-26 13:45:34 -04:00 committed by Nils Wentzell
parent d02eff9ce3
commit c3114e313a

View File

@ -1,15 +1,64 @@
# Start configuration
# ##############################################################################
#
# app4triqs - An example application using triqs and cpp2py
#
# Copyright (C) ...
#
# app4triqs is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# app4triqs is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# app4triqs (in the file COPYING.txt in this directory). If not, see
# <http://www.gnu.org/licenses/>.
#
# ##############################################################################
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
project(app4triqs VERSION 2.2.0 LANGUAGES CXX)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
# ############
# Define Project
project(APP4TRIQS VERSION 2.2.0 LANGUAGES CXX)
# ############
# Load TRIQS and CPP2PY
find_package(TRIQS 2.2 REQUIRED)
find_package(Cpp2Py 1.6 REQUIRED)
# Get the git hash & print status
triqs_get_git_hash_of_source_dir(CMAKE_PROJECT_GIT_HASH)
message(STATUS "${PROJECT_NAME} version : ${PROJECT_VERSION}")
message(STATUS "${PROJECT_NAME} Git hash: ${CMAKE_PROJECT_GIT_HASH}")
# Enforce Consistent Versioning
if(NOT ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} VERSION_EQUAL ${TRIQS_VERSION_MAJOR}.${TRIQS_VERSION_MINOR})
message(FATAL_ERROR "The ${PROJECT_NAME} version ${PROJECT_VERSION} is not compatible with TRIQS version ${TRIQS_VERSION}.")
endif()
# Default Install directory to TRIQS_ROOT if not given or invalid.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX}))
message(STATUS "No install prefix given (or invalid). Defaulting to TRIQS_ROOT")
set(CMAKE_INSTALL_PREFIX ${TRIQS_ROOT} CACHE PATH "default install path" FORCE)
endif()
message(STATUS "-------- CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX} --------")
# ############
# Options
# Default to Release build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Type of build" FORCE)
endif()
message( STATUS "-------- BUILD-TYPE: ${CMAKE_BUILD_TYPE} --------")
message(STATUS "-------- BUILD-TYPE: ${CMAKE_BUILD_TYPE} --------")
# Build static libraries
set(BUILD_SHARED_LIBS OFF)
@ -35,21 +84,12 @@ target_compile_options(project_warnings
-Wno-sign-compare
)
# Load Dependencies
find_package(TRIQS 2.2 REQUIRED)
find_package(Cpp2Py 1.6 REQUIRED)
# #############
# Load non-TRIQS Dependencies
# Default Install directory to TRIQS_ROOT if not given or invalid.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX}))
message(STATUS "No install prefix given (or invalid). Defaulting to TRIQS_ROOT")
set(CMAKE_INSTALL_PREFIX ${TRIQS_ROOT} CACHE PATH "default install path" FORCE)
endif()
message(STATUS "-------- CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX} --------")
# Define the app4triqs version numbers and get the git hash
triqs_get_git_hash_of_source_dir(APP4TRIQS_GIT_HASH)
message(STATUS "app4triqs version : ${PROJECT_VERSION}")
message(STATUS "Git hash: ${APP4TRIQS_GIT_HASH}")
# #############
# Build Project
# Build and install the app4triqs library
add_subdirectory(c++/app4triqs)
@ -69,25 +109,28 @@ if(TRIQS_WITH_PYTHON_SUPPORT)
option(Build_Documentation "Build documentation" OFF)
if(Build_Documentation)
if(NOT TRIQS_WITH_DOCUMENTATION)
message(WARNING "TRIQS library has not been compiled with its documentation! Cannot build documentation.")
message(WARNING "TRIQS was installed without documentation! Cannot build documentation.")
else()
message(STATUS "Documentation Build enabled")
add_subdirectory(doc)
endif()
endif()
else()
message(WARNING "TRIQS library has been installed without Python support. Cannot build the Python Interface and Documentation.")
message(WARNING "TRIQS was installed without Python support. Cannot build the Python Interface and Documentation.")
endif()
# Additional configuration files
add_subdirectory(share)
# #############
# Debian Package
option(BUILD_DEBIAN_PACKAGE "Build a deb package" OFF)
if(BUILD_DEBIAN_PACKAGE)
if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr")
message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be /usr for packaging")
endif()
set(CPACK_PACKAGE_NAME app4triqs)
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_CONTACT "https://github.com/TRIQS/app4triqs")
@ -97,3 +140,4 @@ if(BUILD_DEBIAN_PACKAGE)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
include(CPack)
endif()