Skip to content

Commit

Permalink
Make app4triqs not depend on triqs
Browse files Browse the repository at this point in the history
Co-authored-by: Dylan Simon <dylan@dylex.net>
  • Loading branch information
Wentzell and dylex committed Jul 26, 2023
1 parent f23ebdf commit 178fe60
Show file tree
Hide file tree
Showing 43 changed files with 608 additions and 158 deletions.
23 changes: 4 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: build

on:
push:
branches: [ unstable ]
branches: [ notriqs ]
pull_request:
branches: [ unstable ]
branches: [ notriqs ]

jobs:
build:
Expand Down Expand Up @@ -35,7 +35,6 @@ jobs:
gfortran
hdf5-tools
libblas-dev
libboost-dev
libclang-15-dev
libc++-15-dev
libc++abi-15-dev
Expand All @@ -52,7 +51,6 @@ jobs:
python3-clang-15
python3-dev
python3-mako
python3-matplotlib
python3-mpi4py
python3-numpy
python3-pip
Expand All @@ -63,35 +61,22 @@ jobs:
- name: Install homebrew dependencies
if: matrix.os == 'macos-12'
run: |
brew install gcc@12 llvm boost fftw hdf5 open-mpi openblas
brew install gcc@12 llvm hdf5 open-mpi openblas
pip3 install mako numpy scipy mpi4py
pip3 install -r requirements.txt
- name: Build & Install TRIQS
env:
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
run: |
git clone https://github.com/TRIQS/triqs --branch unstable
mkdir triqs/build && cd triqs/build
cmake .. -DBuild_Tests=OFF -DCMAKE_INSTALL_PREFIX=$HOME/install
make -j1 install VERBOSE=1
cd ../
- name: Build app4triqs
env:
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
LIBRARY_PATH: /usr/local/opt/llvm/lib
run: |
source $HOME/install/share/triqs/triqsvars.sh
mkdir build && cd build && cmake ..
mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/install
make -j2 || make -j1 VERBOSE=1
- name: Test app4triqs
env:
DYLD_FALLBACK_LIBRARY_PATH: /usr/local/opt/llvm/lib
run: |
source $HOME/install/share/triqs/triqsvars.sh
cd build
ctest -j2 --output-on-failure
42 changes: 23 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,17 @@ cmake_policy(VERSION 3.20)

# ############
# Define Project
project(app4triqs VERSION 3.2.0 LANGUAGES C CXX)
project(app4triqs VERSION 1.2.0 LANGUAGES C CXX)
get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)

# ############
# Load TRIQS and CPP2PY
find_package(TRIQS 3.2 REQUIRED)

# Get the git hash & print status
triqs_get_git_hash_of_source_dir(PROJECT_GIT_HASH)
execute_process(COMMAND git rev-parse HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE PROJECT_GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "${PROJECT_NAME} version : ${PROJECT_VERSION}")
message(STATUS "${PROJECT_NAME} Git hash: ${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.
# Assert that Install directory is given and 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)
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE)
message(FATAL_ERROR "No install prefix given (or invalid)")
endif()
if(NOT IS_SUBPROJECT)
message(STATUS "-------- CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX} --------")
Expand All @@ -68,9 +57,6 @@ endif()

# Python Support
option(PythonSupport "Build with Python support" ON)
if(PythonSupport AND NOT TRIQS_WITH_PYTHON_SUPPORT)
message(FATAL_ERROR "TRIQS was installed without Python support. Cannot build the Python Interface. Disable the build with -DPythonSupport=OFF")
endif()

# Documentation
option(Build_Documentation "Build documentation" OFF)
Expand Down Expand Up @@ -125,6 +111,25 @@ target_compile_options(${PROJECT_NAME}_warnings
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-c++20-compat>
)

# ---------------------------------
# Resolve Clang Linktime Problems
# CMake will adjust any linker flags from '-L path_to/mylib.so' to -lmylib
# if the proper mylib.so is automatically found by the linker, i.e.
# the directory comes first in LIBRARY_PATH.
# The clang linker however ignores LIBRARY_PATH.
# We thus explicitly add the content of LIBRARY_PATH to the LDFLAGS
# FIXME For future cmake versions we should populate the
# INTERFACE_LINK_DIRECTORIES of the triqs target
# ---------------------------------
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND DEFINED ENV{LIBRARY_PATH})
string(REPLACE ":" ";" LINK_DIRS $ENV{LIBRARY_PATH})
foreach(dir ${LINK_DIRS})
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -L${dir}")
string(APPEND CMAKE_MODULE_LINKER_FLAGS " -L${dir}")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -L${dir}")
endforeach()
endif()

# #############
# Build Project

Expand Down Expand Up @@ -165,7 +170,6 @@ if(BUILD_DEBIAN_PACKAGE AND NOT IS_SUBPROJECT)
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_CONTACT "https://github.com/TRIQS/${PROJECT_NAME}")
execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE CMAKE_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "triqs (>= 3.2)")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
include(CPack)
Expand Down
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

24 changes: 24 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See packaging for various base options
FROM flatironinstitute/triqs:base
ARG APPNAME=app4triqs

COPY requirements.txt /src/$APPNAME/requirements.txt
RUN pip3 install -r /src/$APPNAME/requirements.txt

RUN useradd -u 990 -m build

ENV SRC=/src \
BUILD=/home/build \
INSTALL=/usr/local \
PYTHONPATH=/usr/local/lib/python$PYTHON_VERSION/site-packages \
CMAKE_PREFIX_PATH=/usr/lib/cmake/$APPNAME

COPY --chown=build . $SRC/$APPNAME
WORKDIR $BUILD/$APPNAME
RUN chown build .
USER build
ARG BUILD_ID
ARG CMAKE_ARGS
RUN cmake $SRC/$APPNAME -DCMAKE_INSTALL_PREFIX=$INSTALL -DCLANG_OPT="$CXXFLAGS" $CMAKE_ARGS && make -j4 || make -j1 VERBOSE=1
USER root
RUN make install
27 changes: 11 additions & 16 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ def projectName = "app4triqs" /* set to app/repo name */
def dockerName = projectName.toLowerCase();
/* 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 keep and publish the results */
def keepInstall = !env.BRANCH_NAME.startsWith("PR-")
def publish = !env.BRANCH_NAME.startsWith("PR-")

properties([
disableConcurrentBuilds(),
buildDiscarder(logRotator(numToKeepStr: '10', daysToKeepStr: '30')),
pipelineTriggers(keepInstall ? [
pipelineTriggers(publish ? [
upstream(
threshold: 'SUCCESS',
upstreamProjects: triqsProject
upstreamProjects: '/TRIQS/cpp2py/master,/TRIQS/h5/unstable'
)
] : [])
])
Expand All @@ -34,13 +31,12 @@ for (int i = 0; i < dockerPlatforms.size(); i++) {
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
( cat packaging/Dockerfile.${env.STAGE_NAME} ; sed '0,/^FROM /d' Dockerfile.build ) > Dockerfile
"""
/* build and tag */
def args = ''
if (platform == documentationPlatform)
args = '-DBuild_Documentation=1'
args = '-DBuild_Documentation=1 -DMATHJAX_PATH=https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2'
else if (platform == "sanitize")
args = '-DASAN=ON -DUBSAN=ON'
def img = docker.build("flatironinstitute/${dockerName}:${env.BRANCH_NAME}-${env.STAGE_NAME}", "--build-arg APPNAME=${projectName} --build-arg BUILD_ID=${env.BUILD_TAG} --build-arg CMAKE_ARGS='${args}' .")
Expand All @@ -49,7 +45,7 @@ for (int i = 0; i < dockerPlatforms.size(); i++) {
sh "make -C \$BUILD/${projectName} test CTEST_OUTPUT_ON_FAILURE=1"
}
}
if (!keepInstall) {
if (!publish || platform != documentationPlatform) {
sh "docker rmi --no-prune ${img.imageName()}"
}
} } }
Expand All @@ -70,9 +66,8 @@ for (int i = 0; i < osxPlatforms.size(); i++) {
def tmpDir = pwd(tmp:true)
def buildDir = "$tmpDir/build"
/* install real branches in a fixed predictable place so apps can find them */
def installDir = keepInstall ? "${env.HOME}/install/${projectName}/${env.BRANCH_NAME}/${platform}" : "$tmpDir/install"
def triqsDir = "${env.HOME}/install/triqs/${triqsBranch}/${platform}"
def venv = triqsDir
def installDir = "$tmpDir/install"
def venv = installDir
dir(installDir) {
deleteDir()
}
Expand All @@ -91,9 +86,9 @@ for (int i = 0; i < osxPlatforms.size(); i++) {
"CMAKE_PREFIX_PATH=$venv/lib/cmake/triqs",
"OMP_NUM_THREADS=2"]) {
deleteDir()
/* note: this is installing into the parent (triqs) venv (install dir), which is thus shared among apps and so not be completely safe */
sh "python3 -m venv $venv"
sh "pip3 install -U -r $srcDir/requirements.txt"
sh "cmake $srcDir -DCMAKE_INSTALL_PREFIX=$installDir -DTRIQS_ROOT=$triqsDir"
sh "cmake $srcDir -DCMAKE_INSTALL_PREFIX=$installDir"
sh "make -j2 || make -j1 VERBOSE=1"
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') { try {
sh "make test CTEST_OUTPUT_ON_FAILURE=1"
Expand All @@ -111,7 +106,7 @@ for (int i = 0; i < osxPlatforms.size(); i++) {
def error = null
try {
parallel platforms
if (keepInstall) { node('linux && docker && triqs') {
if (publish) { node('linux && docker && triqs') {
/* Publish results */
stage("publish") { timeout(time: 5, unit: 'MINUTES') {
def commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![build](https://github.com/TRIQS/app4triqs/workflows/build/badge.svg)](https://github.com/TRIQS/app4triqs/actions?query=workflow%3Abuild)
[![build](https://github.com/TRIQS/app4triqs/workflows/build/badge.svg?branch=notriqs)](https://github.com/TRIQS/app4triqs/actions?query=workflow%3Abuild)

# app4triqs - A skeleton for a TRIQS application

Expand Down
12 changes: 7 additions & 5 deletions c++/app4triqs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ file(GLOB_RECURSE sources *.cpp)
add_library(${PROJECT_NAME}_c ${sources})
add_library(${PROJECT_NAME}::${PROJECT_NAME}_c ALIAS ${PROJECT_NAME}_c)

# Link against triqs and enable warnings
target_link_libraries(${PROJECT_NAME}_c PUBLIC triqs PRIVATE $<BUILD_INTERFACE:${PROJECT_NAME}_warnings>)
# Enable warnings
target_link_libraries(${PROJECT_NAME}_c PRIVATE $<BUILD_INTERFACE:${PROJECT_NAME}_warnings>)

# Configure target and compilation
target_compile_features(${PROJECT_NAME}_c PUBLIC cxx_std_23)
set_target_properties(${PROJECT_NAME}_c PROPERTIES
POSITION_INDEPENDENT_CODE ON
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
Expand All @@ -14,16 +15,17 @@ target_include_directories(${PROJECT_NAME}_c PUBLIC $<BUILD_INTERFACE:${PROJECT_
target_include_directories(${PROJECT_NAME}_c SYSTEM INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
target_compile_definitions(${PROJECT_NAME}_c PUBLIC
APP4TRIQS_GIT_HASH=${PROJECT_GIT_HASH}
TRIQS_GIT_HASH=${TRIQS_GIT_HASH}
$<$<CONFIG:Debug>:APP4TRIQS_DEBUG>
$<$<CONFIG:Debug>:TRIQS_DEBUG>
$<$<CONFIG:Debug>:TRIQS_ARRAYS_ENFORCE_BOUNDCHECK>
)

# Install library and headers
install(TARGETS ${PROJECT_NAME}_c EXPORT ${PROJECT_NAME}-targets DESTINATION lib)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")

# ========= Additional Depdencies ==========

# Link against HDF5 C++ Interface
target_link_libraries(${PROJECT_NAME}_c PUBLIC h5::h5_c)

# ========= Static Analyzer Checks ==========

Expand Down
2 changes: 0 additions & 2 deletions c++/app4triqs/app4triqs.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once
#include <triqs/gfs.hpp>
#include <triqs/mesh.hpp>
#include <h5/h5.hpp>

namespace app4triqs {
Expand Down
6 changes: 6 additions & 0 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ external_dependency(GTest
BUILD_ALWAYS
EXCLUDE_FROM_ALL
)

# -- h5 --
external_dependency(h5
GIT_REPO https://github.com/TRIQS/h5
GIT_TAG unstable
)
3 changes: 1 addition & 2 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ foreach(example ${ExampleList})
get_filename_component(d ${example} DIRECTORY)
add_executable(${PROJECT_NAME}_doc_${f} EXCLUDE_FROM_ALL ${example})
set_property(TARGET ${PROJECT_NAME}_doc_${f} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${d})
target_link_libraries(${PROJECT_NAME}_doc_${f} triqs)
add_custom_command(TARGET ${PROJECT_NAME}_doc_${f}
COMMAND ${PROJECT_NAME}_doc_${f} > ${CMAKE_CURRENT_SOURCE_DIR}/${d}/${f}.output 2>/dev/null
WORKING_DIRECTORY ${d}
Expand All @@ -56,7 +55,7 @@ endif()
add_custom_target(${PROJECT_NAME}_docs_sphinx ALL)
add_custom_command(
TARGET ${PROJECT_NAME}_docs_sphinx
COMMAND PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH} ${SPHINXBUILD_EXECUTABLE} -j auto -c . -b html ${CMAKE_CURRENT_SOURCE_DIR} html
COMMAND PYTHONPATH=${PROJECT_BINARY_DIR}/python:${h5_BINARY_DIR}/python:$ENV{PYTHONPATH} ${SPHINXBUILD_EXECUTABLE} -c . -j auto -b html ${CMAKE_CURRENT_SOURCE_DIR} html
)

option(Sphinx_Only "When building the documentation, skip the Python Modules and the generation of C++ Api and example outputs" OFF)
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion doc/_static/triqs_logo/Icon/SVG/Triqs_Icon_RGB_Black.svg

This file was deleted.

1 change: 0 additions & 1 deletion doc/_static/triqs_logo/Icon/SVG/Triqs_Icon_RGB_Full.svg

This file was deleted.

1 change: 0 additions & 1 deletion doc/_static/triqs_logo/Icon/SVG/Triqs_Icon_RGB_White.svg

This file was deleted.

Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 178fe60

Please sign in to comment.