Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic build system, unit-testing, and Doxygen documentation. #1

Merged
merged 32 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
422600a
Basic build system, unit-testing, and Doxygen documentation.
andrewcoughtrie Oct 27, 2021
9b10688
Update Profiler.md
andrewcoughtrie Oct 27, 2021
da3224d
Merge branch 'main' into build-system
andrewcoughtrie Nov 5, 2021
1423f75
Code review changes to .gitignore file.
andrewcoughtrie Nov 5, 2021
5cd763b
Code review changes to CMakeLists.txt
andrewcoughtrie Nov 5, 2021
77d9324
Code review changes to root README.md file
andrewcoughtrie Nov 5, 2021
0fa81e9
Code review changes to cmake/CompilerWarnings.cmake
andrewcoughtrie Nov 5, 2021
d129a4d
Code review changes to cmake/Doxygen.cmake
andrewcoughtrie Nov 5, 2021
77c5f3f
Code review changes to cmake/PreventInSourceBuilds.cmake
andrewcoughtrie Nov 5, 2021
75aa036
Code review changes to cmake/StandardProjectSettings.cmake
andrewcoughtrie Nov 5, 2021
3600243
Code review changes to cmake/TestingSetup.cmake, also moved find_pack…
andrewcoughtrie Nov 5, 2021
a0a2304
Code review changes to documentation/Doxygen/Prodiler.md
andrewcoughtrie Nov 15, 2021
d55b1fd
Code review changes to documentation/Doxygen/html
andrewcoughtrie Nov 15, 2021
da8d1d9
Code review changes to profilerConfig.cmake.in
andrewcoughtrie Nov 15, 2021
bbfee39
Code review changes to tests
andrewcoughtrie Nov 15, 2021
f20b2f7
Code review changes to src/CMakeLists.txt
andrewcoughtrie Nov 15, 2021
a5b2dbf
Merge remote-tracking branch 'origin/build-system' into build-system
andrewcoughtrie Nov 15, 2021
ad10b64
Review changes to CMakeLists.txt file
andrewcoughtrie Nov 30, 2021
e11c509
Review changes to README.md file
andrewcoughtrie Nov 30, 2021
566b185
Review changes to cmake/CompilerWarnings.cmake file
andrewcoughtrie Nov 30, 2021
87e368e
Review changes to cmake/Doxygen.cmake file
andrewcoughtrie Nov 30, 2021
1d9624d
Review changes to cmake/PreventInSourceBuilds.cmake file
andrewcoughtrie Nov 30, 2021
b66f014
Review changes to cmake/StandardProjectSettings.cmake file
andrewcoughtrie Nov 30, 2021
089dc97
Review changes to documentation/Doxygen/Profiler.md file
andrewcoughtrie Nov 30, 2021
e67775b
Review changes to src/CMakeLists.txt file
andrewcoughtrie Nov 30, 2021
c916bb1
Review changes to profilerConfig.cmake.in file
andrewcoughtrie Nov 30, 2021
ad19090
Review changes to tests/hello_test.cpp file
andrewcoughtrie Nov 30, 2021
2e2804f
Review changes to tests/CMakeLists.txt file
andrewcoughtrie Nov 30, 2021
01b65d9
Review changes to .gitignore file
andrewcoughtrie Nov 30, 2021
cf57ec6
Review changes to src/CMakeLists.txt file
andrewcoughtrie Nov 30, 2021
7f1f892
Review changes to documentation/Doxygen/Profiler.md file
andrewcoughtrie Nov 30, 2021
be078f7
PR #1: Updated changelog for merge to master
TeranIvy Nov 30, 2021
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
174 changes: 174 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
### Emacs template
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved
.org-id-locations
*_archive

# Flymake-mode
*_flymake.*

# Eshell files
/eshell/history
/eshell/lastdir

# ELPA packages
/elpa/

# Reftex files
*.rel

# AUCTeX auto folder
/auto/

# Cask packages
.cask/
dist/

# Flycheck
flycheck_*.el

# Server auth directory
/server/

# Projectiles files
.projectile

# Directory configuration
.dir-locals.el

# Network security
/network-security.data


### Visual Studio Code template
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

### C++ template
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

### Fortran template
# Prerequisites

# Compiled Object files

# Precompiled Headers
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved

# Compiled Dynamic libraries

# Fortran module files

# Compiled Static libraries

# Executables

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/

# CMake
cmake-build-*/

# File-based project format
*.iws

# IntelliJ IDEA
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Vim template
# Swap
[._]*.s[a-v][a-z]
!*.svg # Comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

### CMake template
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

### Build directory
build/
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

### Commits to master ###

DD/MM/YYYY PR #NNN:
30/11/2021 PR #1: Add basic build system, unit-testing, and Doxygen documentation.
65 changes: 65 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Set the minimum version of CMake required by the build system.
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved

# Include file containing in-source build prevention.
include(cmake/PreventInSourceBuilds.cmake)

# Set project name and the languages required to build the project and a
# project description.
project(profiler LANGUAGES CXX
DESCRIPTION "Met Office profiler")

# Set project versioning.
# TODO - Issue #12 Move versioning to the project settings above.
set(SOVERSION 0)
set(VERSION 0.1.0)

# Include general project setting files.
include(cmake/StandardProjectSettings.cmake)
include(cmake/CompilerWarnings.cmake)
include(cmake/Doxygen.cmake)
enable_doxygen()

# Trick to make it easier to add warnings and options to libs/executables.
add_library(project_options INTERFACE)
add_library(project_warnings INTERFACE)
set_project_warnings(project_warnings)

# Defines some standard install directories such as $(prefix)/include.
include(GNUInstallDirs)

# Add src directory to build.
add_subdirectory(src)

# Include the testing setup.
include(cmake/TestingSetup.cmake)

# All below is for installation and creation of *.cmake files for use with the
# find_package cmake function.
# TODO - Issue #13 Move installation functionality to file in cmake directory.
install(
EXPORT "${CMAKE_PROJECT_NAME}Targets"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}
NAMESPACE ${CMAKE_PROJECT_NAME}::
FILE "${CMAKE_PROJECT_NAME}Targets.cmake"
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_PROJECT_NAME}Config.cmake.in"
"${CMAKE_PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}"
PATH_VARS CMAKE_INSTALL_LIBDIR
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake"
VERSION ${VERSION}
COMPATIBILITY SameMajorVersion
)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}"
)
File renamed without changes.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
# profiler

Profiler for scientific code on HPC platforms.
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved

### Requirements

- C++17 compatible compiler.
- CMake version 3.13 or newer.
- GoogleTest version 1.11 or newer.

### Supported Compilers

The code has been tested with the following compilers:
- GCC versions: 9.2.0, 10.2.0.

### Testing Framework and Documentation

The testing framework is GoogleTest (1.11.0).
Source code documentation is generated using Doxygen (minimum 1.8.5).

### Building profiler

**To build:**
In project root directory:
~~~~~~~~~~~~~~~~shell
mkdir build
cd build
cmake ..
make
make test
~~~~~~~~~~~~~~~~
90 changes: 90 additions & 0 deletions cmake/CompilerWarnings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Contains a function for setting up the appropriate warnings for
# different compilers and build settings.
function(set_project_warnings project_name)
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved
# Create option for forcing errors for all warnings.
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)

# Create option to turn on sanitizers.
option(USE_SANITIZERS "Turn on sanitizers to help reporting of runtime errors" OFF)

set(CLANG_WARNINGS
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved
# All warnings (actually not all warnings obviously)
-Wall
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved
# More warnings (should be used on non-legacy code)
-Wextra
# Warn the user if a variable declaration shadows one from a parent context
-Wshadow
# Warn the user if a class with virtual functions has a non-virtual destructor.
# This helps catch hard to track down memory errors
-Wnon-virtual-dtor
# Warn for C-style casts
-Wold-style-cast
# Warn for potential performance problem casts
-Wcast-align
# Warn on anything being unused
-Wunused
# Warn if you overload (not override) a virtual function
-Woverloaded-virtual
# Warn if non-standard C++ is used
-Wpedantic
# Warn on type conversions that may lose data
-Wconversion
# Warn on sign conversions
-Wsign-conversion
# Warn if a null dereference is detected
-Wnull-dereference
# Warn if float is implicit promoted to double
-Wdouble-promotion
# Warn on security issues around functions that format output (i.e. 'printf')
-Wformat=2
)

# Set warnings as errors if requested (recommended during development/debug)
if (WARNINGS_AS_ERRORS)
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
endif ()

set(GCC_WARNINGS
# Include all Clang compiler warnings (uses same flags as g++)
${CLANG_WARNINGS}
# Warn if indentation implies blocks where blocks do not exist
-Wmisleading-indentation
# Warn if 'if / else' chain has duplicated conditions
-Wduplicated-cond
# Warn if 'if / else' branches have duplicated code
-Wduplicated-branches
# Warn about logical operations being used where bitwise were probably wanted
-Wlogical-op
# Warn if you perform a cast to the same type
-Wuseless-cast
)

# Set compiler and linker flags depending on compiler
if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
TeranIvy marked this conversation as resolved.
Show resolved Hide resolved
if(USE_SANITIZERS)
# Set Clang sanitizers for memory errors/leaks and undefined behaviour
set(CLANG_WARNINGS -fsanitize=address,undefined ${CLANG_WARNINGS})
set(CLANG_LINKER_FLAGS -fsanitize=address,undefined)
endif()
set(PROJECT_WARNINGS ${CLANG_WARNINGS})
set(LINKER_FLAGS ${CLANG_LINKER_FLAGS})
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(USE_SANITIZERS)
# Get GCC sanitizers for memory errors/leaks, undefined behaviour and pointer operands
set(GCC_WARNINGS
-fsanitize=address,undefined,leak,pointer-compare,pointer-subtract
${GCC_WARNINGS})
set(GCC_LINKER_FLAGS
-fsanitize=address,undefined,leak,pointer-compare,pointer-subtract)
endif()
set(PROJECT_WARNINGS ${GCC_WARNINGS})
set(LINKER_FLAGS ${GCC_LINKER_FLAGS})
else ()
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
endif ()

# Add compiler and linker flags to project_warnings
target_compile_options(project_warnings INTERFACE ${PROJECT_WARNINGS})
target_link_options(project_warnings INTERFACE ${LINKER_FLAGS})

endfunction()
Loading