diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..6110960 --- /dev/null +++ b/.clang-format @@ -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 diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml new file mode 100644 index 0000000..188fa58 --- /dev/null +++ b/.github/workflows/ci-tests.yml @@ -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 diff --git a/.gitignore b/.gitignore index 796b86c..ceaa4fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,27 @@ -*~ -build \ No newline at end of file +/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 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b25a296 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cmake/blt"] + path = cmake/blt + url = https://github.com/LLNL/blt.git diff --git a/CMakeLists.txt b/CMakeLists.txt index ad07e2f..1a57b11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 - $ - $ - $ - ) - -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 + ) diff --git a/cmake/GretlBasics.cmake b/cmake/GretlBasics.cmake new file mode 100644 index 0000000..6fc4e17 --- /dev/null +++ b/cmake/GretlBasics.cmake @@ -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) + diff --git a/cmake/GretlCompilerFlags.cmake b/cmake/GretlCompilerFlags.cmake new file mode 100644 index 0000000..d9f6bae --- /dev/null +++ b/cmake/GretlCompilerFlags.cmake @@ -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") diff --git a/cmake/GretlConfigHeader.cmake b/cmake/GretlConfigHeader.cmake new file mode 100644 index 0000000..deedd0c --- /dev/null +++ b/cmake/GretlConfigHeader.cmake @@ -0,0 +1,110 @@ +# 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) + +#------------------------------------------------------------------------------ +# Version information that go into the generated config header +#------------------------------------------------------------------------------ +set(GRETL_VERSION_MAJOR 0) +set(GRETL_VERSION_MINOR 0) +set(GRETL_VERSION_PATCH 1) +string(CONCAT GRETL_VERSION_FULL + "v${GRETL_VERSION_MAJOR}" + ".${GRETL_VERSION_MINOR}" + ".${GRETL_VERSION_PATCH}" ) + +if (Git_FOUND) + ## check to see if we are building from a Git repo or an exported tarball + blt_is_git_repo( OUTPUT_STATE is_git_repo ) + + if(${is_git_repo}) + blt_git_hashcode(HASHCODE sha1 RETURN_CODE rc) + if(NOT ${rc} EQUAL 0) + message(FATAL_ERROR "blt_git_hashcode failed!") + endif() + + set(GRETL_GIT_SHA ${sha1}) + endif() + +endif() + +message(STATUS "Configuring Gretl version ${GRETL_VERSION_FULL}") + + +#-------------------------------------------------------------------------- +# Add define we can use when debug builds are enabled +#-------------------------------------------------------------------------- +set(GRETL_DEBUG FALSE) +if(CMAKE_BUILD_TYPE MATCHES "(Debug|RelWithDebInfo)") + set(GRETL_DEBUG TRUE) + + # Controls various behaviors in Axom, like turning off/on SLIC debug and assert macros + set(AXOM_DEBUG TRUE) +endif() + + +#------------------------------------------------------------------------------ +# General Build Info +#------------------------------------------------------------------------------ +gretl_convert_to_native_escaped_file_path(${PROJECT_SOURCE_DIR} GRETL_REPO_DIR) +gretl_convert_to_native_escaped_file_path(${CMAKE_BINARY_DIR} GRETL_BINARY_DIR) + +#------------------------------------------------------------------------------ +# Create Config Header +#------------------------------------------------------------------------------ +gretl_configure_file( + ${PROJECT_SOURCE_DIR}/src/gretl/config.hpp.in + ${PROJECT_BINARY_DIR}/include/gretl/config.hpp +) + +install(FILES ${PROJECT_BINARY_DIR}/include/gretl/config.hpp DESTINATION include/gretl) + +#------------------------------------------------------------------------------ +# Generate gretl-config.cmake for importing Gretl into other CMake packages +#------------------------------------------------------------------------------ + +# Set up some paths, preserve existing cache values (if present) +set(GRETL_INSTALL_INCLUDE_DIR "include" CACHE STRING "") +set(GRETL_INSTALL_CONFIG_DIR "lib" CACHE STRING "") +set(GRETL_INSTALL_LIB_DIR "lib" CACHE STRING "") +set(GRETL_INSTALL_BIN_DIR "bin" CACHE STRING "") +set(GRETL_INSTALL_CMAKE_MODULE_DIR "${GRETL_INSTALL_CONFIG_DIR}/cmake" CACHE STRING "") + +set(GRETL_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "" FORCE) + + +include(CMakePackageConfigHelpers) + +# Add version helper +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/gretl-config-version.cmake + VERSION ${GRETL_VERSION_FULL} + COMPATIBILITY AnyNewerVersion +) + +# Set up cmake package config file +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/gretl-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/gretl-config.cmake + INSTALL_DESTINATION + ${GRETL_INSTALL_CONFIG_DIR} + PATH_VARS + GRETL_INSTALL_INCLUDE_DIR + GRETL_INSTALL_LIB_DIR + GRETL_INSTALL_BIN_DIR + GRETL_INSTALL_CMAKE_MODULE_DIR + ) + +# Install config files +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/gretl-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/gretl-config-version.cmake + DESTINATION + ${GRETL_INSTALL_CMAKE_MODULE_DIR} +) + +# Install BLT files that recreate BLT targets in downstream projects +blt_install_tpl_setups(DESTINATION ${GRETL_INSTALL_CMAKE_MODULE_DIR}) diff --git a/cmake/GretlMacros.cmake b/cmake/GretlMacros.cmake new file mode 100644 index 0000000..4d1a0ed --- /dev/null +++ b/cmake/GretlMacros.cmake @@ -0,0 +1,283 @@ +# 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) + +##------------------------------------------------------------------------------ +## Adds code checks for all cpp/hpp files recursively under the current directory +## that regex match INCLUDES and excludes any files that regex match EXCLUDES +## +## This creates the following parent build targets: +## check - Runs a non file changing style check and CppCheck +## style - In-place code formatting +## +## Creates various child build targets that follow this pattern: +## gretl_ +## gretl__ +## +## This also creates targets for running clang-tidy on the src/ and test/ +## directories, with a more permissive set of checks for the tests, +## called gretl_guidelines_check and gretl_guidelines_check_tests, respectively +##------------------------------------------------------------------------------ +macro(gretl_add_code_checks) + + set(options) + set(singleValueArgs PREFIX) + set(multiValueArgs) + + # Parse the arguments to the macro + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) + + # Create file globbing expressions that only include directories that contain source + set(_base_dirs "tests" "src" "examples") + # Note: any extensions added here should also be added to BLT's lists in CMakeLists.txt + set(_ext_expressions "*.cpp" "*.hpp" "*.inl" "*.cuh" "*.cu" "*.cpp.in" "*.hpp.in") + + set(_glob_expressions) + foreach(_exp ${_ext_expressions}) + foreach(_base_dir ${_base_dirs}) + list(APPEND _glob_expressions "${PROJECT_SOURCE_DIR}/${_base_dir}/${_exp}") + endforeach() + endforeach() + + # Glob for list of files to run code checks on + set(_sources) + file(GLOB_RECURSE _sources ${_glob_expressions}) + + blt_add_code_checks(PREFIX ${arg_PREFIX} + SOURCES ${_sources} + CLANGFORMAT_CFG_FILE ${PROJECT_SOURCE_DIR}/.clang-format + CPPCHECK_FLAGS --enable=all --inconclusive) + + + set(_src_sources) + file(GLOB_RECURSE _src_sources "src/*.cpp" "src/*.hpp" "src/*.inl") + list(FILTER _src_sources EXCLUDE REGEX ".*/tests/.*pp") + + blt_add_clang_tidy_target(NAME ${arg_PREFIX}_guidelines_check + CHECKS "clang-analyzer-*,clang-analyzer-cplusplus*,cppcoreguidelines-*" + SRC_FILES ${_src_sources}) + + # Create list of recursive test directory glob expressions + # NOTE: GLOB operator ** did not appear to be supported by cmake and did not recursively find test subdirectories + # NOTE: Do not include all directories at root (for example: blt) + + file(GLOB_RECURSE _test_sources "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/tests/*.cpp") + list(FILTER _test_sources INCLUDE REGEX ".*/tests/.*pp") + + blt_add_clang_tidy_target(NAME ${arg_PREFIX}_guidelines_check_tests + CHECKS "clang-analyzer-*,clang-analyzer-cplusplus*,cppcoreguidelines-*,-cppcoreguidelines-avoid-magic-numbers" + SRC_FILES ${_test_sources}) + + if (ENABLE_COVERAGE) + blt_add_code_coverage_target(NAME ${arg_PREFIX}_coverage + RUNNER ${CMAKE_MAKE_PROGRAM} test + SOURCE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src ) + endif() + +endmacro(gretl_add_code_checks) + + +##------------------------------------------------------------------------------ +## gretl_convert_to_native_escaped_file_path( path output ) +## +## This macro converts a cmake path to a platform specific string literal +## usable in C++. (For example, on windows C:/Path will be come C:\\Path) +##------------------------------------------------------------------------------ +macro(gretl_convert_to_native_escaped_file_path path output) + file(TO_NATIVE_PATH ${path} ${output}) + string(REPLACE "\\" "\\\\" ${output} "${${output}}") +endmacro(gretl_convert_to_native_escaped_file_path) + + +##------------------------------------------------------------------------------ +## gretl_remove_string_prefix +## +## This macro removes a string prefix from a given string. +## +## PREFIX - String prefix to be removed +## INPUT - String with possible prefix to be removed +## OUTPUT_VAR - Possibly altered output string +## +##------------------------------------------------------------------------------ +macro(gretl_remove_string_prefix) + set(options) + set(singleValueArgs PREFIX INPUT OUTPUT_VAR) + set(multiValueArgs) + + # Parse the arguments to the macro + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT DEFINED arg_PREFIX) + message(FATAL_ERROR "PREFIX is required") + endif() + + if(NOT DEFINED arg_INPUT) + message(FATAL_ERROR "INPUT is required") + endif() + + if(NOT DEFINED arg_OUTPUT_VAR) + message(FATAL_ERROR "OUTPUT_VAR is required") + endif() + + string(LENGTH "${arg_PREFIX}" _prefix_len) + string(SUBSTRING "${arg_INPUT}" 0 ${_prefix_len} _actual_prefix) + + if(_actual_prefix STREQUAL "${arg_PREFIX}") + string(REPLACE "${arg_PREFIX}" "" _stripped_path "${arg_INPUT}") + set(${arg_OUTPUT_VAR} "${_stripped_path}") + else() + set(${arg_OUTPUT_VAR} "${arg_INPUT}") + endif() +endmacro() + + +##------------------------------------------------------------------------------ +## gretl_configure_file +## +## This macro is a thin wrapper over the builtin configure_file command. +## It has the same arguments/options as configure_file but introduces an +## intermediate file that is only copied to the target file if the target differs +## from the intermediate. +##------------------------------------------------------------------------------ +macro(gretl_configure_file _source _target) + set(_tmp_target ${_target}.tmp) + configure_file(${_source} ${_tmp_target} ${ARGN}) + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_tmp_target} ${_target}) + execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${_tmp_target}) +endmacro(gretl_configure_file) + + +##------------------------------------------------------------------------------ +## gretl_remove_string_prefix +## +## This macro fills OUTPUT_VAR with the subdirectory relative to +## "/src" +## +## OUTPUT_VAR - Possibly altered output string +## +##------------------------------------------------------------------------------ +macro(gretl_get_src_subdirectory) + + set(options) + set(singleValueArgs OUTPUT_VAR) + set(multiValueArgs) + + # Parse the arguments to the macro + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT DEFINED arg_OUTPUT_VAR) + message(FATAL_ERROR "OUTPUT_VAR is required") + endif() + + string(TOLOWER ${PROJECT_NAME} _project_name) + + # Convert both paths to absolute + file(REAL_PATH "${PROJECT_SOURCE_DIR}/src/${_project_name}" abs_base_dir) + file(REAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}" abs_full_path) + + # Check if full path starts with the base directory + string(FIND "${abs_full_path}" "${abs_base_dir}" found_pos) + + if(NOT found_pos EQUAL 0) + message(FATAL_ERROR "The full path '${abs_full_path}' does not start with the base directory '${abs_base_dir}'") + endif() + + # Strip base directory from full path + gretl_remove_string_prefix(PREFIX "${abs_base_dir}/" + INPUT "${abs_full_path}" + OUTPUT_VAR ${arg_OUTPUT_VAR}) +endmacro(gretl_get_src_subdirectory) + + +##------------------------------------------------------------------------------ +## gretl_write_unified_header +## +## This macro writes the unified header (.hpp) +## to the build directory for the given NAME with the given HEADERS included +## inside of it. +## +## NAME - The name of the unified header. +## HEADERS - Headers to be included in the header. +## NO_PATH_MODIFICATION - ON/OFF(default) Stops include path modification if on, +## used for the project-level unified header +## +##------------------------------------------------------------------------------ +# List to hold all unified headers to be later used to create a master unified header +set(_${PROJECT_NAME}_unified_headers "" CACHE STRING "" FORCE) +macro(gretl_write_unified_header) + + set(options) + set(singleValueArgs NAME NO_PATH_MODIFICATION) + set(multiValueArgs HEADERS EXCLUDE) + + # Parse the arguments to the macro + cmake_parse_arguments(arg + "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT DEFINED arg_NO_PATH_MODIFICATION) + set(arg_NO_PATH_MODIFICATION OFF) + endif() + + string(TOLOWER ${arg_NAME} _unified_header_name) + string(TOLOWER ${PROJECT_NAME} _project_name) + set(_header ${PROJECT_BINARY_DIR}/include/${_project_name}/${_unified_header_name}.hpp) + set(_tmp_header ${_header}.tmp) + set(_src_subdir) + if(NOT arg_NO_PATH_MODIFICATION) + gretl_get_src_subdirectory(OUTPUT_VAR _src_subdir) + endif() + + file(WRITE ${_tmp_header} "\/\/ Copyright Lawrence Livermore National Security, LLC and +\/\/ other ${PROJECT_NAME} Project Developers. See the top-level LICENSE file for details. +\/\/ +\/\/ SPDX-License-Identifier: (BSD-3-Clause) +\n +") + + file(APPEND ${_tmp_header} "#pragma once\n\n") + + file(APPEND ${_tmp_header} "#include \"${_project_name}\/${_project_name}_config.hpp\"\n\n") + + foreach(_file ${arg_HEADERS}) + if("${_file}" IN_LIST arg_EXCLUDE) + continue() + elseif("${_file}" MATCHES "\\.inl$") + continue() + elseif("${_file}" MATCHES "(\/detail\/)|(\/internal\/)") + continue() + elseif(arg_NO_PATH_MODIFICATION) + file(APPEND ${_tmp_header} "#include \"${_file}\"\n") + else() + set(_headerPath) + gretl_remove_string_prefix(PREFIX "${PROJECT_BINARY_DIR}\/" + INPUT "${_file}" + OUTPUT_VAR _headerPath) + gretl_remove_string_prefix(PREFIX "include\/${_project_name}\/${arg_NAME}\/" + INPUT "${_headerPath}" + OUTPUT_VAR _headerPath) + set(_headerPath "${_project_name}\/${_src_subdir}\/${_headerPath}") + file(APPEND ${_tmp_header} "#include \"${_headerPath}\"\n") + endif() + endforeach() + + file(APPEND ${_tmp_header} "\n") + + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_tmp_header} ${_header}) + execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${_tmp_header}) + + install(FILES ${_header} + DESTINATION include/${_project_name}) + + # Add this component's unified header to the list to be added to the project specific unified header + set(_component_header "${_project_name}/${_unified_header_name}.hpp") + if("${_${PROJECT_NAME}_unified_headers}" STREQUAL "") + set(_${PROJECT_NAME}_unified_headers "${_component_header}" CACHE STRING "" FORCE) + else() + set(_${PROJECT_NAME}_unified_headers "${_${PROJECT_NAME}_unified_headers};${_component_header}" CACHE STRING "" FORCE) + endif() +endmacro(gretl_write_unified_header) diff --git a/cmake/blt b/cmake/blt new file mode 160000 index 0000000..532d150 --- /dev/null +++ b/cmake/blt @@ -0,0 +1 @@ +Subproject commit 532d15088b37d59b399299b0c7b706368470b805 diff --git a/cmake/gretl-config.cmake.in b/cmake/gretl-config.cmake.in new file mode 100644 index 0000000..0ae271b --- /dev/null +++ b/cmake/gretl-config.cmake.in @@ -0,0 +1,37 @@ +# Copyright (c) Lawrence Livermore National Security, LLC and +# other Gretl Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (BSD-3-Clause) +#------------------------------------------------------------------------------ + +cmake_minimum_required(VERSION 3.16 FATAL_ERROR) + +@PACKAGE_INIT@ + +if(NOT GRETL_FOUND) + + #---------------------------------------------------------------------------- + # Set version and paths + #---------------------------------------------------------------------------- + + set(GRETL_VERSION "@GRETL_VERSION_FULL@") + set(GRETL_VERSION_MAJOR "@GRETL_VERSION_MAJOR@") + set(GRETL_VERSION_MINOR "@GRETL_VERSION_MINOR@") + set(GRETL_VERSION_PATCH "@GRETL_VERSION_PATCH@") + + set(GRETL_INSTALL_PREFIX "@GRETL_INSTALL_PREFIX@") + set(GRETL_INCLUDE_DIRS "${GRETL_INSTALL_PREFIX}/include") + + #---------------------------------------------------------------------------- + # Load BLT and Gretl targets + #---------------------------------------------------------------------------- + get_filename_component(GRETL_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + include(${GRETL_CMAKE_CONFIG_DIR}/BLTSetupTargets.cmake) + include(${GRETL_CMAKE_CONFIG_DIR}/gretl-targets.cmake) + + #---------------------------------------------------------------------------- + # Indicate that Gretl is correctly set up + #---------------------------------------------------------------------------- + set(GRETL_FOUND TRUE) + +endif() diff --git a/config-build.py b/config-build.py new file mode 100755 index 0000000..79f9f23 --- /dev/null +++ b/config-build.py @@ -0,0 +1,311 @@ +#!/bin/sh + +# 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) + +"exec" "python3" "-u" "-B" "$0" "$@" + +# Python wrapper script for generating the correct cmake line with the options specified by the user. +# +# Please keep parser option names as close to possible as the names of the cmake options they are wrapping. + +import sys +import os +import subprocess +import argparse +import platform +import shutil +import socket + +_host_configs_map = {"rzgenie" : "rzwhippet-toss_4_x86_64_ib-llvm@19.1.3.cmake", + "rzwhippet" : "rzwhippet-toss_4_x86_64_ib-llvm@19.1.3.cmake", + "dane" : "dane-toss_4_x86_64_ib-llvm@19.1.3.cmake"} + +def get_machine_name(): + return socket.gethostname().rstrip('1234567890') + +def get_default_host_config(): + machine_name = get_machine_name() + + if machine_name in _host_configs_map.keys(): + return _host_configs_map[machine_name] + else: + return "" + +def extract_cmake_location(file_path): + # print "Extracting cmake entry from host config file ", file_path + if os.path.exists(file_path): + cmake_line_prefix = "# cmake executable path: " + file_handle = open(file_path, "r") + content = file_handle.readlines() + for line in content: + if line.lower().startswith(cmake_line_prefix): + return line.split(" ")[4].strip() + print("Could not find a cmake entry in host config file.") + return None + + +def parse_arguments(): + parser = argparse.ArgumentParser(description="Configure cmake build.", + epilog="Note: Additional or unrecognized parameters will be passed directly to cmake." + " For example, append '-DENABLE_OPENMP=ON' to enable OpenMP." + ) + + parser.add_argument("-bp", + "--buildpath", + type=str, + default="", + help="specify path for build directory. If not specified, will create in current directory.") + + parser.add_argument("-ip", + "--installpath", + type=str, + default="", + help="specify path for install directory. If not specified, will create in current directory.") + + parser.add_argument("-bt", + "--buildtype", + type=str, + choices=["Release", "Debug", "RelWithDebInfo", "MinSizeRel"], + help="build type. defaults to Release") + + parser.add_argument("-e", + "--eclipse", + action='store_true', + help="create an eclipse project file.") + + parser.add_argument("-ecc", + "--exportcompilercommands", + action='store_true', + help="generate a compilation database. Can be used by the clang tools such as clang-modernize. Will create a 'compile_commands.json' file in build directory.") + + parser.add_argument("-hc", + "--hostconfig", + default="", + type=str, + help="select a specific host-config file to initalize CMake's cache") + + parser.add_argument("--print-default-host-config", + action='store_true', + help="print the default host config for this system and exit") + + parser.add_argument("--print-machine-name", + action='store_true', + help="print the machine name for this system and exit") + + parser.add_argument("-n", + "--ninja", + action='store_true', + help="use ninja generator to build instead of make") + + args, unknown_args = parser.parse_known_args() + if unknown_args: + print("[config-build]: Passing the following arguments directly to cmake... %s" % unknown_args) + + return args, unknown_args + + +######################## +# Find CMake Cache File +######################## +def find_host_config(args, repodir): + if args.hostconfig != "": + hostconfigpath = os.path.abspath(args.hostconfig) + else: + hostconfigpath = get_default_host_config() + if hostconfigpath == "": + print("[config-build]: Error could not find default host-config for this platform.") + print(" Either set one in this script or use the command line argument '-hc'.") + else: + hostconfigpath = os.path.join(repodir, "host-configs", hostconfigpath) + assert os.path.exists( hostconfigpath ), "Could not find CMake host config file '%s'." % hostconfigpath + print("Using host config file: '%s'." % hostconfigpath) + return hostconfigpath + + +######################## +# Get Platform information from host config name +######################## +def get_platform_info(hostconfigpath): + platform_info = "" + platform_info = os.path.split(hostconfigpath)[1] + if platform_info.endswith(".cmake"): + platform_info = platform_info[:-6] + return platform_info + + +##################### +# Setup Build Dir +##################### +def setup_build_dir(args, platform_info): + if args.buildpath != "": + # use explicit build path + buildpath = args.buildpath + else: + # use platform info & build type + buildpath = "-".join(["build", platform_info, args.buildtype.lower()]) + + buildpath = os.path.abspath(buildpath) + + if os.path.exists(buildpath): + print("Build directory '%s' already exists. Deleting..." % buildpath) + shutil.rmtree(buildpath) + + print("Creating build directory '%s'..." % buildpath) + os.makedirs(buildpath) + return buildpath + + +##################### +# Setup Install Dir +##################### +def setup_install_dir(args, platform_info): + # For install directory, we will clean up old ones, but we don't need to create it, cmake will do that. + if args.installpath != "": + installpath = os.path.abspath(args.installpath) + else: + # use platform info & build type + installpath = "-".join( + ["install", platform_info, args.buildtype.lower()] + ) + + installpath = os.path.abspath(installpath) + + if os.path.exists(installpath): + print( + "Install directory '%s' already exists, deleting..." % installpath + ) + shutil.rmtree(installpath) + + print("Creating install path '%s'..." % installpath) + os.makedirs(installpath) + return installpath + + +############################ +# Check if executable exists +############################ +def executable_exists(path): + if path == "cmake": + return True + return os.path.isfile(path) and os.access(path, os.X_OK) + + +############################ +# Build CMake command line +############################ +def create_cmake_command_line(args, unknown_args, buildpath, installpath, hostconfigpath): + + import stat + + cmakeline = extract_cmake_location(hostconfigpath) + assert cmakeline, "Host config file doesn't contain valid cmake location, value was %s" % cmakeline + assert executable_exists( cmakeline ), "['%s'] invalid path to cmake executable or file does not have execute permissions" % cmakeline + + # create the ccmake command for convenience + cmakedir = os.path.dirname(cmakeline) + ccmake_cmd = cmakedir + "/ccmake" + if executable_exists( ccmake_cmd ): + # write the ccmake command to a file to use for convenience + with open( "%s/ccmake_cmd" % buildpath, "w" ) as ccmakefile: + ccmakefile.write("#!/usr/bin/env bash\n") + ccmakefile.write(ccmake_cmd) + ccmakefile.write(" $@") + ccmakefile.write("\n") + + st = os.stat("%s/ccmake_cmd" % buildpath) + os.chmod("%s/ccmake_cmd" % buildpath, st.st_mode | stat.S_IEXEC) + + # Add cache file option + cmakeline += " -C %s" % hostconfigpath + + # Add build type (opt or debug) + cmakeline += " -DCMAKE_BUILD_TYPE=" + args.buildtype + + # Set install dir + cmakeline += " -DCMAKE_INSTALL_PREFIX=%s" % installpath + + if args.exportcompilercommands: + cmakeline += " -DCMAKE_EXPORT_COMPILE_COMMANDS=on" + + if args.eclipse: + cmakeline += ' -G "Eclipse CDT4 - Unix Makefiles"' + + if args.ninja: + cmakeline += ' -G Ninja' + + if unknown_args: + cmakeline += " " + " ".join( unknown_args ) + + rootdir = os.path.dirname( os.path.abspath(sys.argv[0]) ) + cmakeline += " %s " % rootdir + + # Dump the cmake command to file for convenience + with open("%s/cmake_cmd" % buildpath, "w") as cmdfile: + cmdfile.write(cmakeline) + cmdfile.write("\n") + + st = os.stat("%s/cmake_cmd" % buildpath) + os.chmod("%s/cmake_cmd" % buildpath, st.st_mode | stat.S_IEXEC) + return cmakeline + + +############################ +# Run CMake +############################ +def run_cmake(buildpath, cmakeline): + print("Changing to build directory...") + os.chdir(buildpath) + print("Executing CMake line: '%s'" % cmakeline) + print() + returncode = subprocess.call(cmakeline, shell=True) + if not returncode == 0: + print("Error: CMake command failed with return code: {0}".format(returncode)) + return False + return True + + +############################ +# Main +############################ +def main(): + repodir = os.path.abspath(os.path.dirname(__file__)) + assert os.path.abspath(os.getcwd())==repodir, "config-build must be run from %s" % repodir + + args, unknown_args = parse_arguments() + + if args.print_machine_name: + machine_name = get_machine_name() + print(machine_name) + return True + + if args.print_default_host_config: + default_hc = get_default_host_config() + if default_hc != "": + print(os.path.splitext(default_hc)[0]) + return True + else: + return False + + if args.buildtype == None: + # Set default CMake build type + args.buildtype = "Release" + # If CMAKE_BUILD_TYPE was passed in as an argument, use that option instead + for unknown_arg in unknown_args: + if "-DCMAKE_BUILD_TYPE" in unknown_arg: + args.buildtype = unknown_arg.split("=")[1] + break + + basehostconfigpath = find_host_config(args, repodir) + platform_info = get_platform_info(basehostconfigpath) + buildpath = setup_build_dir(args, platform_info) + installpath = setup_install_dir(args, platform_info) + + cmakeline = create_cmake_command_line(args, unknown_args, buildpath, installpath, basehostconfigpath) + return run_cmake(buildpath, cmakeline) + +if __name__ == '__main__': + exit(0 if main() else 1) diff --git a/host-configs/dane-toss_4_x86_64_ib-gcc@13.3.1.cmake b/host-configs/dane-toss_4_x86_64_ib-gcc@13.3.1.cmake new file mode 100644 index 0000000..b45f50d --- /dev/null +++ b/host-configs/dane-toss_4_x86_64_ib-gcc@13.3.1.cmake @@ -0,0 +1,53 @@ +#------------------------------------------------------------------------------ +# !!!! This is a generated file, edit at own risk !!!! +#------------------------------------------------------------------------------ +# CMake executable path: /usr/tce/bin/cmake +#------------------------------------------------------------------------------ + +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") + +#------------------------------------------------------------------------------ +# Compilers +#------------------------------------------------------------------------------ +# Compiler Spec: gcc@13.3.1/hpiynx6mdjb57v77us3h6yyzxymdbr6d +#------------------------------------------------------------------------------ +if(DEFINED ENV{SPACK_CC}) + + set(CMAKE_C_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_10_47/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/gcc/gcc" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_10_47/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/gcc/g++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_10_47/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/gcc/gfortran" CACHE PATH "") + +else() + + set(CMAKE_C_COMPILER "/usr/tce/packages/gcc/gcc-13.3.1/bin/gcc" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/tce/packages/gcc/gcc-13.3.1/bin/g++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/tce/packages/gcc/gcc-13.3.1/bin/gfortran" CACHE PATH "") + +endif() + +set(CMAKE_Fortran_FLAGS "-fPIC" CACHE STRING "") + + +#------------------------------------------------------------------------------ +# Devtools +#------------------------------------------------------------------------------ + +set(DEVTOOLS_ROOT "/usr/WS2/smithdev/devtools/toss_4_x86_64_ib/2024_05_30_15_02_20/._view/psk2dcrijss6s4i6qmxplzthrzm3y7nh" CACHE PATH "") + +set(CLANGFORMAT_EXECUTABLE "/usr/tce/packages/clang/clang-19.1.3/bin/clang-format" CACHE PATH "") + +set(CLANGTIDY_EXECUTABLE "/usr/tce/packages/clang/clang-19.1.3/bin/clang-tidy" CACHE PATH "") + +set(ENABLE_DOCS ON CACHE BOOL "") + +set(SPHINX_EXECUTABLE "${DEVTOOLS_ROOT}/python-3.11.7/bin/sphinx-build" CACHE PATH "") + +set(CPPCHECK_EXECUTABLE "${DEVTOOLS_ROOT}/cppcheck-2.9/bin/cppcheck" CACHE PATH "") + +set(DOXYGEN_EXECUTABLE "${DEVTOOLS_ROOT}/doxygen-1.9.8/bin/doxygen" CACHE PATH "") + + diff --git a/host-configs/dane-toss_4_x86_64_ib-llvm@19.1.3.cmake b/host-configs/dane-toss_4_x86_64_ib-llvm@19.1.3.cmake new file mode 100644 index 0000000..0022e66 --- /dev/null +++ b/host-configs/dane-toss_4_x86_64_ib-llvm@19.1.3.cmake @@ -0,0 +1,53 @@ +#------------------------------------------------------------------------------ +# !!!! This is a generated file, edit at own risk !!!! +#------------------------------------------------------------------------------ +# CMake executable path: /usr/tce/bin/cmake +#------------------------------------------------------------------------------ + +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") + +#------------------------------------------------------------------------------ +# Compilers +#------------------------------------------------------------------------------ +# Compiler Spec: llvm@19.1.3/bmskmshy3mzlmo37b2pxkt76vqcffxvp +#------------------------------------------------------------------------------ +if(DEFINED ENV{SPACK_CC}) + + set(CMAKE_C_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_10_47/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/clang/clang" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_10_47/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/clang/clang++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_10_47/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/gcc/gfortran" CACHE PATH "") + +else() + + set(CMAKE_C_COMPILER "/usr/tce/packages/clang/clang-19.1.3-magic/bin/clang" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/tce/packages/clang/clang-19.1.3-magic/bin/clang++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/tce/packages/gcc/gcc-13.3.1/bin/gfortran" CACHE PATH "") + +endif() + +set(CMAKE_Fortran_FLAGS "-fPIC" CACHE STRING "") + + +#------------------------------------------------------------------------------ +# Devtools +#------------------------------------------------------------------------------ + +set(DEVTOOLS_ROOT "/usr/WS2/smithdev/devtools/toss_4_x86_64_ib/2024_05_30_15_02_20/._view/psk2dcrijss6s4i6qmxplzthrzm3y7nh" CACHE PATH "") + +set(CLANGFORMAT_EXECUTABLE "/usr/tce/packages/clang/clang-19.1.3/bin/clang-format" CACHE PATH "") + +set(CLANGTIDY_EXECUTABLE "/usr/tce/packages/clang/clang-19.1.3/bin/clang-tidy" CACHE PATH "") + +set(ENABLE_DOCS ON CACHE BOOL "") + +set(SPHINX_EXECUTABLE "${DEVTOOLS_ROOT}/python-3.11.7/bin/sphinx-build" CACHE PATH "") + +set(CPPCHECK_EXECUTABLE "${DEVTOOLS_ROOT}/cppcheck-2.9/bin/cppcheck" CACHE PATH "") + +set(DOXYGEN_EXECUTABLE "${DEVTOOLS_ROOT}/doxygen-1.9.8/bin/doxygen" CACHE PATH "") + + diff --git a/host-configs/docker/gcc@14.2.0.cmake b/host-configs/docker/gcc@14.2.0.cmake new file mode 100644 index 0000000..204c04f --- /dev/null +++ b/host-configs/docker/gcc@14.2.0.cmake @@ -0,0 +1,53 @@ +#------------------------------------------------------------------------------ +# !!!! This is a generated file, edit at own risk !!!! +#------------------------------------------------------------------------------ +# CMake executable path: /usr/local/bin/cmake +#------------------------------------------------------------------------------ + +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") + +#------------------------------------------------------------------------------ +# Compilers +#------------------------------------------------------------------------------ +# Compiler Spec: gcc@14.2.0/na7vd37xl45hztvg4h4fojpnqlfxgd2r +#------------------------------------------------------------------------------ +if(DEFINED ENV{SPACK_CC}) + + set(CMAKE_C_COMPILER "/home/serac/serac_tpls/none-none/compiler-wrapper-1.0-adr4m722sut3yibwgl2ehvjbtuzeozzm/libexec/spack/gcc/gcc" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/home/serac/serac_tpls/none-none/compiler-wrapper-1.0-adr4m722sut3yibwgl2ehvjbtuzeozzm/libexec/spack/gcc/g++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/home/serac/serac_tpls/none-none/compiler-wrapper-1.0-adr4m722sut3yibwgl2ehvjbtuzeozzm/libexec/spack/gcc/gfortran" CACHE PATH "") + +else() + + set(CMAKE_C_COMPILER "/usr/bin/gcc-14" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/bin/g++-14" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/bin/gfortran-14" CACHE PATH "") + +endif() + +set(CMAKE_C_FLAGS "-fPIC -pthread" CACHE STRING "") + +set(CMAKE_CXX_FLAGS "-fPIC -pthread" CACHE STRING "") + +set(CMAKE_Fortran_FLAGS "-fPIC -pthread" CACHE STRING "") + + +#------------------------------------------------------------------------------ +# Devtools +#------------------------------------------------------------------------------ + +# Code checks disabled due to disabled devtools + +set(SMITH_ENABLE_CODE_CHECKS OFF CACHE BOOL "") + +set(ENABLE_CLANGFORMAT OFF CACHE BOOL "") + +set(ENABLE_CLANGTIDY OFF CACHE BOOL "") + +set(ENABLE_DOCS OFF CACHE BOOL "") + + diff --git a/host-configs/docker/llvm@19.1.1.cmake b/host-configs/docker/llvm@19.1.1.cmake new file mode 100644 index 0000000..02aa3f5 --- /dev/null +++ b/host-configs/docker/llvm@19.1.1.cmake @@ -0,0 +1,57 @@ +#------------------------------------------------------------------------------ +# !!!! This is a generated file, edit at own risk !!!! +#------------------------------------------------------------------------------ +# CMake executable path: /usr/local/bin/cmake +#------------------------------------------------------------------------------ + +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") + +#------------------------------------------------------------------------------ +# Compilers +#------------------------------------------------------------------------------ +# Compiler Spec: llvm@19.1.1/yq5rjyb4vplepvexmd5okbdyoezvrvsz +#------------------------------------------------------------------------------ +if(DEFINED ENV{SPACK_CC}) + + set(CMAKE_C_COMPILER "/home/serac/serac_tpls/none-none/compiler-wrapper-1.0-adr4m722sut3yibwgl2ehvjbtuzeozzm/libexec/spack/clang/clang" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/home/serac/serac_tpls/none-none/compiler-wrapper-1.0-adr4m722sut3yibwgl2ehvjbtuzeozzm/libexec/spack/clang/clang++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/home/serac/serac_tpls/none-none/compiler-wrapper-1.0-adr4m722sut3yibwgl2ehvjbtuzeozzm/libexec/spack/gcc/gfortran" CACHE PATH "") + +else() + + set(CMAKE_C_COMPILER "/usr/lib/llvm-19/bin/clang" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/lib/llvm-19/bin/clang++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/bin/gfortran-13" CACHE PATH "") + +endif() + +set(CMAKE_C_FLAGS "-fPIC -pthread" CACHE STRING "") + +set(CMAKE_CXX_FLAGS "-fPIC -pthread" CACHE STRING "") + +set(CMAKE_Fortran_FLAGS "-fPIC -pthread" CACHE STRING "") + + +#------------------------------------------------------------------------------ +# Devtools +#------------------------------------------------------------------------------ + +set(DEVTOOLS_ROOT "/usr" CACHE PATH "") + +set(CLANGFORMAT_EXECUTABLE "${DEVTOOLS_ROOT}/lib/llvm-19/bin/clang-format" CACHE PATH "") + +set(CLANGTIDY_EXECUTABLE "${DEVTOOLS_ROOT}/lib/llvm-19/bin/clang-tidy" CACHE PATH "") + +set(ENABLE_DOCS ON CACHE BOOL "") + +set(SPHINX_EXECUTABLE "${DEVTOOLS_ROOT}/bin/sphinx-build" CACHE PATH "") + +set(CPPCHECK_EXECUTABLE "${DEVTOOLS_ROOT}/bin/cppcheck" CACHE PATH "") + +set(DOXYGEN_EXECUTABLE "${DEVTOOLS_ROOT}/local/bin/doxygen" CACHE PATH "") + + diff --git a/host-configs/rzwhippet-toss_4_x86_64_ib-gcc@13.3.1.cmake b/host-configs/rzwhippet-toss_4_x86_64_ib-gcc@13.3.1.cmake new file mode 100644 index 0000000..49c5168 --- /dev/null +++ b/host-configs/rzwhippet-toss_4_x86_64_ib-gcc@13.3.1.cmake @@ -0,0 +1,53 @@ +#------------------------------------------------------------------------------ +# !!!! This is a generated file, edit at own risk !!!! +#------------------------------------------------------------------------------ +# CMake executable path: /usr/tce/bin/cmake +#------------------------------------------------------------------------------ + +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") + +#------------------------------------------------------------------------------ +# Compilers +#------------------------------------------------------------------------------ +# Compiler Spec: gcc@13.3.1/hpiynx6mdjb57v77us3h6yyzxymdbr6d +#------------------------------------------------------------------------------ +if(DEFINED ENV{SPACK_CC}) + + set(CMAKE_C_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_50_56/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/gcc/gcc" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_50_56/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/gcc/g++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_50_56/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/gcc/gfortran" CACHE PATH "") + +else() + + set(CMAKE_C_COMPILER "/usr/tce/packages/gcc/gcc-13.3.1/bin/gcc" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/tce/packages/gcc/gcc-13.3.1/bin/g++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/tce/packages/gcc/gcc-13.3.1/bin/gfortran" CACHE PATH "") + +endif() + +set(CMAKE_Fortran_FLAGS "-fPIC" CACHE STRING "") + + +#------------------------------------------------------------------------------ +# Devtools +#------------------------------------------------------------------------------ + +set(DEVTOOLS_ROOT "/usr/WS2/smithdev/devtools/toss_4_x86_64_ib/2024_05_30_15_09_55/._view/rkqkran3ydsuprr2wip5pdnz5wh7xwnr" CACHE PATH "") + +set(CLANGFORMAT_EXECUTABLE "/usr/tce/packages/clang/clang-19.1.3/bin/clang-format" CACHE PATH "") + +set(CLANGTIDY_EXECUTABLE "/usr/tce/packages/clang/clang-19.1.3/bin/clang-tidy" CACHE PATH "") + +set(ENABLE_DOCS ON CACHE BOOL "") + +set(SPHINX_EXECUTABLE "${DEVTOOLS_ROOT}/python-3.11.7/bin/sphinx-build" CACHE PATH "") + +set(CPPCHECK_EXECUTABLE "${DEVTOOLS_ROOT}/cppcheck-2.9/bin/cppcheck" CACHE PATH "") + +set(DOXYGEN_EXECUTABLE "${DEVTOOLS_ROOT}/doxygen-1.9.8/bin/doxygen" CACHE PATH "") + + diff --git a/host-configs/rzwhippet-toss_4_x86_64_ib-llvm@19.1.3.cmake b/host-configs/rzwhippet-toss_4_x86_64_ib-llvm@19.1.3.cmake new file mode 100644 index 0000000..b123b61 --- /dev/null +++ b/host-configs/rzwhippet-toss_4_x86_64_ib-llvm@19.1.3.cmake @@ -0,0 +1,53 @@ +#------------------------------------------------------------------------------ +# !!!! This is a generated file, edit at own risk !!!! +#------------------------------------------------------------------------------ +# CMake executable path: /usr/tce/bin/cmake +#------------------------------------------------------------------------------ + +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") + +#------------------------------------------------------------------------------ +# Compilers +#------------------------------------------------------------------------------ +# Compiler Spec: llvm@19.1.3/bmskmshy3mzlmo37b2pxkt76vqcffxvp +#------------------------------------------------------------------------------ +if(DEFINED ENV{SPACK_CC}) + + set(CMAKE_C_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_50_56/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/clang/clang" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_50_56/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/clang/clang++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/WS2/smithdev/libs/smith/toss_4_x86_64_ib/2025_09_25_10_50_56/none-none/compiler-wrapper-1.0-hxzxhboumtniaqs7qivgliluv4h2lbxt/libexec/spack/gcc/gfortran" CACHE PATH "") + +else() + + set(CMAKE_C_COMPILER "/usr/tce/packages/clang/clang-19.1.3-magic/bin/clang" CACHE PATH "") + + set(CMAKE_CXX_COMPILER "/usr/tce/packages/clang/clang-19.1.3-magic/bin/clang++" CACHE PATH "") + + set(CMAKE_Fortran_COMPILER "/usr/tce/packages/gcc/gcc-13.3.1/bin/gfortran" CACHE PATH "") + +endif() + +set(CMAKE_Fortran_FLAGS "-fPIC" CACHE STRING "") + + +#------------------------------------------------------------------------------ +# Devtools +#------------------------------------------------------------------------------ + +set(DEVTOOLS_ROOT "/usr/WS2/smithdev/devtools/toss_4_x86_64_ib/2024_05_30_15_09_55/._view/rkqkran3ydsuprr2wip5pdnz5wh7xwnr" CACHE PATH "") + +set(CLANGFORMAT_EXECUTABLE "/usr/tce/packages/clang/clang-19.1.3/bin/clang-format" CACHE PATH "") + +set(CLANGTIDY_EXECUTABLE "/usr/tce/packages/clang/clang-19.1.3/bin/clang-tidy" CACHE PATH "") + +set(ENABLE_DOCS ON CACHE BOOL "") + +set(SPHINX_EXECUTABLE "${DEVTOOLS_ROOT}/python-3.11.7/bin/sphinx-build" CACHE PATH "") + +set(CPPCHECK_EXECUTABLE "${DEVTOOLS_ROOT}/cppcheck-2.9/bin/cppcheck" CACHE PATH "") + +set(DOXYGEN_EXECUTABLE "${DEVTOOLS_ROOT}/doxygen-1.9.8/bin/doxygen" CACHE PATH "") + + diff --git a/scripts/check_for_missing_headers.py b/scripts/check_for_missing_headers.py new file mode 100755 index 0000000..ed1f29b --- /dev/null +++ b/scripts/check_for_missing_headers.py @@ -0,0 +1,97 @@ +#!/bin/sh +"exec" "python3" "-u" "-B" "$0" "$@" +############################################################################## +# Copyright (c) Lawrence Livermore National Security, LLC and +# other Gretl Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (BSD-3-Clause) +############################################################################## + +""" + file: check_for_missing_headers.py + + description: + This script takes a Gretl install and source directory and checks to see + if install includes the same header files. + +""" + +import os +import sys +import argparse + +def parse_arguments(): + parser = argparse.ArgumentParser() + parser.add_argument("-i", + "--install-dir", + default="", + dest="install_dir", + help="specify path of the install directory.") + parser.add_argument("-s", + "--src-dir", + default="", + dest="src_dir", + help="specify path of the src directory.") + return parser.parse_known_args() + +# return list of relative paths to header files +def get_headers_from(dir): + headers = [] + for (dirpath, dirnames, filenames) in os.walk(dir, topdown=True): + # skip tests directories + if "tests" in dirnames: + dirnames.remove("tests") + for f in filenames: + if ".hpp" in f and ".in" not in f: + relative_header_path = dirpath.replace(dir + "/", "") + headers.append({"path": relative_header_path, "headerfile": f}) + return headers + +def main(): + args, unknown_args = parse_arguments() + + # ensure args are valid + install_dir = args.install_dir + if not os.path.isdir(install_dir): + print("Error: install_dir is not a directory or does not exist: {}".format(install_dir)) + return 1 + install_dir = os.path.abspath(install_dir) + + src_dir = args.src_dir + if not os.path.isdir(src_dir): + print("Error: src_dir is not a directory or does not exist: {}".format(src_dir)) + return 1 + src_dir = os.path.abspath(src_dir) + + print("============================================================") + print("check_for_missing_headers.py args") + print("install_dir: {0}".format(install_dir)) + print("src_dir: {0}".format(src_dir)) + print("============================================================") + + # grab headers from install and src + install_headers = get_headers_from(os.path.join(install_dir, "include")) + src_headers = get_headers_from(os.path.join(src_dir)) + + # check if each header in src is in install as well + res = 0 + for sh in src_headers: + found = False + for ih in install_headers: + src_relative_header = "{0}/{1}".format(sh["path"], sh["headerfile"]) + install_relative_header = "{0}/{1}".format(ih["path"], ih["headerfile"]) + if src_relative_header == install_relative_header: + found = True + break + if not found: + cmakelists_path = os.path.join(src_dir, sh["path"], "CMakeLists.txt") + print("Header '{0}' is missing; it should probably be listed in {1}".format(sh["headerfile"], cmakelists_path)) + res = 1 + + if res == 0: + print("No missing headers found.") + + return res + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/github-actions/linux-build_and_test.sh b/scripts/github-actions/linux-build_and_test.sh new file mode 100755 index 0000000..187d55c --- /dev/null +++ b/scripts/github-actions/linux-build_and_test.sh @@ -0,0 +1,43 @@ +#!/bin/bash +############################################################################## +# 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) +############################################################################## + +set -x + +function or_die () { + "$@" + local status=$? + if [[ $status != 0 ]] ; then + echo ERROR $status command: $@ + exit $status + fi +} + +echo "~~~~ helpful info ~~~~" +echo "USER="`id -u -n` +echo "PWD="`pwd` +echo "HOST_CONFIG=$HOST_CONFIG" +echo "CMAKE_EXTRA_FLAGS=$CMAKE_EXTRA_FLAGS" +echo "~~~~~~~~~~~~~~~~~~~~~~" + +export BUILD_TYPE=${BUILD_TYPE:-Debug} + + +echo "~~~~~~ FIND NUMPROCS ~~~~~~~~" +NUMPROCS=`python3 -c "import os; print(f'{os.cpu_count()}')"` +NUM_BUILD_PROCS=`python3 -c "import os; print(f'{max(2, os.cpu_count() * 8 // 10)}')"` + +echo "~~~~~~ RUNNING CMAKE ~~~~~~~~" +or_die python3 ./config-build.py -bp builddir -hc ./host-configs/docker/${HOST_CONFIG} -bt ${BUILD_TYPE} ${CMAKE_EXTRA_FLAGS} +or_die cd builddir + +echo "~~~~~~ BUILDING ~~~~~~~~" +or_die make -j $NUM_BUILD_PROCS VERBOSE=1 + +echo "~~~~~~ RUNNING TESTS ~~~~~~~~" +make CTEST_OUTPUT_ON_FAILURE=1 test ARGS='-T Test -VV -j$NUM_BUILD_PROCS' + diff --git a/scripts/github-actions/linux-check.sh b/scripts/github-actions/linux-check.sh new file mode 100755 index 0000000..c67ea6c --- /dev/null +++ b/scripts/github-actions/linux-check.sh @@ -0,0 +1,52 @@ +#!/bin/bash +############################################################################## +# 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) +############################################################################## + +set -x + +function or_die () { + "$@" + local status=$? + if [[ $status != 0 ]] ; then + echo ERROR $status command: $@ + exit $status + fi +} + +echo "~~~~ helpful info ~~~~" +echo "USER="`id -u -n` +echo "PWD="`pwd` +echo "HOST_CONFIG=$HOST_CONFIG" +echo "CMAKE_EXTRA_FLAGS=$CMAKE_EXTRA_FLAGS" +echo "~~~~~~~~~~~~~~~~~~~~~~" + +echo "~~~~~~ RUNNING CMAKE ~~~~~~~~" +cmake_args="-DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=ON -DENABLE_CLANGTIDY=OFF -DGRETL_ENABLE_CODE_CHECKS=ON" + +if [[ "$CHECK_TYPE" == "style" ]] ; then + CLANGFORMAT_EXECUTABLE=/usr/bin/clang-format + if [[ ! -f "$CLANGFORMAT_EXECUTABLE" ]]; then + echo "clang-format not found: $CLANGFORMAT_EXECUTABLE" + exit 1 + fi + cmake_args="$cmake_args -DENABLE_CLANGFORMAT=ON -DCLANGFORMAT_EXECUTABLE=$CLANGFORMAT_EXECUTABLE" +fi + +or_die ./config-build.py -hc host-configs/docker/${HOST_CONFIG} -bp build-check-debug -ip install-check-debug $cmake_args +or_die cd build-check-debug + +if [[ "$CHECK_TYPE" == "style" ]] ; then + or_die make VERBOSE=1 clangformat_check +fi + +if [[ "$CHECK_TYPE" == "header" ]] ; then + or_die make -j4 + or_die make install -j4 + or_die ../scripts/check_for_missing_headers.py -i ../install-check-debug -s ../src +fi + +exit 0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..61b5373 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,11 @@ +# 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) + +add_subdirectory(gretl) + +if(GRETL_ENABLE_TESTS) + add_subdirectory(tests) +endif() diff --git a/src/gretl/CMakeLists.txt b/src/gretl/CMakeLists.txt new file mode 100644 index 0000000..2214177 --- /dev/null +++ b/src/gretl/CMakeLists.txt @@ -0,0 +1,57 @@ +# 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) + +# This file contains metadata that often changes (ie. git sha). +# Hide these changes in the source file so we do not force +# a full rebuild. +gretl_configure_file( + git_sha.hpp.in + ${PROJECT_BINARY_DIR}/include/gretl/git_sha.hpp + ) + +set(gretl_sources + about.cpp + data_store.cpp + state_base.cpp + vector_state.cpp) + +set(gretl_headers + about.hpp + checkpoint.hpp + create_state.hpp + data_store.hpp + double_state.hpp + ${PROJECT_BINARY_DIR}/include/gretl/git_sha.hpp + print_utils.hpp + state_base.hpp + state.hpp + test_utils.hpp + upstream_state.hpp + vector_state.hpp) + +blt_add_library(NAME gretl + SOURCES ${gretl_sources} + HEADERS ${gretl_headers}) + +gretl_write_unified_header( + NAME gretl + HEADERS ${gretl_headers} + ) + +target_include_directories(gretl PUBLIC + $ + $ + $ + ) + +install(FILES ${gretl_headers} ${PROJECT_BINARY_DIR}/include/gretl/gretl.hpp + DESTINATION include/gretl ) + +install(TARGETS gretl + EXPORT gretl-targets + DESTINATION lib + ) + diff --git a/src/gretl/about.cpp b/src/gretl/about.cpp new file mode 100644 index 0000000..5d12356 --- /dev/null +++ b/src/gretl/about.cpp @@ -0,0 +1,60 @@ +// 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) + +#include "gretl/about.hpp" +#include "gretl/config.hpp" +#include "gretl/git_sha.hpp" + +#include + +namespace gretl { + +std::string about() +{ + std::string about = "\n"; + + // Version info + about += std::string("Gretl Version: ") + version() + "\n"; + about += "\n"; + + // General configuration +#ifdef GRETL_DEBUG + about += std::string("Debug Build: ON\n"); +#else + about += std::string("Debug Build: OFF\n"); +#endif + + about += std::string("\n"); + + return about; +} + +std::string gitSHA() { return GRETL_GIT_SHA; } + +std::string version(bool add_SHA) +{ + std::string version = GRETL_VERSION_FULL; + + std::string sha = gitSHA(); + if (add_SHA && !sha.empty()) { + version += "-" + sha; + } + + return version; +} + +std::string compiler() { return std::string(GRETL_COMPILER_NAME) + " version " + std::string(GRETL_COMPILER_VERSION); } + +std::string buildType() +{ +#ifdef GRETL_DEBUG + return "Debug"; +#else + return "Release"; +#endif +} + +} // namespace gretl diff --git a/src/gretl/about.hpp b/src/gretl/about.hpp new file mode 100644 index 0000000..46abd79 --- /dev/null +++ b/src/gretl/about.hpp @@ -0,0 +1,60 @@ +// 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) + +/** + * @file about.hpp + * + * @brief This file contains the interface used for retrieving information + * about how the driver is configured. + */ + +#pragma once + +#include +#include + +namespace gretl { + +/** + * @brief Returns a string about the configuration of Gretl + * + * @return string containing various configuration information about Gretl + */ +std::string about(); + +/** + * @brief Returns a string for the Git SHA when the driver was built + * + * Note: This will not update unless you reconfigure CMake after a commit. + * + * @return string value of the Git SHA if built in a Git repo, empty if not + */ +std::string gitSHA(); + +/** + * @brief Returns a string for the version of Gretl + * + * @param[in] add_SHA boolean for whether to add the Git SHA to the version if available + * + * @return string value of the version of Gretl + */ +std::string version(bool add_SHA = true); + +/** + * @brief Returns a string for the current compiler name and version + * + * @return string value of the current compiler name and version + */ +std::string compiler(); + +/** + * @brief Returns a string for the current CMake build type (e.g. Debug, Release) + * + * @return string value of the build type + */ +std::string buildType(); + +} // namespace gretl diff --git a/src/checkpoint.hpp b/src/gretl/checkpoint.hpp similarity index 100% rename from src/checkpoint.hpp rename to src/gretl/checkpoint.hpp diff --git a/src/gretl/config.hpp.in b/src/gretl/config.hpp.in new file mode 100644 index 0000000..8688c08 --- /dev/null +++ b/src/gretl/config.hpp.in @@ -0,0 +1,31 @@ +// 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) + +#pragma once + +// Gretl Version Information +// clang-format off +#define GRETL_VERSION_MAJOR @GRETL_VERSION_MAJOR@ +#define GRETL_VERSION_MINOR @GRETL_VERSION_MINOR@ +#define GRETL_VERSION_PATCH @GRETL_VERSION_PATCH@ +#define GRETL_VERSION_FULL "@GRETL_VERSION_FULL@" +// clang-format on +/*NOTE: Do not add GRETL_GIT_SHA here. This will force + * full rebuild on all local changes. It is added in gretl::version() + * and gretl::about(), as well as accessible from gretl::gitSha(). + */ + +// Gretl Locations +#define GRETL_REPO_DIR "@GRETL_REPO_DIR@" +#define GRETL_BINARY_DIR "@GRETL_BINARY_DIR@" + +// Compiler Information +#define GRETL_COMPILER_NAME "@CMAKE_CXX_COMPILER_ID@" +#define GRETL_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@" + +// General defines +#cmakedefine GRETL_DEBUG + diff --git a/src/create_state.hpp b/src/gretl/create_state.hpp similarity index 100% rename from src/create_state.hpp rename to src/gretl/create_state.hpp diff --git a/src/data_store.cpp b/src/gretl/data_store.cpp similarity index 100% rename from src/data_store.cpp rename to src/gretl/data_store.cpp diff --git a/src/data_store.hpp b/src/gretl/data_store.hpp similarity index 100% rename from src/data_store.hpp rename to src/gretl/data_store.hpp diff --git a/src/double_state.hpp b/src/gretl/double_state.hpp similarity index 100% rename from src/double_state.hpp rename to src/gretl/double_state.hpp diff --git a/src/gretl/git_sha.hpp.in b/src/gretl/git_sha.hpp.in new file mode 100644 index 0000000..7131b5d --- /dev/null +++ b/src/gretl/git_sha.hpp.in @@ -0,0 +1,17 @@ +// 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) + +#pragma once + +/*NOTE: Do not include this file in anywhere other than about.cpp. + * This variable changes often and will force a full rebuild on all dependent files + * any time you git commit and re-run cmake. It is added in gretl::version() + * and gretl::about(), as well as accessible from gretl::gitSha(). + */ + +// clang-format off +#define GRETL_GIT_SHA "@GRETL_GIT_SHA@" +// clang-format on diff --git a/src/print_utils.hpp b/src/gretl/print_utils.hpp similarity index 100% rename from src/print_utils.hpp rename to src/gretl/print_utils.hpp diff --git a/src/state.hpp b/src/gretl/state.hpp similarity index 100% rename from src/state.hpp rename to src/gretl/state.hpp diff --git a/src/state_base.cpp b/src/gretl/state_base.cpp similarity index 100% rename from src/state_base.cpp rename to src/gretl/state_base.cpp diff --git a/src/state_base.hpp b/src/gretl/state_base.hpp similarity index 100% rename from src/state_base.hpp rename to src/gretl/state_base.hpp diff --git a/src/test_utils.hpp b/src/gretl/test_utils.hpp similarity index 100% rename from src/test_utils.hpp rename to src/gretl/test_utils.hpp diff --git a/src/upstream_state.hpp b/src/gretl/upstream_state.hpp similarity index 100% rename from src/upstream_state.hpp rename to src/gretl/upstream_state.hpp diff --git a/src/vector_state.cpp b/src/gretl/vector_state.cpp similarity index 100% rename from src/vector_state.cpp rename to src/gretl/vector_state.cpp diff --git a/src/vector_state.hpp b/src/gretl/vector_state.hpp similarity index 100% rename from src/vector_state.hpp rename to src/gretl/vector_state.hpp diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt new file mode 100644 index 0000000..92725bb --- /dev/null +++ b/src/tests/CMakeLists.txt @@ -0,0 +1,23 @@ +# 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) + +set(gretl_test_sources + test_gretl_checkpoint.cpp + test_gretl_dynamics.cpp + test_gretl_graph.cpp) + +foreach(test ${gretl_test_sources}) + get_filename_component( test_name ${test} NAME_WE ) + blt_add_executable(NAME ${test_name} + SOURCES ${test} + OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY} + DEPENDS_ON gretl gtest + FOLDER gretl/tests ) + + blt_add_test(NAME ${test_name} + COMMAND ${test_name} ) +endforeach() + diff --git a/tests/test_gretl_checkpoint.cpp b/src/tests/test_gretl_checkpoint.cpp similarity index 96% rename from tests/test_gretl_checkpoint.cpp rename to src/tests/test_gretl_checkpoint.cpp index 0079cf6..94eb6b7 100644 --- a/tests/test_gretl_checkpoint.cpp +++ b/src/tests/test_gretl_checkpoint.cpp @@ -8,9 +8,9 @@ #include #include #include "gtest/gtest.h" -#include "checkpoint.hpp" -#include "state.hpp" -#include "data_store.hpp" +#include "gretl/checkpoint.hpp" +#include "gretl/state.hpp" +#include "gretl/data_store.hpp" static size_t count = 0; @@ -150,7 +150,7 @@ TEST_F(CheckpointFixture, Automated) std::vector advanceStates(N + 1); gretl::DataStore dataStore(S); - gretl::State X = dataStore.create_state(x); + gretl::State X = dataStore.create_state(x); advanceStates[0] = X.get(); for (size_t n = 0; n < N; ++n) { diff --git a/tests/test_gretl_dynamics.cpp b/src/tests/test_gretl_dynamics.cpp similarity index 97% rename from tests/test_gretl_dynamics.cpp rename to src/tests/test_gretl_dynamics.cpp index cfbac3b..17dcb8a 100644 --- a/tests/test_gretl_dynamics.cpp +++ b/src/tests/test_gretl_dynamics.cpp @@ -11,10 +11,10 @@ #include #include #include "gtest/gtest.h" -#include "checkpoint.hpp" -#include "state.hpp" -#include "test_utils.hpp" -#include "vector_state.hpp" +#include "gretl/checkpoint.hpp" +#include "gretl/state.hpp" +#include "gretl/test_utils.hpp" +#include "gretl/vector_state.hpp" static constexpr size_t numParams = 4; diff --git a/tests/test_gretl_graph.cpp b/src/tests/test_gretl_graph.cpp similarity index 97% rename from tests/test_gretl_graph.cpp rename to src/tests/test_gretl_graph.cpp index d6e5035..55edfb0 100644 --- a/tests/test_gretl_graph.cpp +++ b/src/tests/test_gretl_graph.cpp @@ -8,10 +8,10 @@ #include #include #include -#include "vector_state.hpp" -#include "data_store.hpp" -#include "test_utils.hpp" #include "gtest/gtest.h" +#include "gretl/vector_state.hpp" +#include "gretl/data_store.hpp" +#include "gretl/test_utils.hpp" using gretl::print; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index 6bd32b7..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# 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) - -include(FetchContent) -FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) - -file(GLOB_RECURSE cpp_tests ${PROJECT_SOURCE_DIR}/tests/*.cpp) - -foreach(filename ${cpp_tests}) - - get_filename_component(testname ${filename} NAME_WE) - - add_executable(${testname} ${filename}) - target_link_libraries(${testname} PUBLIC ${CMAKE_PROJECT_NAME} GTest::gtest_main) - - add_test(${testname} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${testname}) - -endforeach(filename ${cpp_tests}) - -