Skip to content

Commit 45d5d9a

Browse files
committed
wip refactor and formalization
1 parent ab42d38 commit 45d5d9a

19 files changed

+7728
-214
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "cmake/blt"]
2+
path = cmake/blt
3+
url = [email protected]:LLNL/blt.git

CMakeLists.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
###################################################################################################
2+
# Copyright (c) 2024, Lawrence Livermore National Security, LLC.
3+
# All rights reserved.
4+
# See the LICENSE file for details.
5+
# SPDX-License-Identifier: (BSD-3-Clause)
6+
###################################################################################################
7+
8+
cmake_minimum_required( VERSION 3.23.1 )
9+
10+
# Set version number
11+
set( UNITGUARD_VERSION_MAJOR 0 )
12+
set( UNITGUARD_VERSION_MINOR 1 )
13+
set( UNITGUARD_VERSION_PATCHLEVEL 0 )
14+
15+
# check if UNITGUARD is build as a submodule or a separate project
16+
get_directory_property( parent_dir PARENT_DIRECTORY )
17+
if(parent_dir)
18+
set( is_submodule ON )
19+
else()
20+
set( is_submodule OFF )
21+
endif()
22+
23+
if( NOT is_submodule )
24+
message( STATUS "UnitGuard is not a submodule" )
25+
project( UNITGUARD LANGUAGES CXX C )
26+
27+
set( BLT_CXX_STD "c++17" CACHE STRING "Version of C++ standard" FORCE )
28+
set( ENABLE_WARNINGS_AS_ERRORS "ON" CACHE PATH "" )
29+
30+
option( UNITGUARD_ENABLE_UNIT_TESTS "Builds tests" ON )
31+
option( UNITGUARD_ENABLE_DOCS "Builds documentation" ON )
32+
33+
if( NOT BLT_LOADED )
34+
if( DEFINED BLT_SOURCE_DIR )
35+
if( NOT EXISTS ${BLT_SOURCE_DIR}/SetupBLT.cmake )
36+
message( FATAL_ERROR "Given BLT_SOURCE_DIR does not contain SetupBLT.cmake" )
37+
endif()
38+
else ()
39+
set( BLT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/cmake/blt CACHE PATH "" )
40+
41+
if( NOT EXISTS ${BLT_SOURCE_DIR}/SetupBLT.cmake )
42+
message( FATAL_ERROR "The BLT submodule is not present. If in git repository run the following two commands:\n \
43+
git submodule init\n \
44+
git submodule update" )
45+
endif ()
46+
endif ()
47+
48+
include( ${BLT_SOURCE_DIR}/SetupBLT.cmake )
49+
endif()
50+
else()
51+
if( NOT BLT_LOADED )
52+
message( FATAL_ERROR "When using UnitGuard as a submodule you must have already loaded BLT." )
53+
endif()
54+
endif()
55+
56+
include( cmake/CMakeBasics.cmake )
57+
include( cmake/Macros.cmake )
58+
include( cmake/Config.cmake )
59+
60+
add_subdirectory( src )
61+
62+
if( UNITGUARD_ENABLE_DOCS )
63+
add_subdirectory( docs )
64+
endif()

cmake/CMakeBasics.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if( CMAKE_CXX_STANDARD IN_LIST "98; 11; 14" )
2+
MESSAGE( FATAL_ERROR "UnitGaurd requires at least c++17" )
3+
endif()
4+
5+
blt_append_custom_compiler_flag( FLAGS_VAR CMAKE_CXX_FLAGS DEFAULT "${OpenMP_CXX_FLAGS}")
6+
blt_append_custom_compiler_flag( FLAGS_VAR CMAKE_CXX_FLAGS
7+
GNU "-Wpedantic -pedantic-errors -Wshadow -Wfloat-equal -Wcast-align -Wcast-qual"
8+
CLANG "-Wpedantic -pedantic-errors -Wshadow -Wfloat-equal -Wcast-align -Wcast-qual"
9+
)
10+
11+
blt_append_custom_compiler_flag( FLAGS_VAR CMAKE_CXX_FLAGS_DEBUG
12+
GNU ""
13+
CLANG "-fstandalone-debug"
14+
)

cmake/Config.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
if( ENABLE_ADDR2LINE )
2+
if ( NOT DEFINED ADDR2LINE_EXEC )
3+
set( ADDR2LINE_EXEC /usr/bin/addr2line CACHE PATH "" )
4+
endif()
5+
6+
if ( NOT EXISTS ${ADDR2LINE_EXEC} )
7+
message( FATAL_ERROR "The addr2line executable does not exist: ${ADDR2LINE_EXEC}" )
8+
endif()
9+
10+
set( UNITGUARD_ADDR2LINE_EXEC ${ADDR2LINE_EXEC} )
11+
endif()
12+
13+
14+
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/UnitGuardConfig.hpp.in
15+
${CMAKE_BINARY_DIR}/include/UnitGuardConfig.hpp )
16+
17+
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/UnitGuardConfig.hpp.in
18+
${CMAKE_CURRENT_SOURCE_DIR}/docs/doxygen/UnitGuardConfig.hpp )
19+
20+
# Install the generated header.
21+
install( FILES ${CMAKE_BINARY_DIR}/include/UnitGuardConfig.hpp
22+
DESTINATION include )
23+
24+
set(UNITGUARD_INSTALL_INCLUDE_DIR "include" CACHE STRING "")
25+
set(UNITGUARD_INSTALL_CONFIG_DIR "lib" CACHE STRING "")
26+
set(UNITGUARD_INSTALL_LIB_DIR "lib" CACHE STRING "")
27+
set(UNITGUARD_INSTALL_BIN_DIR "bin" CACHE STRING "")
28+
set(UNITGUARD_INSTALL_CMAKE_MODULE_DIR "${UNITGUARD_INSTALL_CONFIG_DIR}/cmake" CACHE STRING "")
29+
set(UNITGUARD_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "" FORCE)
30+
31+
32+
include(CMakePackageConfigHelpers)
33+
configure_package_config_file(
34+
${CMAKE_CURRENT_SOURCE_DIR}/cmake/unitguard-config.cmake.in
35+
${CMAKE_CURRENT_BINARY_DIR}/unitguard-config.cmake
36+
INSTALL_DESTINATION
37+
${UNITGUARD_INSTALL_CONFIG_DIR}
38+
PATH_VARS
39+
UNITGUARD_INSTALL_INCLUDE_DIR
40+
UNITGUARD_INSTALL_LIB_DIR
41+
UNITGUARD_INSTALL_BIN_DIR
42+
UNITGUARD_INSTALL_CMAKE_MODULE_DIR
43+
)
44+
45+
46+
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/unitguard-config.cmake
47+
DESTINATION share/unitguard/cmake/)

cmake/Macros.cmake

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
macro(untiguard_add_code_checks)
2+
3+
set(options)
4+
set(singleValueArgs PREFIX UNCRUSTIFY_CFG_FILE )
5+
set(multiValueArgs EXCLUDES )
6+
7+
# Parse the arguments to the macro
8+
cmake_parse_arguments(arg
9+
"${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN})
10+
11+
set(_all_sources)
12+
file(GLOB_RECURSE _all_sources
13+
"*.cpp" "*.hpp" "*.cxx" "*.hxx" "*.cc" "*.c" "*.h" "*.hh" )
14+
15+
# Check for excludes
16+
if (NOT DEFINED arg_EXCLUDES)
17+
set(_sources ${_all_sources})
18+
else()
19+
set(_sources)
20+
foreach(_source ${_all_sources})
21+
set(_to_be_excluded FALSE)
22+
foreach(_exclude ${arg_EXCLUDES})
23+
if (${_source} MATCHES ${_exclude})
24+
set(_to_be_excluded TRUE)
25+
break()
26+
endif()
27+
endforeach()
28+
29+
if (NOT ${_to_be_excluded})
30+
list(APPEND _sources ${_source})
31+
endif()
32+
endforeach()
33+
endif()
34+
35+
set( CPPCHECK_FLAGS --std=c++17
36+
--enable=all
37+
--suppress=missingIncludeSystem
38+
--suppress=unmatchedSuppression
39+
--suppress=missingInclude
40+
--suppress=noConstructor
41+
--suppress=noExplicitConstructor
42+
--suppress=unusedFunction
43+
--suppress=constStatement
44+
--suppress=unusedStructMember )
45+
46+
blt_add_code_checks( PREFIX ${arg_PREFIX}
47+
SOURCES ${_sources}
48+
UNCRUSTIFY_CFG_FILE ${PROJECT_SOURCE_DIR}/src/uncrustify.cfg
49+
CPPCHECK_FLAGS ${CPPCHECK_FLAGS}
50+
)
51+
52+
if( CPPCHECK_FOUND )
53+
add_test( NAME testCppCheck
54+
COMMAND bash -c "make cppcheck_check 2> >(tee cppcheck.err) >/dev/null && exit $(cat cppcheck.err | wc -l)"
55+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
56+
)
57+
endif()
58+
59+
if( CLANGTIDY_FOUND )
60+
add_test( NAME testClangTidy
61+
COMMAND bash -c "make clang_tidy_check 2> >(tee tidyCheck.err) >/dev/null && exit $(cat tidyCheck.err | wc -l)"
62+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
63+
)
64+
endif()
65+
66+
67+
if (ENABLE_COVERAGE)
68+
blt_add_code_coverage_target(NAME ${arg_PREFIX}_coverage
69+
RUNNER ctest -E 'blt_gtest_smoke|testCppCheck|testClangTidy|testUncrustifyCheck|testDoxygenCheck|testCppCheck|testClangTidy'
70+
SOURCE_DIRECTORIES ${PROJECT_SOURCE_DIR}/src )
71+
endif()
72+
endmacro(untiguard_add_code_checks)

cmake/blt

Submodule blt added at 2bf714a

cmake/unitguard-config.cmake.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if( NOT UNITGUARD_FOUND )
2+
include(${CMAKE_CURRENT_LIST_DIR}/../../../lib/cmake/unitguard/unitguard.cmake)
3+
set(UNITGUARD_FOUND TRUE)
4+
# Export version number
5+
set( UNITGUARD_VERSION_MAJOR @UNITGUARD_VERSION_MAJOR@ )
6+
set( UNITGUARD_VERSION_MINOR @UNITGUARD_VERSION_MINOR@ )
7+
set( UNITGUARD_VERSION_PATCHLEVEL @UNITGUARD_VERSION_PATCHLEVEL@ )
8+
endif()

docs/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if(DOXYGEN_FOUND)
2+
blt_add_doxygen_target( unitguard_doxygen )
3+
4+
add_test( NAME testDoxygenCheck
5+
COMMAND bash -c "${mkdir_cmd} ${DOXYGEN_EXECUTABLE} Doxyfile 2> >(tee doxygen.err) && exit $(cat doxygen.err | wc -l)"
6+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
7+
)
8+
endif()

0 commit comments

Comments
 (0)