Skip to content

Commit

Permalink
From template
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Mar 21, 2024
0 parents commit 4819c88
Show file tree
Hide file tree
Showing 66 changed files with 3,634 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .ci_support/run_docker_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

set -xe

cd /tmp
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=~/.local \
-DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=32 \
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Wshadow -Werror -D_GLIBCXX_ASSERTIONS" \
-DSWIG_COMPILE_FLAGS="-O1 -Wno-unused-parameter -Wno-shadow" \
-DSPHINX_FLAGS="-W -T -j4" \
/io
make install
make tests
ctest --output-on-failure --timeout 100 ${MAKEFLAGS}

uid=$1
gid=$2
if test -n "${uid}" -a -n "${gid}"
then
sudo cp -r ~/.local/share/doc/*/html /io
sudo chown -R ${uid}:${gid} /io/html
fi
21 changes: 21 additions & 0 deletions .ci_support/run_docker_mingw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

set -xe

cd /tmp
mkdir build && cd build

PREFIX=${PWD}/install
CXXFLAGS="-Wall -Wextra -D_GLIBCXX_ASSERTIONS" ${ARCH}-w64-mingw32-cmake \
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
-DPython_INCLUDE_DIR=${MINGW_PREFIX}/include/python${PYMAJMIN} \
-DPython_LIBRARY=${MINGW_PREFIX}/lib/libpython${PYMAJMIN}.dll.a \
-DPython_EXECUTABLE=/usr/bin/${ARCH}-w64-mingw32-python${PYMAJMIN}-bin \
-DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=32 \
/io
make install
${ARCH}-w64-mingw32-strip --strip-unneeded ${PREFIX}/bin/*.dll ${PREFIX}/Lib/site-packages/*/*.pyd
echo lib/test ${PREFIX}/Lib/site-packages/* | xargs -n 1 cp ${PREFIX}/bin/*.dll
OPENTURNS_NUM_THREADS=2 ctest -R pyinstallcheck --output-on-failure --timeout 1000 --schedule-random ${MAKEFLAGS}
make tests
OPENTURNS_NUM_THREADS=2 ctest -R cppcheck --output-on-failure --timeout 1000 --schedule-random ${MAKEFLAGS}
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build
on:
push:
branches: [ master ]
pull_request:
jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: |
docker pull openturns/archlinux-module
docker run -e MAKEFLAGS='-j2' -v `pwd`:/io openturns/archlinux-module /io/.ci_support/run_docker_linux.sh `id -u` `id -g`
- name: Upload
if: ${{ github.ref == 'refs/heads/master' }}
run: |
exit 0
git clone --depth 1 https://${{ secrets.GH_TOKEN }}@github.com/openturns/openturns.github.io.git /tmp/io
mkdir -p /tmp/io/ottemplate/master
cp -r html/* /tmp/io/ottemplate/master
cd /tmp/io
touch .nojekyll
git config user.email "[email protected]"
git config user.name "GitHub Actions"
git add -A .
git commit -a -m "GitHub Actions build ${GITHUB_REPOSITORY} ${GITHUB_RUN_ID}" || exit 0
git push --quiet origin master > /dev/null 2>&1
mingw:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: |
docker pull openturns/archlinux-module-mingw
docker run -e MAKEFLAGS='-j2' -v `pwd`:/io openturns/archlinux-module-mingw /io/.ci_support/run_docker_mingw.sh
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint source code

on: [push, pull_request]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install
run: |
sudo apt-get install python3-pip
pip3 install flake8
- name: Run linter
run: ./utils/lint.sh

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build*/
*~
Empty file added AUTHORS
Empty file.
209 changes: 209 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
cmake_minimum_required (VERSION 3.13)

option (BUILD_PYTHON "Build the python module for the library" ON)
option (USE_SPHINX "Use sphinx for documentation" ON)
option (BUILD_SHARED_LIBS "Build shared libraries" ON)

# By default, build in Release mode. Must appear before project() command
set( CMAKE_BUILD_TYPE Release CACHE STRING "Build type")

project (ottemplate)

string (TOLOWER ${CMAKE_PROJECT_NAME} PACKAGE_NAME)

# set module dir to find custom scripts
list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

if (POLICY CMP0042)
# MACOSX_RPATH is enabled by default
cmake_policy(SET CMP0042 NEW)
endif()
if (POLICY CMP0078)
# UseSWIG generates standard target names
cmake_policy(SET CMP0078 NEW)
endif()
if (POLICY CMP0086)
# UseSWIG honors SWIG_MODULE_NAME via -module flag
cmake_policy(SET CMP0086 NEW)
endif()

find_package (OpenTURNS CONFIG REQUIRED)
message (STATUS "Found OpenTURNS: ${OPENTURNS_ROOT_DIR} (found version \"${OPENTURNS_VERSION_STRING}\")")
if (NOT DEFINED OPENTURNS_PYTHON_MODULE_PATH)
set (OPENTURNS_PYTHON_MODULE_PATH ${OPENTURNS_PYTHON3_MODULE_PATH})
endif ()

if (NOT BUILD_SHARED_LIBS)
list ( APPEND OTTEMPLATE_DEFINITIONS "-DOTTEMPLATE_STATIC" )
endif ()
add_definitions ( ${OTTEMPLATE_DEFINITIONS} )

if (MSVC)
# Disable some warnings
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4197 /wd4244 /wd4251 /wd4267 /wd4996")
endif ()

include (GNUInstallDirs)

set (OTTEMPLATE_LIBRARY_PATH ${CMAKE_INSTALL_LIBDIR})
set (OTTEMPLATE_INCLUDE_PATH ${CMAKE_INSTALL_INCLUDEDIR})
set (OTTEMPLATE_SWIG_INCLUDE_DIRS ${OTTEMPLATE_INCLUDE_PATH}/${PACKAGE_NAME}/swig)
set (OTTEMPLATE_DATA_PATH ${CMAKE_INSTALL_DATAROOTDIR})
set (OTTEMPLATE_CONFIG_CMAKE_PATH ${CMAKE_INSTALL_LIBDIR}/cmake/ottemplate)
set (OTTEMPLATE_DOC_PATH ${CMAKE_INSTALL_DOCDIR})

set (CMAKE_CXX_STANDARD 11)

if (BUILD_PYTHON)
find_package (SWIG 3)
include (${SWIG_USE_FILE})

if (CMAKE_VERSION VERSION_LESS 3.24)
find_package (Python 3.5 COMPONENTS Interpreter Development)
else ()
find_package (Python 3.5 COMPONENTS Interpreter Development.Module)
endif ()

if (Python_FOUND)
include (FindPythonModule)
find_python_module (matplotlib)
if (NOT TARGET Python::Module)
include (TargetLinkLibrariesWithDynamicLookup)
endif ()

if (USE_SPHINX)
find_program (SPHINX_EXECUTABLE NAMES sphinx-build DOC "Sphinx Documentation Builder (sphinx-doc.org)")
find_python_module (numpydoc)
find_python_module (sphinx_gallery)
if (SPHINX_EXECUTABLE AND NUMPYDOC_FOUND AND SPHINX_GALLERY_FOUND AND MATPLOTLIB_FOUND)
find_python_module (sphinx)
endif ()
if (NOT SPHINX_FOUND)
message (STATUS "Disabling documentation (need sphinx/pandoc/numpydoc/sphinx-gallery/matplotlib)")
endif ()
endif ()

if (WIN32)
set (OTTEMPLATE_PYTHON_MODULE_PATH Lib/site-packages CACHE PATH "site-packages dir")
else ()
set (OTTEMPLATE_PYTHON_MODULE_PATH ${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages CACHE PATH "site-packages dir")
endif ()
endif ()
endif ()


# Define variables without OTTEMPLATE_ prefix with absolute paths
foreach (_var PYTHON_MODULE_PATH LIBRARY_PATH INCLUDE_PATH CONFIG_CMAKE_PATH)
if (IS_ABSOLUTE "${OTTEMPLATE_${_var}}")
set (${_var} ${OTTEMPLATE_${_var}})
else ()
set (${_var} ${CMAKE_INSTALL_PREFIX}/${OTTEMPLATE_${_var}})
endif ()
get_filename_component (${_var} "${${_var}}" ABSOLUTE)
file (TO_NATIVE_PATH "${${_var}}" NATIVE_${_var})
string (REPLACE "\\" "\\\\" NATIVE_${_var} ${NATIVE_${_var}})
endforeach ()

# RPATH settings
set (CMAKE_INSTALL_RPATH ${LIBRARY_PATH})
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Some useful macros to ease CMakeLists.txt file writing
set (SOURCEFILES "" CACHE INTERNAL "List of source files to compile")
macro (ot_add_source_file FILENAME)
set (sf ${SOURCEFILES} ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME})
set (SOURCEFILES ${sf} CACHE INTERNAL "List of source files to compile")
endmacro ()

macro (ot_install_header_file FILENAME)
install (FILES ${PACKAGE_NAME}/${FILENAME} DESTINATION ${OTTEMPLATE_INCLUDE_PATH}/${PACKAGE_NAME})
endmacro ()

macro (ot_install_swig_file FILENAME)
install (FILES ${FILENAME} DESTINATION ${OTTEMPLATE_SWIG_INCLUDE_DIRS})
endmacro ()

set (INTERNAL_INCLUDE_DIRS "" CACHE INTERNAL "List of directories with header files needed for build")
macro (ot_add_current_dir_to_include_dirs)
set (inc_dirs ${INTERNAL_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
set (INTERNAL_INCLUDE_DIRS ${inc_dirs} CACHE INTERNAL "List of directories with header files needed for build")
endmacro ()


set ( CPACK_PACKAGE_NAME ${PACKAGE_NAME} )
set ( CPACK_PACKAGE_VERSION_MAJOR 0 )
set ( CPACK_PACKAGE_VERSION_MINOR 0 )
set ( CPACK_PACKAGE_VERSION_PATCH )
set ( CPACK_SOURCE_GENERATOR "TGZ;TBZ2" )
set (CPACK_BINARY_STGZ OFF CACHE BOOL "STGZ")
set (CPACK_BINARY_TBZ2 ON CACHE BOOL "TBZ2")
set (CPACK_BINARY_TGZ ON CACHE BOOL "TGZ" )
set (CPACK_BINARY_TZ OFF CACHE BOOL "TZ" )
set ( CPACK_SOURCE_IGNORE_FILES "/.git;/build;.*~;${CPACK_SOURCE_IGNORE_FILES}" )
set ( PACKAGE_NAME ${CPACK_PACKAGE_NAME} )
set ( PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR} )
if ( CPACK_PACKAGE_VERSION_PATCH )
set ( PACKAGE_VERSION ${PACKAGE_VERSION}.${CPACK_PACKAGE_VERSION_PATCH} )
endif ()
set ( CPACK_SOURCE_PACKAGE_FILE_NAME ${PACKAGE_NAME}-${PACKAGE_VERSION} )


# The tests can't be run if this function is absent
enable_testing ()
add_custom_target (tests COMMENT "Build tests")
add_custom_target (check COMMENT "Run pre-installation tests")
add_custom_target (installcheck COMMENT "Run post-installation tests")

add_subdirectory (lib)
add_dependencies (check cppcheck)

if (Python_FOUND AND SWIG_FOUND)
add_subdirectory (python)
add_dependencies (installcheck pyinstallcheck)
endif ()


# uninstall target
configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
IMMEDIATE @ONLY
)

add_custom_target ( uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)

set ( OTTEMPLATE_LIBRARY ottemplate )
set ( OTTEMPLATE_LIBRARIES ${OPENTURNS_LIBRARIES} )
list ( APPEND OTTEMPLATE_LIBRARIES ${OTTEMPLATE_LIBRARY} )
set ( OTTEMPLATE_LIBRARY_DIRS ${OPENTURNS_LIBRARY_DIRS} )
list ( APPEND OTTEMPLATE_LIBRARY_DIRS ${LIBRARY_PATH} )
set ( OTTEMPLATE_INCLUDE_DIR ${INCLUDE_PATH} )
set ( OTTEMPLATE_INCLUDE_DIRS ${OTTEMPLATE_INCLUDE_DIR} )
set ( OTTEMPLATE_ROOT_DIR ${CMAKE_INSTALL_PREFIX} )
list ( APPEND OTTEMPLATE_INCLUDE_DIRS ${OPENTURNS_INCLUDE_DIRS} )
set ( OTTEMPLATE_VERSION_STRING ${PACKAGE_VERSION} )
set ( OTTEMPLATE_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR} )
set ( OTTEMPLATE_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR} )
set ( OTTEMPLATE_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH} )

include(CMakePackageConfigHelpers)
configure_package_config_file (cmake/OTTemplateConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/OTTemplateConfig.cmake
INSTALL_DESTINATION ${OTTEMPLATE_CONFIG_CMAKE_PATH}
PATH_VARS
OTTEMPLATE_ROOT_DIR
OTTEMPLATE_INCLUDE_DIR
OTTEMPLATE_INCLUDE_DIRS
OTTEMPLATE_LIBRARY_DIRS
PYTHON_MODULE_PATH
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

write_basic_package_version_file (OTTemplateConfigVersion.cmake VERSION ${OTTEMPLATE_VERSION_STRING} COMPATIBILITY AnyNewerVersion)

install (FILES ${CMAKE_CURRENT_BINARY_DIR}/OTTemplateConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/OTTemplateConfigVersion.cmake
DESTINATION ${OTTEMPLATE_CONFIG_CMAKE_PATH})

include (CPack)
Loading

0 comments on commit 4819c88

Please sign in to comment.