From 422600a8496aa92673b74a31fb943fb5acb9307e Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Wed, 27 Oct 2021 11:51:57 +0100 Subject: [PATCH 01/30] Basic build system, unit-testing, and Doxygen documentation. --- .gitignore | 216 +++++++++++++++++++++++++ CMakeLists.txt | 55 +++++++ README.md | 15 ++ cmake/CompilerWarnings.cmake | 55 +++++++ cmake/Doxygen.cmake | 27 ++++ cmake/PreventInSourceBuilds.cmake | 18 +++ cmake/StandardProjectSettings.cmake | 42 +++++ cmake/TestingSetup.cmake | 2 + documentation/Doxygen/Profiler.md | 35 ++++ documentation/Doxygen/html/footer.html | 21 +++ documentation/Doxygen/html/header.html | 55 +++++++ profilerConfig.cmake.in | 2 + src/CMakeLists.txt | 22 +++ src/profiler.h | 6 + tests/CMakeLists.txt | 14 ++ tests/hello_test.cpp | 18 +++ 16 files changed, 603 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 cmake/CompilerWarnings.cmake create mode 100644 cmake/Doxygen.cmake create mode 100644 cmake/PreventInSourceBuilds.cmake create mode 100644 cmake/StandardProjectSettings.cmake create mode 100644 cmake/TestingSetup.cmake create mode 100644 documentation/Doxygen/Profiler.md create mode 100644 documentation/Doxygen/html/footer.html create mode 100644 documentation/Doxygen/html/header.html create mode 100644 profilerConfig.cmake.in create mode 100644 src/CMakeLists.txt create mode 100644 src/profiler.h create mode 100644 tests/CMakeLists.txt create mode 100644 tests/hello_test.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..00e3fe11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,216 @@ +### Emacs template +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.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 + + +### VisualStudioCode 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 +*.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 + +# 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/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### 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 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..db01eb68 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,55 @@ +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) +include(cmake/PreventInSourceBuilds.cmake) + +project(profiler LANGUAGES CXX + DESCRIPTION "Met Office Profiler") + +set(SOVERSION 0) +set(VERSION 0.1.0) + +include(cmake/StandardProjectSettings.cmake) +include(cmake/CompilerWarnings.cmake) +include(cmake/Doxygen.cmake) +enable_doxygen() + +add_library(project_options INTERFACE) +add_library(project_warnings INTERFACE) +set_project_warnings(project_warnings) + +# Find required packages +find_package(GTest REQUIRED) +include(GoogleTest) + +include(GNUInstallDirs) + +add_subdirectory(src) + +include(cmake/TestingSetup.cmake) + +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}" + ) + diff --git a/README.md b/README.md index 55caf77b..1d4d97f2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # profiler Profiler for scientific code on HPC platforms. + +## Building +Requires a c++17 compatible compiler, currently only tested with GCC-9.2.0. + +The testing framework is GoogleTest (1.11.0) and source code documentation is created using Doxygen (1.8.5). + +**To build:** +In project root directory. +~~~~~~~~~~~~~~~~shell +mkdir build +cd build +cmake .. +make +make test +~~~~~~~~~~~~~~~~ diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake new file mode 100644 index 00000000..6354e028 --- /dev/null +++ b/cmake/CompilerWarnings.cmake @@ -0,0 +1,55 @@ +function(set_project_warnings project_name) + option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) + + set(CLANG_WARNINGS + -Wall + -Wextra # reasonable and standard + -Wshadow # warn the user if a variable declaration shadows one from a parent context + -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps + # catch hard to track down memory errors + -Wold-style-cast # warn for c-style casts + -Wcast-align # warn for potential performance problem casts + -Wunused # warn on anything being unused + -Woverloaded-virtual # warn if you overload (not override) a virtual function + -Wpedantic # warn if non-standard C++ is used + -Wconversion # warn on type conversions that may lose data + -Wsign-conversion # warn on sign conversions + -Wnull-dereference # warn if a null dereference is detected + -Wdouble-promotion # warn if float is implicit promoted to double + -Wformat=2 # warn on security issues around functions that format output (ie printf) + ) + + if (WARNINGS_AS_ERRORS) + set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) + endif () + + set(GCC_WARNINGS + -fsanitize=address,undefined,leak,pointer-compare,pointer-subtract + ${CLANG_WARNINGS} + -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist + -Wduplicated-cond # warn if if / else chain has duplicated conditions + -Wduplicated-branches # warn if if / else branches have duplicated code + -Wlogical-op # warn about logical operations being used where bitwise were probably wanted + -Wuseless-cast # warn if you perform a cast to the same type + ) + + set(CLANG_LINKER_FLAGS + -fsanitize=address,undefined) + + set(GCC_LINKER_FLAGS + -fsanitize=address,undefined,leak,pointer-compare,pointer-subtract) + + if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + set(PROJECT_WARNINGS ${CLANG_WARNINGS}) + set(LINKER_FLAGS ${CLANG_LINKER_FLAGS}) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + 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 () + + target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) + target_link_options(${project_name} INTERFACE ${LINKER_FLAGS}) + +endfunction() \ No newline at end of file diff --git a/cmake/Doxygen.cmake b/cmake/Doxygen.cmake new file mode 100644 index 00000000..167e3bd7 --- /dev/null +++ b/cmake/Doxygen.cmake @@ -0,0 +1,27 @@ +function(enable_doxygen) + option(ENABLE_DOXYGEN "Enable doxygen doc builds of source" ON) + if (ENABLE_DOXYGEN) + set(DOXYGEN_CALLER_GRAPH YES) + set(DOXYGEN_CALL_GRAPH YES) + set(DOXYGEN_EXTRACT_ALL YES) + set(DOXYGEN_PRIVATE YES) + set(DOXYGEN_GENERATE_LATEX YES) + set(DOXYGEN_LATEX_OUTPUT pdf) + set(DOXYGEN_HIDE_SCOPE_NAMES YES) + set(DOXYGEN_PROJECT_NAME "Profiler") + set(DOXYGEN_PROJECT_NUMBER "v${VERSION}") + set(DOXYGEN_DISABLE_INDEX NO) + set(DOXYGEN_GENERATE_TREEVIEW YES) + set(DOXYGEN_JAVADOC_BANNER NO) + set(DOXYGEN_JAVADOC_AUTOBRIEF NO) + set(DOXYGEN_JAVADOC_BLOCK NO) + set(DOXYGEN_FULL_PATH_NAMES NO) + set(DOXYGEN_STRIP_CODE_COMMENTS NO) + set(DOXYGEN_HTML_HEADER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/header.html) + set(DOXYGEN_HTML_FOOTER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/footer.html) +# set(DOXYGEN_HTML_STYLESHEET ${PROJECT_SOURCE_DIR}/documentation/Doxygen/customdoxygen.css) + find_package(Doxygen REQUIRED dot) + doxygen_add_docs(doxygen-docs ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/documentation/Doxygen ALL) + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/docs) + endif () +endfunction() \ No newline at end of file diff --git a/cmake/PreventInSourceBuilds.cmake b/cmake/PreventInSourceBuilds.cmake new file mode 100644 index 00000000..d3cee97a --- /dev/null +++ b/cmake/PreventInSourceBuilds.cmake @@ -0,0 +1,18 @@ +# +# This function will prevent in-source builds +function(AssureOutOfSourceBuilds) + # make sure the user doesn't play dirty with symlinks + get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) + get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) + + # disallow in-source builds + if ("${srcdir}" STREQUAL "${bindir}") + message("######################################################") + message("Warning: in-source builds are disabled") + message("Please create a separate build directory and run cmake from there") + message("######################################################") + message(FATAL_ERROR "Quitting configuration") + endif () +endfunction() + +assureoutofsourcebuilds() \ No newline at end of file diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake new file mode 100644 index 00000000..bc980ad8 --- /dev/null +++ b/cmake/StandardProjectSettings.cmake @@ -0,0 +1,42 @@ +# Set C++ standard compliance +set(CMAKE_CXX_STANDARD 17) + +# Set a default build type if none was specified +if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.") + set(CMAKE_BUILD_TYPE + RelWithDebInfo + CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui, ccmake + set_property( + CACHE CMAKE_BUILD_TYPE + PROPERTY STRINGS + "Debug" + "Debug-Coverage" + "Release" + "MinSizeRel" + "RelWithDebInfo") +endif () + +# Generate compile_commands.json to make it easier to work with clang based tools +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +option(ENABLE_IPO "Enable Interprocedural Optimization, aka Link Time Optimization (LTO)" OFF) + +if (ENABLE_IPO) + include(CheckIPOSupported) + check_ipo_supported( + RESULT + result + OUTPUT + output) + if (result) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) + else () + message(SEND_ERROR "IPO is not supported: ${output}") + endif () +endif () + +if(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "..." FORCE) +endif() \ No newline at end of file diff --git a/cmake/TestingSetup.cmake b/cmake/TestingSetup.cmake new file mode 100644 index 00000000..5cba7816 --- /dev/null +++ b/cmake/TestingSetup.cmake @@ -0,0 +1,2 @@ +enable_testing() +add_subdirectory(tests) diff --git a/documentation/Doxygen/Profiler.md b/documentation/Doxygen/Profiler.md new file mode 100644 index 00000000..44960adf --- /dev/null +++ b/documentation/Doxygen/Profiler.md @@ -0,0 +1,35 @@ +Documentation {#mainpage} +============= +[TOC] + +# Introduction {#Introduction} +This is a profiling tool written in C++ designed for use with the Unified +Model and LFRic. +The current implementation is a work in progress. + +# Metrics {#metrics} + +The Metrics to be included are going to be based on Performance Optimisation +and Productivity (POP) Standard Metrics +for Parallel Performance Analysis. + +## Load Balance {#lb} +~~~~~~~~~~~~~~~~~~~~~~~cpp +class A { + private: + int a_; + + public: + // Constructor + A(int a):a_(a){}; + + // Destructor + ~A; + + // Getter + void get_a(){return a_;} +}; +~~~~~~~~~~~~~~~~~~~~~~~ + +## Communication Efficiency {#comme} + \ No newline at end of file diff --git a/documentation/Doxygen/html/footer.html b/documentation/Doxygen/html/footer.html new file mode 100644 index 00000000..1ea92c85 --- /dev/null +++ b/documentation/Doxygen/html/footer.html @@ -0,0 +1,21 @@ + + + + + + + + + + \ No newline at end of file diff --git a/documentation/Doxygen/html/header.html b/documentation/Doxygen/html/header.html new file mode 100644 index 00000000..731e1a5d --- /dev/null +++ b/documentation/Doxygen/html/header.html @@ -0,0 +1,55 @@ + + + + + + + + $projectname: $title + $title + + + + $treeview + $search + $mathjax + + $extrastylesheet + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + + +
$projectbrief
+
$searchbox
+
+ + \ No newline at end of file diff --git a/profilerConfig.cmake.in b/profilerConfig.cmake.in new file mode 100644 index 00000000..c8509c00 --- /dev/null +++ b/profilerConfig.cmake.in @@ -0,0 +1,2 @@ +@PACKAGE_INIT@ +include( "${CMAKE_CURRENT_LIST_DIR}/profilerTargets.cmake" ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..ab5d7aac --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,22 @@ +include(CMakePackageConfigHelpers) + +add_library(${CMAKE_PROJECT_NAME} SHARED + profiler.h + ) + +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE + project_warnings + project_options) + +set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES + SOVERSION ${SOVERSION} + VERSION ${VERSION} + LINKER_LANGUAGE CXX + PUBLIC_HEADER "profiler.h") + +install(TARGETS ${CMAKE_PROJECT_NAME} EXPORT "${CMAKE_PROJECT_NAME}Targets" + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT "${CMAKE_PROJECT_NAME}_RunTime" + NAMELINK_COMPONENT "${CMAKE_PROJECT_NAME}_Development" + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/src/profiler.h b/src/profiler.h new file mode 100644 index 00000000..f13f308c --- /dev/null +++ b/src/profiler.h @@ -0,0 +1,6 @@ +#ifndef PROFILER_H +#define PROFILER_H + +// Empty file for testing build system. + +#endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..212abd2d --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,14 @@ +function(add_unit_test test_name cpp_file) + add_executable(${test_name} ${cpp_file}) + target_link_libraries(${test_name} + project_warnings + project_options + GTest::Main) + target_include_directories(${test_name} PRIVATE + ${PROJECT_SOURCE_DIR}/src) + gtest_discover_tests(${test_name}) +endfunction() + +add_unit_test(hello_test hello_test.cpp) + + diff --git a/tests/hello_test.cpp b/tests/hello_test.cpp new file mode 100644 index 00000000..67eb5520 --- /dev/null +++ b/tests/hello_test.cpp @@ -0,0 +1,18 @@ +/*----------------------------------------------------------------------------*\ + (C) Crown copyright 2021 Met Office. All rights reserved. + The file LICENCE, distributed with this code, contains details of the terms + under which the code may be used. +-------------------------------------------------------------------------------- + Description + A basic unit test example using GTest +\*----------------------------------------------------------------------------*/ + +#include + +// Demonstrate some basic assertions. +TEST(HelloTest, BasicAssertions) { + // Expect two strings not to be equal. + EXPECT_STRNE("hello", "world"); + // Expect equality. + EXPECT_EQ(7 * 6, 42); +} From 9b10688fdde8ed2005a6f78fcd3ff360665ce80e Mon Sep 17 00:00:00 2001 From: Andrew Coughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Wed, 27 Oct 2021 18:03:44 +0100 Subject: [PATCH 02/30] Update Profiler.md --- documentation/Doxygen/Profiler.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/Doxygen/Profiler.md b/documentation/Doxygen/Profiler.md index 44960adf..78cf4af9 100644 --- a/documentation/Doxygen/Profiler.md +++ b/documentation/Doxygen/Profiler.md @@ -27,9 +27,9 @@ class A { ~A; // Getter - void get_a(){return a_;} + int get_a(){return a_;} }; ~~~~~~~~~~~~~~~~~~~~~~~ ## Communication Efficiency {#comme} - \ No newline at end of file + From 1423f757f59707fe5c234f28d632b00cb4e94972 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Fri, 5 Nov 2021 11:31:54 +0000 Subject: [PATCH 03/30] Code review changes to .gitignore file. --- .gitignore | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 00e3fe11..85158e05 100644 --- a/.gitignore +++ b/.gitignore @@ -13,43 +13,43 @@ tramp .org-id-locations *_archive -# flymake-mode +# Flymake-mode *_flymake.* -# eshell files +# Eshell files /eshell/history /eshell/lastdir -# elpa packages +# ELPA packages /elpa/ -# reftex files +# Reftex files *.rel # AUCTeX auto folder /auto/ -# cask packages +# Cask packages .cask/ dist/ # Flycheck flycheck_*.el -# server auth directory +# Server auth directory /server/ -# projectiles files +# Projectiles files .projectile -# directory configuration +# Directory configuration .dir-locals.el -# network security +# Network security /network-security.data -### VisualStudioCode template +### Visual Studio Code template .vscode/* !.vscode/settings.json !.vscode/tasks.json @@ -132,13 +132,14 @@ flycheck_*.el .idea/**/uiDesigner.xml .idea/**/dbnavigator.xml -# Gradle +# Gradle Build Tool .idea/**/gradle.xml .idea/**/libraries # Gradle and Maven with auto-import # When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using +# since they will be recreated, and may cause churn. +# Uncomment if using. # auto-import. # .idea/artifacts # .idea/compiler.xml @@ -152,13 +153,13 @@ flycheck_*.el # CMake cmake-build-*/ -# Mongo Explorer plugin +# MongoDB Explorer plugin .idea/**/mongoSettings.xml # File-based project format *.iws -# IntelliJ +# IntelliJ IDEA out/ # mpeltonen/sbt-idea plugin @@ -179,13 +180,13 @@ fabric.properties # Editor-based Rest Client .idea/httpRequests -# Android studio 3.1+ serialized cache file +# Android Studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser ### Vim template # Swap [._]*.s[a-v][a-z] -!*.svg # comment out if you don't need vector files +!*.svg # Comment out if you don't need vector files [._]*.sw[a-p] [._]s[a-rt-v][a-z] [._]ss[a-gi-z] @@ -213,4 +214,4 @@ cmake_install.cmake install_manifest.txt compile_commands.json CTestTestfile.cmake -_deps \ No newline at end of file +_deps From 5cd763b155c7ebc8f3e3a822f0f2e361bd9ad570 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Fri, 5 Nov 2021 11:45:57 +0000 Subject: [PATCH 04/30] Code review changes to CMakeLists.txt --- CMakeLists.txt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db01eb68..233817b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,26 @@ +# Set the minimum version of CMake required by the build system. cmake_minimum_required(VERSION 3.13 FATAL_ERROR) + +# 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") + DESCRIPTION "Met Office profiler") +# Set project versioning +# TODO - Move this to the project setting above, requires a few other changes. 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) @@ -20,12 +29,18 @@ set_project_warnings(project_warnings) find_package(GTest REQUIRED) include(GoogleTest) +# 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 - Move all below to file in cmake directory. install( EXPORT "${CMAKE_PROJECT_NAME}Targets" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME} @@ -52,4 +67,3 @@ install( "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}" ) - From 77d932464ec79a99575dd3b7a68da14732430c2e Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Fri, 5 Nov 2021 13:20:50 +0000 Subject: [PATCH 05/30] Code review changes to root README.md file --- README.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1d4d97f2..bf146664 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,27 @@ # profiler + Profiler for scientific code on HPC platforms. -## Building -Requires a c++17 compatible compiler, currently only tested with GCC-9.2.0. +### 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). -The testing framework is GoogleTest (1.11.0) and source code documentation is created using Doxygen (1.8.5). +### Building profiler **To build:** -In project root directory. +In project root directory: ~~~~~~~~~~~~~~~~shell mkdir build cd build From 0fa81e9720801854eb43a03ed182eac4a48911b4 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Fri, 5 Nov 2021 14:28:54 +0000 Subject: [PATCH 06/30] Code review changes to cmake/CompilerWarnings.cmake --- cmake/CompilerWarnings.cmake | 93 +++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index 6354e028..470af4e2 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -1,55 +1,90 @@ +# Contains a function for setting up the appropriate warnings for +# different compilers and build settings. function(set_project_warnings project_name) + # 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 + # All warnings (actually not all warnings obviously) -Wall - -Wextra # reasonable and standard - -Wshadow # warn the user if a variable declaration shadows one from a parent context - -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps - # catch hard to track down memory errors - -Wold-style-cast # warn for c-style casts - -Wcast-align # warn for potential performance problem casts - -Wunused # warn on anything being unused - -Woverloaded-virtual # warn if you overload (not override) a virtual function - -Wpedantic # warn if non-standard C++ is used - -Wconversion # warn on type conversions that may lose data - -Wsign-conversion # warn on sign conversions - -Wnull-dereference # warn if a null dereference is detected - -Wdouble-promotion # warn if float is implicit promoted to double - -Wformat=2 # warn on security issues around functions that format output (ie printf) + # More warnings (should be used on none 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 (ie printf) + -Wformat=2 ) + # Set warnings as errors if requested (Recommended during development/debug) if (WARNINGS_AS_ERRORS) set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) endif () set(GCC_WARNINGS - -fsanitize=address,undefined,leak,pointer-compare,pointer-subtract + # Include all Clang compiler warnings (uses same flags as g++) ${CLANG_WARNINGS} - -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist - -Wduplicated-cond # warn if if / else chain has duplicated conditions - -Wduplicated-branches # warn if if / else branches have duplicated code - -Wlogical-op # warn about logical operations being used where bitwise were probably wanted - -Wuseless-cast # warn if you perform a cast to the same type + # 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(CLANG_LINKER_FLAGS - -fsanitize=address,undefined) - - set(GCC_LINKER_FLAGS - -fsanitize=address,undefined,leak,pointer-compare,pointer-subtract) - + # Set compiler and linker flags depending on compiler if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + 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 () - target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) - target_link_options(${project_name} INTERFACE ${LINKER_FLAGS}) + # 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() \ No newline at end of file +endfunction() From d129a4df9615d9e13935351ad5b15f95f2b87a4f Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Fri, 5 Nov 2021 15:12:14 +0000 Subject: [PATCH 07/30] Code review changes to cmake/Doxygen.cmake --- cmake/Doxygen.cmake | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmake/Doxygen.cmake b/cmake/Doxygen.cmake index 167e3bd7..d1d7709f 100644 --- a/cmake/Doxygen.cmake +++ b/cmake/Doxygen.cmake @@ -1,3 +1,6 @@ +# This file sets up the options for the Doxygen generation of API documentation +# available options for CMake Doxygen integration can be found here: +# https://cmake.org/cmake/help/latest/module/FindDoxygen.html function(enable_doxygen) option(ENABLE_DOXYGEN "Enable doxygen doc builds of source" ON) if (ENABLE_DOXYGEN) @@ -7,8 +10,9 @@ function(enable_doxygen) set(DOXYGEN_PRIVATE YES) set(DOXYGEN_GENERATE_LATEX YES) set(DOXYGEN_LATEX_OUTPUT pdf) + set(DOXYGEN_MARKDOWN_SUPPORT YES) set(DOXYGEN_HIDE_SCOPE_NAMES YES) - set(DOXYGEN_PROJECT_NAME "Profiler") + set(DOXYGEN_PROJECT_NAME "${CMAKE_PROJECT_NAME}") set(DOXYGEN_PROJECT_NUMBER "v${VERSION}") set(DOXYGEN_DISABLE_INDEX NO) set(DOXYGEN_GENERATE_TREEVIEW YES) @@ -19,9 +23,14 @@ function(enable_doxygen) set(DOXYGEN_STRIP_CODE_COMMENTS NO) set(DOXYGEN_HTML_HEADER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/header.html) set(DOXYGEN_HTML_FOOTER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/footer.html) -# set(DOXYGEN_HTML_STYLESHEET ${PROJECT_SOURCE_DIR}/documentation/Doxygen/customdoxygen.css) + + # Find the Doxygen application install (requires dot) find_package(Doxygen REQUIRED dot) + + # Set up Doxygen build with source directory and additional pages. doxygen_add_docs(doxygen-docs ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/documentation/Doxygen ALL) + + # Set up installation destination install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/docs) endif () -endfunction() \ No newline at end of file +endfunction() From 77c5f3f49fe7e23929bfd7fa417f37db03c75f1a Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Fri, 5 Nov 2021 15:58:20 +0000 Subject: [PATCH 08/30] Code review changes to cmake/PreventInSourceBuilds.cmake --- cmake/PreventInSourceBuilds.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/PreventInSourceBuilds.cmake b/cmake/PreventInSourceBuilds.cmake index d3cee97a..862807e6 100644 --- a/cmake/PreventInSourceBuilds.cmake +++ b/cmake/PreventInSourceBuilds.cmake @@ -1,11 +1,12 @@ # # This function will prevent in-source builds function(AssureOutOfSourceBuilds) - # make sure the user doesn't play dirty with symlinks + # Make sure the user doesn't perform in source builds by tricking + # the build system through the use of symlinks get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) - # disallow in-source builds + # Disallow in-source builds if ("${srcdir}" STREQUAL "${bindir}") message("######################################################") message("Warning: in-source builds are disabled") @@ -15,4 +16,4 @@ function(AssureOutOfSourceBuilds) endif () endfunction() -assureoutofsourcebuilds() \ No newline at end of file +AssureOutOfSourceBuilds() From 75aa036ab774d225cdbecb827ef90d5e6f2bd3a4 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Fri, 5 Nov 2021 16:05:23 +0000 Subject: [PATCH 09/30] Code review changes to cmake/StandardProjectSettings.cmake --- cmake/StandardProjectSettings.cmake | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index bc980ad8..8ed819ea 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -1,3 +1,6 @@ +# Some basic project settings for defaults such as build type and installation +# prefix + # Set C++ standard compliance set(CMAKE_CXX_STANDARD 17) @@ -7,20 +10,24 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) - # Set the possible values of build type for cmake-gui, ccmake + # Set the possible values of build type for cmake-gui, ccmake. set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS - "Debug" - "Debug-Coverage" - "Release" - "MinSizeRel" - "RelWithDebInfo") + # These build type options set the listed compiler options. + # These are CMake default flags for C++ + "Debug" # -g + "Release" # -O3 -DNDEBUG + "MinSizeRel" # -Os -DNDEBUG + "RelWithDebInfo" # -O2 -g -DNDEBUG + ) endif () -# Generate compile_commands.json to make it easier to work with clang based tools +# Generate compile_commands.json to make it easier to work with Clang-based tools set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +# Interprocedural optimisation is useful for improving program performance through +# analysis of the entire program rather than just single program units. option(ENABLE_IPO "Enable Interprocedural Optimization, aka Link Time Optimization (LTO)" OFF) if (ENABLE_IPO) @@ -37,6 +44,7 @@ if (ENABLE_IPO) endif () endif () +#Set default install location to be in build directory rather than /usr/bin etc. if(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "..." FORCE) -endif() \ No newline at end of file +endif() From 360024338fff9e659fb1f418d9291df1d9b0cb32 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Fri, 5 Nov 2021 16:09:13 +0000 Subject: [PATCH 10/30] Code review changes to cmake/TestingSetup.cmake, also moved find_package for GoogleTest --- CMakeLists.txt | 4 ---- cmake/TestingSetup.cmake | 8 ++++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 233817b4..3f1700f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,10 +25,6 @@ add_library(project_options INTERFACE) add_library(project_warnings INTERFACE) set_project_warnings(project_warnings) -# Find required packages -find_package(GTest REQUIRED) -include(GoogleTest) - # Defines some standard install directories such as $(prefix)/include. include(GNUInstallDirs) diff --git a/cmake/TestingSetup.cmake b/cmake/TestingSetup.cmake index 5cba7816..8ba55173 100644 --- a/cmake/TestingSetup.cmake +++ b/cmake/TestingSetup.cmake @@ -1,2 +1,10 @@ +# Enable CTest integration with GoogleTest and add a directory for the tests + +# Find required testing packages +find_package(GTest REQUIRED) +include(GoogleTest) + +# Enable CTest enable_testing() + add_subdirectory(tests) From a0a2304e8f6c9cc5f2e4a4abf0ee9a3d86e7c9e9 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Mon, 15 Nov 2021 16:27:01 +0000 Subject: [PATCH 11/30] Code review changes to documentation/Doxygen/Prodiler.md --- documentation/Doxygen/Profiler.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/documentation/Doxygen/Profiler.md b/documentation/Doxygen/Profiler.md index 44960adf..983325e2 100644 --- a/documentation/Doxygen/Profiler.md +++ b/documentation/Doxygen/Profiler.md @@ -3,13 +3,14 @@ Documentation {#mainpage} [TOC] # Introduction {#Introduction} -This is a profiling tool written in C++ designed for use with the Unified + +This is a profiling tool written in C++ and designed for use with the Unified Model and LFRic. The current implementation is a work in progress. # Metrics {#metrics} -The Metrics to be included are going to be based on Performance Optimisation +The metrics to be included are going to be based on Performance Optimisation and Productivity (POP) Standard Metrics for Parallel Performance Analysis. @@ -32,4 +33,5 @@ class A { ~~~~~~~~~~~~~~~~~~~~~~~ ## Communication Efficiency {#comme} +TBD \ No newline at end of file From d55b1fd3e0abb42c619c49b05211fd7810586875 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Mon, 15 Nov 2021 16:28:34 +0000 Subject: [PATCH 12/30] Code review changes to documentation/Doxygen/html --- documentation/Doxygen/html/footer.html | 2 +- documentation/Doxygen/html/header.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/Doxygen/html/footer.html b/documentation/Doxygen/html/footer.html index 1ea92c85..dab72aab 100644 --- a/documentation/Doxygen/html/footer.html +++ b/documentation/Doxygen/html/footer.html @@ -18,4 +18,4 @@ - \ No newline at end of file + diff --git a/documentation/Doxygen/html/header.html b/documentation/Doxygen/html/header.html index 731e1a5d..ca5b0ff0 100644 --- a/documentation/Doxygen/html/header.html +++ b/documentation/Doxygen/html/header.html @@ -52,4 +52,4 @@
- \ No newline at end of file + From da8d1d9e9f58a8aaca47c9145cb2a17e21ba63b5 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Mon, 15 Nov 2021 16:35:25 +0000 Subject: [PATCH 13/30] Code review changes to profilerConfig.cmake.in --- profilerConfig.cmake.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/profilerConfig.cmake.in b/profilerConfig.cmake.in index c8509c00..ffadfd1a 100644 --- a/profilerConfig.cmake.in +++ b/profilerConfig.cmake.in @@ -1,2 +1,6 @@ +# Package configuration file used by the configure_package_config_file command +# in the root CMakeLists.txt file. This allows downstreams to use imported +# targets (i.e. find_package()) + @PACKAGE_INIT@ include( "${CMAKE_CURRENT_LIST_DIR}/profilerTargets.cmake" ) From bbfee39705de74b6c3cfc7f08e6f42aca26043f4 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Mon, 15 Nov 2021 17:00:16 +0000 Subject: [PATCH 14/30] Code review changes to tests --- LICENSE => LICENCE | 0 tests/CMakeLists.txt | 2 -- tests/hello_test.cpp | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) rename LICENSE => LICENCE (100%) diff --git a/LICENSE b/LICENCE similarity index 100% rename from LICENSE rename to LICENCE diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 212abd2d..b2c01f38 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,5 +10,3 @@ function(add_unit_test test_name cpp_file) endfunction() add_unit_test(hello_test hello_test.cpp) - - diff --git a/tests/hello_test.cpp b/tests/hello_test.cpp index 67eb5520..7d88001c 100644 --- a/tests/hello_test.cpp +++ b/tests/hello_test.cpp @@ -3,8 +3,8 @@ The file LICENCE, distributed with this code, contains details of the terms under which the code may be used. -------------------------------------------------------------------------------- - Description - A basic unit test example using GTest + Description: + A basic unit test example using GoogleTest \*----------------------------------------------------------------------------*/ #include From f20b2f77699841b116fe19f06882f5f374e1d4d3 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Mon, 15 Nov 2021 17:00:33 +0000 Subject: [PATCH 15/30] Code review changes to src/CMakeLists.txt --- src/CMakeLists.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ab5d7aac..63f8845f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,20 +1,31 @@ +# File includes functionality to compile source into a shared library and set +# up installation of the lib and header files upon build and install. +# TODO - Generalise this for multiple libs + +# Include helper functions for creating config files. include(CMakePackageConfigHelpers) +# Add files source files to library add_library(${CMAKE_PROJECT_NAME} SHARED profiler.h ) +# Link library to and external libs (also use project warnings and options) target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE project_warnings project_options) +# Set the properties of the library including, the version and language. Also +# set which header files are to be public and installed, this can be useful +# when limiting access to the internal workings of the library with the install. set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES SOVERSION ${SOVERSION} VERSION ${VERSION} LINKER_LANGUAGE CXX PUBLIC_HEADER "profiler.h") -install(TARGETS ${CMAKE_PROJECT_NAME} EXPORT "${CMAKE_PROJECT_NAME}Targets" +# Set up installation rules for the library. +install(TARGETS ${CMAKE_PROJECT_NAME} EXPORT "${CMAKE_PROJECT_NAME}Targets" LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT "${CMAKE_PROJECT_NAME}_RunTime" NAMELINK_COMPONENT "${CMAKE_PROJECT_NAME}_Development" From ad10b648a461fc22c01c0aa3f6f1770bb14457f9 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:23:58 +0000 Subject: [PATCH 16/30] Review changes to CMakeLists.txt file --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f1700f3..8ea79443 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Set the minimum version of CMake required by the build system. cmake_minimum_required(VERSION 3.13 FATAL_ERROR) -# Include file containing in source build prevention. +# Include file containing in-source build prevention. include(cmake/PreventInSourceBuilds.cmake) # Set project name and the languages required to build the project and a @@ -9,8 +9,8 @@ include(cmake/PreventInSourceBuilds.cmake) project(profiler LANGUAGES CXX DESCRIPTION "Met Office profiler") -# Set project versioning -# TODO - Move this to the project setting above, requires a few other changes. +# Set project versioning. +# TODO - Issue #12 Move versioning to the project settings above. set(SOVERSION 0) set(VERSION 0.1.0) @@ -36,7 +36,7 @@ include(cmake/TestingSetup.cmake) # All below is for installation and creation of *.cmake files for use with the # find_package cmake function. -# TODO - Move all below to file in cmake directory. +# 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} From e11c50944c0d46a7b50b59fb6ea8ba726351e2d8 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:24:47 +0000 Subject: [PATCH 17/30] Review changes to README.md file --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf146664..23a2168b 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ Profiler for scientific code on HPC platforms. ### Requirements -- C++17 compatible compiler +- 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 +- GCC versions: 9.2.0, 10.2.0. ### Testing Framework and Documentation From 566b18570a614a1efd474f50c676a9b34fa2a583 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:26:49 +0000 Subject: [PATCH 18/30] Review changes to cmake/CompilerWarnings.cmake file --- cmake/CompilerWarnings.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index 470af4e2..650ff1a5 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -1,7 +1,7 @@ # Contains a function for setting up the appropriate warnings for # different compilers and build settings. function(set_project_warnings project_name) - # Create option for forcing errors for all warnings + # Create option for forcing errors for all warnings. option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) # Create option to turn on sanitizers. @@ -10,7 +10,7 @@ function(set_project_warnings project_name) set(CLANG_WARNINGS # All warnings (actually not all warnings obviously) -Wall - # More warnings (should be used on none legacy code) + # More warnings (should be used on non-legacy code) -Wextra # Warn the user if a variable declaration shadows one from a parent context -Wshadow @@ -35,11 +35,11 @@ function(set_project_warnings project_name) -Wnull-dereference # Warn if float is implicit promoted to double -Wdouble-promotion - # Warn on security issues around functions that format output (ie printf) + # Warn on security issues around functions that format output (i.e. 'printf') -Wformat=2 ) - # Set warnings as errors if requested (Recommended during development/debug) + # Set warnings as errors if requested (recommended during development/debug) if (WARNINGS_AS_ERRORS) set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) endif () From 87e368e122a78695ae0d0b65b6654aba00786255 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:30:35 +0000 Subject: [PATCH 19/30] Review changes to cmake/Doxygen.cmake file --- cmake/Doxygen.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/Doxygen.cmake b/cmake/Doxygen.cmake index d1d7709f..1073127a 100644 --- a/cmake/Doxygen.cmake +++ b/cmake/Doxygen.cmake @@ -1,5 +1,5 @@ -# This file sets up the options for the Doxygen generation of API documentation -# available options for CMake Doxygen integration can be found here: +# This file sets up the options for the Doxygen generation of API documentation. +# Available options for CMake Doxygen integration can be found here: # https://cmake.org/cmake/help/latest/module/FindDoxygen.html function(enable_doxygen) option(ENABLE_DOXYGEN "Enable doxygen doc builds of source" ON) @@ -24,13 +24,13 @@ function(enable_doxygen) set(DOXYGEN_HTML_HEADER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/header.html) set(DOXYGEN_HTML_FOOTER ${PROJECT_SOURCE_DIR}/documentation/Doxygen/html/footer.html) - # Find the Doxygen application install (requires dot) + # Find the Doxygen application install (requires "dot" tool). find_package(Doxygen REQUIRED dot) # Set up Doxygen build with source directory and additional pages. doxygen_add_docs(doxygen-docs ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/documentation/Doxygen ALL) - # Set up installation destination + # Set up installation destination. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/docs) endif () endfunction() From 1d9624d41289601ded953b5cf5967be3c9c3d434 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:31:47 +0000 Subject: [PATCH 20/30] Review changes to cmake/PreventInSourceBuilds.cmake file --- cmake/PreventInSourceBuilds.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/PreventInSourceBuilds.cmake b/cmake/PreventInSourceBuilds.cmake index 862807e6..9309d992 100644 --- a/cmake/PreventInSourceBuilds.cmake +++ b/cmake/PreventInSourceBuilds.cmake @@ -1,7 +1,6 @@ -# # This function will prevent in-source builds function(AssureOutOfSourceBuilds) - # Make sure the user doesn't perform in source builds by tricking + # Make sure the user doesn't perform in-source builds by tricking # the build system through the use of symlinks get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) From b66f0145da3ac9423d26738db6213cbf7977dbe4 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:33:58 +0000 Subject: [PATCH 21/30] Review changes to cmake/StandardProjectSettings.cmake file --- cmake/StandardProjectSettings.cmake | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 8ed819ea..31e2e003 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -1,10 +1,10 @@ # Some basic project settings for defaults such as build type and installation -# prefix +# prefix. -# Set C++ standard compliance +# Set C++ standard compliance. set(CMAKE_CXX_STANDARD 17) -# Set a default build type if none was specified +# Set a default build type if none was specified. if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.") set(CMAKE_BUILD_TYPE @@ -15,7 +15,7 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS # These build type options set the listed compiler options. - # These are CMake default flags for C++ + # These are CMake default flags for C++. "Debug" # -g "Release" # -O3 -DNDEBUG "MinSizeRel" # -Os -DNDEBUG @@ -23,7 +23,7 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) ) endif () -# Generate compile_commands.json to make it easier to work with Clang-based tools +# Generate compile_commands.json to make it easier to work with Clang-based tools. set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Interprocedural optimisation is useful for improving program performance through @@ -44,7 +44,7 @@ if (ENABLE_IPO) endif () endif () -#Set default install location to be in build directory rather than /usr/bin etc. -if(${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) +# Set default install location to be in build directory rather than /usr/bin etc. +if (${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "..." FORCE) -endif() +endif () From 089dc977c1b75022762b723860ae591d1f946c85 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:35:14 +0000 Subject: [PATCH 22/30] Review changes to documentation/Doxygen/Profiler.md file --- documentation/Doxygen/Profiler.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/Doxygen/Profiler.md b/documentation/Doxygen/Profiler.md index 29fad23c..dc4e5a00 100644 --- a/documentation/Doxygen/Profiler.md +++ b/documentation/Doxygen/Profiler.md @@ -15,6 +15,7 @@ and Productivity (POP) Standard Metrics for Parallel Performance Analysis. ## Load Balance {#lb} + ~~~~~~~~~~~~~~~~~~~~~~~cpp class A { private: @@ -33,5 +34,6 @@ class A { ~~~~~~~~~~~~~~~~~~~~~~~ ## Communication Efficiency {#comme} + TBD \ No newline at end of file From e67775b6ebc4e26ee9201e07fbacebd915dbbc25 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:37:51 +0000 Subject: [PATCH 23/30] Review changes to src/CMakeLists.txt file --- src/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 63f8845f..15e21414 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,16 +1,16 @@ # File includes functionality to compile source into a shared library and set # up installation of the lib and header files upon build and install. -# TODO - Generalise this for multiple libs +# TODO - Issue #14 - Generalise build for multiple libs # Include helper functions for creating config files. include(CMakePackageConfigHelpers) -# Add files source files to library +# Add files source files to library. add_library(${CMAKE_PROJECT_NAME} SHARED profiler.h ) -# Link library to and external libs (also use project warnings and options) +# Link library to and external libs (also use project warnings and options). target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE project_warnings project_options) From c916bb19acf6a488ec71490a5974e7680bd3e318 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:38:42 +0000 Subject: [PATCH 24/30] Review changes to profilerConfig.cmake.in file --- profilerConfig.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profilerConfig.cmake.in b/profilerConfig.cmake.in index ffadfd1a..cba7c43c 100644 --- a/profilerConfig.cmake.in +++ b/profilerConfig.cmake.in @@ -1,6 +1,6 @@ # Package configuration file used by the configure_package_config_file command # in the root CMakeLists.txt file. This allows downstreams to use imported -# targets (i.e. find_package()) +# targets (i.e. find_package()). @PACKAGE_INIT@ include( "${CMAKE_CURRENT_LIST_DIR}/profilerTargets.cmake" ) From ad19090b3b561e36bfea1206cb27fada8680dfef Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 15:55:28 +0000 Subject: [PATCH 25/30] Review changes to tests/hello_test.cpp file --- tests/hello_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/hello_test.cpp b/tests/hello_test.cpp index 7d88001c..17c6d54f 100644 --- a/tests/hello_test.cpp +++ b/tests/hello_test.cpp @@ -4,7 +4,7 @@ under which the code may be used. -------------------------------------------------------------------------------- Description: - A basic unit test example using GoogleTest + A basic unit test example using GoogleTest. \*----------------------------------------------------------------------------*/ #include From 2e2804f4261a6d3989b8b1ae5e7bc430ef7ee07f Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 16:18:10 +0000 Subject: [PATCH 26/30] Review changes to tests/CMakeLists.txt file --- tests/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b2c01f38..bd951754 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,4 @@ +# Function to simplify adding unit-tests function(add_unit_test test_name cpp_file) add_executable(${test_name} ${cpp_file}) target_link_libraries(${test_name} @@ -9,4 +10,6 @@ function(add_unit_test test_name cpp_file) gtest_discover_tests(${test_name}) endfunction() +# List of unit-tests added to CTest. Add a line calling the 'add_unit_test' +# function to add an additional file of tests. add_unit_test(hello_test hello_test.cpp) From 01b65d9379eb85c466885d5a5087744628198211 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 16:46:54 +0000 Subject: [PATCH 27/30] Review changes to .gitignore file --- .gitignore | 51 ++++----------------------------------------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 85158e05..3ee4c074 100644 --- a/.gitignore +++ b/.gitignore @@ -114,48 +114,11 @@ flycheck_*.el # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle Build Tool -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. -# Uncomment if using. -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr +.idea/ # CMake cmake-build-*/ -# MongoDB Explorer plugin -.idea/**/mongoSettings.xml - # File-based project format *.iws @@ -168,21 +131,12 @@ out/ # JIRA plugin atlassian-ide-plugin.xml -# Cursive Clojure plugin -.idea/replstate.xml - # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties -# Editor-based Rest Client -.idea/httpRequests - -# Android Studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - ### Vim template # Swap [._]*.s[a-v][a-z] @@ -215,3 +169,6 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake _deps + +### Build directory +build/ From cf57ec670c74530ffb8acebbca0bc1f149888e99 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 16:49:49 +0000 Subject: [PATCH 28/30] Review changes to src/CMakeLists.txt file --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 15e21414..6f23c776 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ # File includes functionality to compile source into a shared library and set # up installation of the lib and header files upon build and install. -# TODO - Issue #14 - Generalise build for multiple libs +# TODO - Issue #14 - Generalise build for multiple libs. # Include helper functions for creating config files. include(CMakePackageConfigHelpers) From 7f1f892f75e8fe3cc3a66946668fd566a5bb6471 Mon Sep 17 00:00:00 2001 From: andrewcoughtrie <24609575+andrewcoughtrie@users.noreply.github.com> Date: Tue, 30 Nov 2021 16:49:56 +0000 Subject: [PATCH 29/30] Review changes to documentation/Doxygen/Profiler.md file --- documentation/Doxygen/Profiler.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/documentation/Doxygen/Profiler.md b/documentation/Doxygen/Profiler.md index dc4e5a00..d1cccf27 100644 --- a/documentation/Doxygen/Profiler.md +++ b/documentation/Doxygen/Profiler.md @@ -35,5 +35,4 @@ class A { ## Communication Efficiency {#comme} -TBD - \ No newline at end of file +TBD \ No newline at end of file From be078f7027c5c429caa9f5a4b24f382b9303b518 Mon Sep 17 00:00:00 2001 From: TeranIvy Date: Tue, 30 Nov 2021 17:00:34 +0000 Subject: [PATCH 30/30] PR #1: Updated changelog for merge to master --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0513e9ff..16954847 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.