Skip to content

Commit

Permalink
Port app4triqs project structure to tprf
Browse files Browse the repository at this point in the history
  • Loading branch information
Wentzell committed Apr 17, 2019
1 parent 5737303 commit 1bb09af
Show file tree
Hide file tree
Showing 91 changed files with 828 additions and 413 deletions.
125 changes: 74 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,68 +1,91 @@
# start configuration
cmake_minimum_required(VERSION 2.8)
project(tprf CXX)
set(CMAKE_BUILD_TYPE Release)
enable_testing()
# Start configuration
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
project(triqs_tprf CXX)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()

# 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} --------")

# We use shared libraries
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
# Build static libraries
set(BUILD_SHARED_LIBS OFF)

# Load TRIQS and Cpp2Py
find_package(TRIQS 2.0 REQUIRED)
find_package(Cpp2Py 1.5 REQUIRED)
# Export the list of compile-commands into compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Load TRIQS, including all predefined variables from TRIQS installation
# First append triqs installed files to the cmake load path
list(APPEND CMAKE_MODULE_PATH ${TRIQS_PATH}/share/triqs/cmake)
# Enable compiler warnings for the whole project
add_compile_options(-Wall
$<$<CONFIG:Debug>:-Og>
$<$<CONFIG:Debug>:-ggdb3>
)

add_definitions(${TRIQS_CXX_DEFINITIONS})
include_directories(${TRIQS_INCLUDE_ALL})
# Load Dependencies
find_package(TRIQS 2.2 REQUIRED)
find_package(Cpp2Py 1.6 REQUIRED)

# Default Install directory to TRIQS_ROOT if not given. Checks an absolute name is given.
# 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} -------------")

# All PRIVATE common options.
# The std for all targets
add_compile_options(-std=c++17)
message(STATUS "-------- CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX} --------")

# Common to all targets (ctint, python, tests).
include_directories(${CMAKE_SOURCE_DIR})
# Define the triqs_tprf version numbers and get the git hash
set(TPRF_VERSION_MAJOR 2)
set(TPRF_VERSION_MINOR 2)
set(TPRF_VERSION_PATCH 0)
set(TPRF_VERSION ${TPRF_VERSION_MAJOR}.${TPRF_VERSION_MINOR}.${TPRF_VERSION_PATCH})
triqs_get_git_hash_of_source_dir(TPRF_GIT_HASH)
message(STATUS "triqs_tprf version : ${TPRF_VERSION}")
message(STATUS "Git hash: ${TPRF_GIT_HASH}")

# Get the Git Hash
find_package(Git)
# Build and install the triqs_tprf library
add_subdirectory(c++/triqs_tprf)

execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE TPRF_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "TPRF git hash : ${TPRF_GIT_HASH}")
# Tests
option(Build_Tests "Build tests" ON)
if(Build_Tests)
enable_testing()
add_subdirectory(test)
endif()

# To be fixed!!
triqs_set_rpath_for_all_targets()
if(TRIQS_WITH_PYTHON_SUPPORT)
# Python interface
add_subdirectory(python/triqs_tprf)

# Compile C++ code
add_subdirectory(c++)
# Build the documentation
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.")
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.")
endif()

# Python interface (if is compiled with Python support).
# Remove this for a pure C++ code.
if (${TRIQS_WITH_PYTHON_SUPPORT})
add_subdirectory(python)
# Additional configuration files
add_subdirectory(share)

# Build Sphinx based docs
option(BUILD_DOC "Build documentation" OFF)
if(${BUILD_DOC})
if(NOT ${TRIQS_WITH_DOCUMENTATION})
message(FATAL_ERROR "Error: TRIQS library has not been compiled with its documentation")
endif()
add_subdirectory(doc)
endif(${BUILD_DOC})
# 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_GENERATOR "DEB")
SET(CPACK_PACKAGE_VERSION ${TPRF_VERSION})
SET(CPACK_PACKAGE_CONTACT "https://github.com/TRIQS/triqs_tprf")
EXECUTE_PROCESS(COMMAND dpkg --print-architecture OUTPUT_VARIABLE CMAKE_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "triqs (>= 2.2)")
SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
SET(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
INCLUDE(CPack)
endif()

# Add tests
enable_testing()
add_subdirectory(test)
1 change: 1 addition & 0 deletions ChangeLog.md
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See ../triqs/packaging for other options
FROM flatironinstitute/triqs:master-ubuntu-clang

ARG APPNAME
COPY . $SRC/$APPNAME
WORKDIR $BUILD/$APPNAME
RUN chown build .
USER build
ARG BUILD_DOC=0
RUN cmake $SRC/$APPNAME -DTRIQS_ROOT=${INSTALL} -DBuild_Documentation=${BUILD_DOC} && make -j2 && make test CTEST_OUTPUT_ON_FAILURE=1
USER root
RUN make install
154 changes: 154 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
def projectName = "triqs_tprf" /* set to app/repo name */

/* which platform to build documentation on */
def documentationPlatform = "ubuntu-clang"
/* depend on triqs upstream branch/project */
def triqsBranch = env.CHANGE_TARGET ?: env.BRANCH_NAME
def triqsProject = '/TRIQS/triqs/' + triqsBranch.replaceAll('/', '%2F')
/* whether to publish the results (disabled for template project) */
def publish = !env.BRANCH_NAME.startsWith("PR-") && projectName != "triqs_tprf"

properties([
disableConcurrentBuilds(),
buildDiscarder(logRotator(numToKeepStr: '10', daysToKeepStr: '30')),
pipelineTriggers([
upstream(
threshold: 'SUCCESS',
upstreamProjects: triqsProject
)
])
])

/* map of all builds to run, populated below */
def platforms = [:]

/****************** linux builds (in docker) */
/* Each platform must have a cooresponding Dockerfile.PLATFORM in triqs/packaging */
def dockerPlatforms = ["ubuntu-clang", "ubuntu-gcc", "centos-gcc"]
/* .each is currently broken in jenkins */
for (int i = 0; i < dockerPlatforms.size(); i++) {
def platform = dockerPlatforms[i]
platforms[platform] = { -> node('docker') {
stage(platform) { timeout(time: 1, unit: 'HOURS') {
checkout scm
/* construct a Dockerfile for this base */
sh """
( echo "FROM flatironinstitute/triqs:${triqsBranch}-${env.STAGE_NAME}" ; sed '0,/^FROM /d' Dockerfile ) > Dockerfile.jenkins
mv -f Dockerfile.jenkins Dockerfile
"""
/* build and tag */
def img = docker.build("flatironinstitute/${projectName}:${env.BRANCH_NAME}-${env.STAGE_NAME}", "--build-arg APPNAME=${projectName} --build-arg BUILD_DOC=${platform==documentationPlatform} .")
if (!publish || platform != documentationPlatform) {
/* but we don't need the tag so clean it up (except for documentation) */
sh "docker rmi --no-prune ${img.imageName()}"
}
} }
} }
}

/****************** osx builds (on host) */
def osxPlatforms = [
["gcc", ['CC=gcc-7', 'CXX=g++-7']],
["clang", ['CC=$BREW/opt/llvm/bin/clang', 'CXX=$BREW/opt/llvm/bin/clang++', 'CXXFLAGS=-I$BREW/opt/llvm/include', 'LDFLAGS=-L$BREW/opt/llvm/lib']]
]
for (int i = 0; i < osxPlatforms.size(); i++) {
def platformEnv = osxPlatforms[i]
def platform = platformEnv[0]
platforms["osx-$platform"] = { -> node('osx && triqs') {
stage("osx-$platform") { timeout(time: 1, unit: 'HOURS') {
def srcDir = pwd()
def tmpDir = pwd(tmp:true)
def buildDir = "$tmpDir/build"
def installDir = "$tmpDir/install"
def triqsDir = "${env.HOME}/install/triqs/${triqsBranch}/${platform}"
dir(installDir) {
deleteDir()
}

checkout scm
dir(buildDir) { withEnv(platformEnv[1].collect { it.replace('\$BREW', env.BREW) } + [
"PATH=$triqsDir/bin:${env.BREW}/bin:/usr/bin:/bin:/usr/sbin",
"CPLUS_INCLUDE_PATH=$triqsDir/include:${env.BREW}/include",
"LIBRARY_PATH=$triqsDir/lib:${env.BREW}/lib",
"CMAKE_PREFIX_PATH=$triqsDir/lib/cmake/triqs"]) {
deleteDir()
sh "cmake $srcDir -DCMAKE_INSTALL_PREFIX=$installDir -DTRIQS_ROOT=$triqsDir"
sh "make -j3"
try {
sh "make test CTEST_OUTPUT_ON_FAILURE=1"
} catch (exc) {
archiveArtifacts(artifacts: 'Testing/Temporary/LastTest.log')
throw exc
}
sh "make install"
} }
} }
} }
}

/****************** wrap-up */
try {
parallel platforms
if (publish) { node("docker") {
/* Publish results */
stage("publish") { timeout(time: 1, unit: 'HOURS') {
def commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
def release = env.BRANCH_NAME == "master" || env.BRANCH_NAME == "unstable" || sh(returnStdout: true, script: "git describe --exact-match HEAD || true").trim()
def workDir = pwd()
/* Update documention on gh-pages branch */
dir("$workDir/gh-pages") {
def subdir = "${projectName}/${env.BRANCH_NAME}"
git(url: "ssh://[email protected]/TRIQS/TRIQS.github.io.git", branch: "master", credentialsId: "ssh", changelog: false)
sh "rm -rf ${subdir}"
docker.image("flatironinstitute/${projectName}:${env.BRANCH_NAME}-${documentationPlatform}").inside() {
sh "cp -rp \$INSTALL/share/doc/${projectName} ${subdir}"
}
sh "git add -A ${subdir}"
sh """
git commit --author='Flatiron Jenkins <[email protected]>' --allow-empty -m 'Generated documentation for ${subdir}' -m '${env.BUILD_TAG} ${commit}'
"""
// note: credentials used above don't work (need JENKINS-28335)
sh "git push origin master || { git pull --rebase origin master && git push origin master ; }"
}
/* Update docker repo submodule */
if (release) { dir("$workDir/docker") { try {
git(url: "ssh://[email protected]/TRIQS/docker.git", branch: env.BRANCH_NAME, credentialsId: "ssh", changelog: false)
sh "echo '160000 commit ${commit}\t${projectName}' | git update-index --index-info"
sh """
git commit --author='Flatiron Jenkins <[email protected]>' --allow-empty -m 'Autoupdate ${projectName}' -m '${env.BUILD_TAG}'
"""
// note: credentials used above don't work (need JENKINS-28335)
sh "git push origin ${env.BRANCH_NAME} || { git pull --rebase origin ${env.BRANCH_NAME} && git push origin ${env.BRANCH_NAME} ; }"
} catch (err) {
/* Ignore, non-critical -- might not exist on this branch */
echo "Failed to update docker repo"
} } }
} }
} }
} catch (err) {
/* send email on build failure (declarative pipeline's post section would work better) */
if (env.BRANCH_NAME != "jenkins") emailext(
subject: "\$PROJECT_NAME - Build # \$BUILD_NUMBER - FAILED",
body: """\$PROJECT_NAME - Build # \$BUILD_NUMBER - FAILED
$err
Check console output at \$BUILD_URL to view full results.
Building \$BRANCH_NAME for \$CAUSE
\$JOB_DESCRIPTION
Changes:
\$CHANGES
End of build log:
\${BUILD_LOG,maxLines=60}
""",
to: '[email protected], [email protected]',
recipientProviders: [
[$class: 'DevelopersRecipientProvider'],
],
replyTo: '$DEFAULT_REPLYTO'
)
throw err
}
16 changes: 16 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
TRIQS: a Toolbox for Research in Interacting Quantum Systems

Copyright (C) 2014 by P. Seth, I. Krivenko, M. Ferrero, O. Parcollet

TRIQS 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.

TRIQS 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
TRIQS (in the file COPYING.txt in this directory). If not, see
<http://www.gnu.org/licenses/>.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ later version (see <http://www.gnu.org/licenses/>).

It 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.
PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 changes: 0 additions & 22 deletions c++/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 1bb09af

Please sign in to comment.