Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BasedOnStyle: Google
AccessModifierOffset: -1
ColumnLimit: 120
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
DerivePointerAlignment: false
SortIncludes: false
PointerAlignment: Left
106 changes: 106 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: CI Tests

on:
pull_request:
push:
branches:
- develop

# Cancel previous jobs if an update has been made to the pull request
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/develop' }}

env:
CLANG_DOCKER_IMAGE: seracllnl/tpls:clang-19_10-09-25_23h-54m
GCC_DOCKER_IMAGE: seracllnl/tpls:gcc-14_10-09-25_23h-54m

jobs:
# Hacky solution to reference env variables outside of `run` steps https://stackoverflow.com/a/74217028
set_image_vars:
runs-on: ubuntu-latest
steps:
- name: Do Nothing
run: echo
outputs:
clang_docker_image: ${{ env.CLANG_DOCKER_IMAGE }}
gcc_docker_image: ${{ env.GCC_DOCKER_IMAGE }}
build_and_test:
runs-on: ubuntu-24.04
needs:
- set_image_vars
strategy:
fail-fast: true
matrix:
build_type: [ Debug, Release ]
config:
- job_name: llvm@19.1.1, shared
host_config: llvm@19.1.1.cmake
compiler_image: ${{ needs.set_image_vars.outputs.clang_docker_image }}
cmake_opts: "-DBUILD_SHARED_LIBS=ON"
- job_name: gcc@14.2.0, shared
host_config: gcc@14.2.0.cmake
compiler_image: ${{ needs.set_image_vars.outputs.gcc_docker_image }}
cmake_opts: "-DBUILD_SHARED_LIBS=ON"
- job_name: llvm@19.1.1, static
host_config: llvm@19.1.1.cmake
compiler_image: ${{ needs.set_image_vars.outputs.clang_docker_image }}
- job_name: gcc@14.2.0, static
host_config: gcc@14.2.0.cmake
compiler_image: ${{ needs.set_image_vars.outputs.gcc_docker_image }}
name: ${{ matrix.build_type }} - ${{ matrix.config.job_name }}
container:
image: ${{ matrix.config.compiler_image }}
volumes:
- /home/serac/serac
# Required - default is set to user "serac"
options: --user root
steps:
- name: Checkout Gretl
uses: actions/checkout@v4
with:
submodules: recursive
- name: Print Matrix Variables
run: |
echo "build_src_opts ${{ matrix.config.build_src_opts }}"
echo "build_type ${{ matrix.build_type }}"
echo "cmake_opts ${{ matrix.config.cmake_opts }}"
echo "compiler_image ${{ matrix.config.compiler_image }}"
echo "host_config ${{ matrix.config.host_config }}"
- name: Build and Test ${{ matrix.build_type }} - ${{ matrix.config.job_name }}
timeout-minutes: 80
run: |
HOST_CONFIG=${{ matrix.config.host_config }} \
CMAKE_EXTRA_FLAGS=" ${{ matrix.config.cmake_opts }} " \
BUILD_TYPE=${{ matrix.build_type }} \
./scripts/github-actions/linux-build_and_test.sh
- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: Test Results ${{ matrix.config.host_config }} ${{ matrix.build_type }} ${{ matrix.config.cmake_opts }}
path: "**/Test.xml"
check_code:
runs-on: ubuntu-24.04
needs:
- set_image_vars
strategy:
# If any of checks (e.g. style) fail, allow other jobs to continue running.
fail-fast: false
matrix:
check_type: [style, header]
container:
image: ${{ needs.set_image_vars.outputs.clang_docker_image }}
volumes:
- /home/serac/serac
# Required - default is set to user "serac"
options: --user root
env:
CHECK_TYPE: ${{ matrix.check_type }}
HOST_CONFIG: llvm@19.1.1.cmake
steps:
- name: Checkout Gretl
uses: actions/checkout@v4
with:
submodules: recursive
- name: Check ${{ matrix.check_type }}
run: ./scripts/github-actions/linux-check.sh
29 changes: 27 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
*~
build
/build*/
/install*/
*.swp
*.code-workspace
/uberenv_libs*
/spack*
/src/docs/doxygen/html/
/src/docs/doxygen/xml/
/src/docs/sphinx/_build/
/src/docs/_build
/*.cmake
.vscode/
*.orig
__pycache__/
view
/_smith_build_and_test*
build-linux-*-*-*
build-darwin-*-*-*
*.core
radiuss
.cache
.dotnet
.vscode-server
.gitconfig
.bash_history
.sudo_as_admin_successful
.viminfo
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cmake/blt"]
path = cmake/blt
url = https://github.com/LLNL/blt.git
135 changes: 99 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,106 @@
# SPDX-License-Identifier: (BSD-3-Clause)

cmake_minimum_required(VERSION 3.16)
project(gretl LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

file(GLOB_RECURSE cpp_sources
${PROJECT_SOURCE_DIR}/src/*.cpp
${PROJECT_SOURCE_DIR}/src/*.hpp)

add_library(gretl ${cpp_sources})

target_include_directories(gretl PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)

file(GLOB_RECURSE gretl_headers
${PROJECT_SOURCE_DIR}/src/*.hpp)

# Specify public headers for the library
set_target_properties(gretl PROPERTIES PUBLIC_HEADER gretl_headers)

# Install the library and its public headers
install(TARGETS gretl
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gretl)

if (GRETL_ENABLE_ASAN)
add_link_options(-fsanitize=address)
add_compile_options(-fsanitize=address)
project(gretl LANGUAGES C CXX)

#------------------------------------------------------------------------------
# Setup BLT
#------------------------------------------------------------------------------

if(DEFINED BLT_SOURCE_DIR)
# Support having a shared BLT outside of the repository if given a BLT_SOURCE_DIR
if(NOT EXISTS ${BLT_SOURCE_DIR}/SetupBLT.cmake)
message(FATAL_ERROR "Given BLT_SOURCE_DIR does not contain SetupBLT.cmake")
endif()
else()
set(BLT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/cmake/blt" CACHE PATH "")
if (NOT EXISTS ${BLT_SOURCE_DIR}/SetupBLT.cmake)
message(FATAL_ERROR
"The BLT is not present. "
"Either run the following two commands in your git repository: \n"
" git submodule init\n"
" git submodule update\n"
"Or add -DBLT_SOURCE_DIR=/path/to/blt to your CMake command." )
endif()
endif()

# Tune BLT to our needs
if (NOT BLT_CXX_STD)
set(BLT_CXX_STD "c++17" CACHE STRING "")
endif()

# These BLT tools are not used in Gretl, turn them off
set(_unused_blt_tools
CLANGQUERY
CLANGTIDY
DOXYGEN
SPHINX
VALGRIND
ASTYLE
CMAKEFORMAT
UNCRUSTIFY
YAPF)
foreach(_tool ${_unused_blt_tools})
set(ENABLE_${_tool} OFF CACHE BOOL "")
endforeach()

# These BLT tools are only used by Gretl developers, so turn them off
# unless an explicit executable path is given
set(_used_blt_tools
CLANGFORMAT
CPPCHECK)
foreach(_tool ${_used_blt_tools})
if(NOT ${_tool}_EXECUTABLE)
set(ENABLE_${_tool} OFF CACHE BOOL "")
else()
set(ENABLE_${_tool} ON CACHE BOOL "")
endif()
endforeach()

set(BLT_REQUIRED_CLANGFORMAT_VERSION "19" CACHE STRING "")

set(ENABLE_ALL_WARNINGS ON CACHE BOOL "")
set(ENABLE_WARNINGS_AS_ERRORS ON CACHE BOOL "")

set(BLT_EXPORT_THIRDPARTY OFF CACHE BOOL "")
if (BLT_EXPORT_THIRDPARTY)
message(FATAL_ERROR "Gretl does not use BLT's exporting of TPLs, it conflicts with the new blt_install_tpl_setups macro.")
endif()

if (GRETL_ENABLE_TESTING)
enable_testing()
add_subdirectory(tests)
include(${BLT_SOURCE_DIR}/SetupBLT.cmake)

#------------------------------------------------------------------------------
# Setup Macros/Basics
#------------------------------------------------------------------------------

include(${PROJECT_SOURCE_DIR}/cmake/GretlMacros.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/GretlBasics.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/GretlCompilerFlags.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/GretlConfigHeader.cmake)

#------------------------------------------------------------------------------
# Add Code Checks
#------------------------------------------------------------------------------

message(STATUS "Gretl Code Checks: ${GRETL_ENABLE_CODE_CHECKS}")

if (GRETL_ENABLE_CODE_CHECKS)
gretl_add_code_checks(PREFIX gretl)
endif()


#------------------------------------------------------------------------------
# Add subdirectories
#------------------------------------------------------------------------------

add_subdirectory(src)


#------------------------------------------------------------------------------
# Export Targets
#------------------------------------------------------------------------------

install(EXPORT gretl-targets
NAMESPACE gretl::
DESTINATION lib/cmake
)
27 changes: 27 additions & 0 deletions cmake/GretlBasics.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) Lawrence Livermore National Security, LLC and
# other Gretl Project Developers. See the top-level LICENSE file for
# details.
#
# SPDX-License-Identifier: (BSD-3-Clause)

#------------------------------------------------------------------------------
# Options
#------------------------------------------------------------------------------
option(ENABLE_ASAN "Enable AddressSanitizer for memory checking (Clang or GCC only)" OFF)
if(ENABLE_ASAN)
if(NOT (C_COMPILER_FAMILY_IS_CLANG OR C_COMPILER_FAMILY_IS_GNU))
message(FATAL_ERROR "ENABLE_ASAN only supports Clang and GCC")
endif()
endif()

# Only enable Gretl's code checks by default if it is the top-level project
# or a user overrides it
if("${CMAKE_PROJECT_NAME}" STREQUAL "gretl")
set(_enable_gretl_code_checks ON)
else()
set(_enable_gretl_code_checks OFF)
endif()
option(GRETL_ENABLE_CODE_CHECKS "Enable Gretl's code checks" ${_enable_gretl_code_checks})

cmake_dependent_option(GRETL_ENABLE_TESTS "Enables Gretl Tests" ON "ENABLE_TESTS" OFF)

29 changes: 29 additions & 0 deletions cmake/GretlCompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Lawrence Livermore National Security, LLC and
# other Gretl Project Developers. See the top-level LICENSE file for
# details.
#
# SPDX-License-Identifier: (BSD-3-Clause)

if(ENABLE_ASAN)
message(STATUS "AddressSanitizer is ON (ENABLE_ASAN)")
foreach(_flagvar CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS)
string(APPEND ${_flagvar} " -fsanitize=address -fno-omit-frame-pointer")
endforeach()
endif()

# Need to add symbols to dynamic symtab in order to be visible from stacktraces
string(APPEND CMAKE_EXE_LINKER_FLAGS " -rdynamic")

# Prevent unused -Xlinker arguments on Lassen Clang-10
if(DEFINED ENV{SYS_TYPE} AND "$ENV{SYS_TYPE}" STREQUAL "blueos_3_ppc64le_ib_p9")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wno-unused-command-line-argument")
endif()

# Enable warnings for things not covered by -Wall -Wextra
set(_extra_flags "-Wshadow -Wdouble-promotion -Wconversion -Wundef -Wnull-dereference -Wold-style-cast")
blt_append_custom_compiler_flag(FLAGS_VAR CMAKE_CXX_FLAGS DEFAULT ${_extra_flags})

# Only clang has fine-grained control over the designated initializer warnings
# This can be added to the GCC flags when C++20 is available
# This should be compatible with Clang 8 through Clang 12
blt_append_custom_compiler_flag(FLAGS_VAR CMAKE_CXX_FLAGS CLANG "-Wpedantic -Wno-c++2a-extensions -Wunused-private-field")
Loading