diff --git a/Makefile b/Makefile index e10cc45..23af4f0 100644 --- a/Makefile +++ b/Makefile @@ -18,21 +18,11 @@ REPLACE_CMD = $(BASHCMD) $(BASH_SCRIPT_DIR)/replace.sh CLANG_TIDY_CMD = $(BASHCMD) $(BASH_SCRIPT_DIR)/clang-tidy.sh CLANG_FORMAT_CMD = $(BASHCMD) $(BASH_SCRIPT_DIR)/clang-format.sh - CLANG_TIDY_CONFIG = $(SRC_DIR)/linter/.clang-tidy CLANG_FORMAT_STYLE = $(SRC_DIR)/linter/.clang-format -# COMPILE_COMMANDS_FILE = compile_commands.json -# ifeq ($(wildcard $(DEBUG_DIR)/$(COMPILE_COMMANDS_FILE)),) -# ifeq ($(wildcard $(RELEASE_DIR)/$(COMPILE_COMMANDS_FILE)),) -# $(info Neither $(DEBUG_DIR)/$(COMPILE_COMMANDS_FILE) nor $(RELEASE_DIR)/$(COMPILE_COMMANDS_FILE) exist. \ -# Run make debug or make release first.) -# else -# COMPILE_COMMANDS := $(RELEASE_DIR)/$(COMPILE_COMMANDS_FILE) -# endif -# else -# COMPILE_COMMANDS := $(DEBUG_DIR)/$(COMPILE_COMMANDS_FILE) -# endif +INCLUDE_LIBS_EXT = "/usr/include/eigen3 /usr/include/catch2 /usr/include/hdf5/serial" + all: debug release documentation @@ -64,7 +54,7 @@ documentation: linter: clang-tidy clang-format clang-tidy: - $(CLANG_TIDY_CMD) $(PROJECT_DIR) $(COMPILE_COMMANDS) $(CLANG_TIDY_CONFIG) $(SRC_DIR) $(CPP_STD) + $(CLANG_TIDY_CMD) $(BUIL_DIR) $(SRC_DIR) $(CLANG_TIDY_CONFIG) $(CPP_STD) $(INCLUDE_LIBS_EXT) clang-format: $(CLANG_FORMAT_CMD) $(CLANG_FORMAT_STYLE) $(SRC_DIR) diff --git a/dev/CMakeLists.txt b/dev/CMakeLists.txt index dbd83d3..0bff515 100644 --- a/dev/CMakeLists.txt +++ b/dev/CMakeLists.txt @@ -34,7 +34,9 @@ add_subdirectory(app) # Include tests add_subdirectory(tests) - # Set compile options for different build types set(CMAKE_CXX_FLAGS_DEBUG "-g3 -O0 -tr") -set(CMAKE_CXX_FLAGS_RELEASE "-O3") \ No newline at end of file +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + +# Write include dirs to a file +include(cmake/WriteIncludeDirs.cmake) \ No newline at end of file diff --git a/dev/app/src/main.cpp b/dev/app/src/main.cpp index ace9f84..f618a82 100644 --- a/dev/app/src/main.cpp +++ b/dev/app/src/main.cpp @@ -1,23 +1,21 @@ +#include +#include +#include + +#include #include #include #include #include -#include -#include - -#include -#include - namespace po = boost::program_options; namespace dpc = flash::data_processing::config; namespace tp = flash::types; po::variables_map loadCommandLineArguments(int argc, char* argv[]) { po::options_description desc("Allowed options"); - desc.add_options() - ("help,h", "produce help message") - ("config-file,i", po::value()->default_value("config.yaml"), "set path to a config.yaml"); + desc.add_options()("help,h", "produce help message")( + "config-file,i", po::value()->default_value("config.yaml"), "set path to a config.yaml"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -30,33 +28,30 @@ po::variables_map loadCommandLineArguments(int argc, char* argv[]) { return vm; } -dpc::Config setupConfigParameters(po::variables_map commandLineArguments){ - +dpc::Config setupConfigParameters(po::variables_map commandLineArguments) { auto configFile = commandLineArguments["config-file"].as(); std::cout << "Load configuration from " << configFile << std::endl; - try{ - + try { auto configNode = YAML::LoadFile(configFile); auto params = dpc::Config(configNode); params.validate(); return params; - - } catch (YAML::BadFile BF){ - std::cerr << "Flash is terminating: " << "Could not open " << configFile << std::endl; - } catch (dpc::InvalidKeyException IKE){ + + } catch (YAML::BadFile BF) { + std::cerr << "Flash is terminating: " + << "Could not open " << configFile << std::endl; + } catch (dpc::InvalidKeyException IKE) { std::cerr << "Flash is terminating: " << IKE.what() << std::endl; - } catch (dpc::MissingKeyException MKE){ + } catch (dpc::MissingKeyException MKE) { std::cerr << "Flash is terminating: " << MKE.what() << std::endl; - } catch (dpc::InvalidConfigurationException ICE){ + } catch (dpc::InvalidConfigurationException ICE) { std::cerr << "Flash is terminating: " << ICE.what() << std::endl; } - } int main(int argc, char* argv[]) { - auto commandLineArguments = loadCommandLineArguments(argc, argv); - auto configParameters = setupConfigParameters(commandLineArguments); + auto configParameters = setupConfigParameters(commandLineArguments); return 0; } diff --git a/dev/cmake/ConfigCatch2.cmake b/dev/cmake/ConfigCatch2.cmake index 0e3cfb3..bab7daf 100644 --- a/dev/cmake/ConfigCatch2.cmake +++ b/dev/cmake/ConfigCatch2.cmake @@ -17,4 +17,5 @@ # "Path to Catch2 include directory" # FORCE) -find_package(Catch2 REQUIRED) \ No newline at end of file +find_package(Catch2 REQUIRED) +include_directories(${CATCH3_INCLUDE_DIRS}) \ No newline at end of file diff --git a/dev/cmake/ConfigEigen.cmake b/dev/cmake/ConfigEigen.cmake index 6e793ed..e4de143 100644 --- a/dev/cmake/ConfigEigen.cmake +++ b/dev/cmake/ConfigEigen.cmake @@ -13,4 +13,5 @@ # # Optionally, include Armadillo headers if needed explicitly # include_directories(${ARMADILLO_INCLUDE_DIRS}) -find_package(Eigen3 REQUIRED) \ No newline at end of file +find_package(Eigen3 REQUIRED) +include_directories(${EIGEN3_INCLUDE_DIRS}) \ No newline at end of file diff --git a/dev/cmake/ConfigHDF5.cmake b/dev/cmake/ConfigHDF5.cmake index 41ed2d1..908c824 100644 --- a/dev/cmake/ConfigHDF5.cmake +++ b/dev/cmake/ConfigHDF5.cmake @@ -16,5 +16,4 @@ # FORCE) find_package(HDF5 REQUIRED COMPONENTS C CXX) - include_directories(${HDF5_INCLUDE_DIRS}) \ No newline at end of file diff --git a/dev/cmake/ConfigYamlCpp.cmake b/dev/cmake/ConfigYamlCpp.cmake index 28798db..fb5bc4c 100644 --- a/dev/cmake/ConfigYamlCpp.cmake +++ b/dev/cmake/ConfigYamlCpp.cmake @@ -27,4 +27,4 @@ # # FetchContent_MakeAvailable(some_dependency) find_package(yaml-cpp REQUIRED) - +include_directories(${YAML_CPP_INCLUDE_DIRS}) \ No newline at end of file diff --git a/dev/cmake/WriteIncludeDirs.cmake b/dev/cmake/WriteIncludeDirs.cmake new file mode 100644 index 0000000..64c327f --- /dev/null +++ b/dev/cmake/WriteIncludeDirs.cmake @@ -0,0 +1,13 @@ +# Get the list of include directories (e.g., target_include_directories or include_directories) +get_property(INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) + +# Specify the output file +set(OUTPUT_FILE "${CMAKE_BINARY_DIR}/include_paths.txt") + +# Open the file for writing +file(WRITE ${OUTPUT_FILE} "") + +# Iterate over the list of include directories and write each to the file +foreach(INCLUDE_DIR ${INCLUDE_DIRS}) + file(APPEND ${OUTPUT_FILE} "${INCLUDE_DIR}\n") +endforeach() \ No newline at end of file diff --git a/dev/libs/CMakeLists.txt b/dev/libs/CMakeLists.txt index 62975dc..f0fcacf 100644 --- a/dev/libs/CMakeLists.txt +++ b/dev/libs/CMakeLists.txt @@ -1,11 +1,8 @@ -# types -add_subdirectory(types) -# constants -add_subdirectory(constants) -# config -add_subdirectory(data_processing) -# electrons -add_subdirectory(electrons) + +add_subdirectory(types) +add_subdirectory(constants) +add_subdirectory(data_processing) +add_subdirectory(electrons) \ No newline at end of file diff --git a/dev/libs/constants/CMakeLists.txt b/dev/libs/constants/CMakeLists.txt index 2320e0e..f8d48cf 100644 --- a/dev/libs/constants/CMakeLists.txt +++ b/dev/libs/constants/CMakeLists.txt @@ -2,6 +2,7 @@ add_library(constants INTERFACE) -target_include_directories(constants INTERFACE - include +target_include_directories(constants + INTERFACE + include ) \ No newline at end of file diff --git a/dev/libs/data_processing/CMakeLists.txt b/dev/libs/data_processing/CMakeLists.txt index 8230736..9793b59 100644 --- a/dev/libs/data_processing/CMakeLists.txt +++ b/dev/libs/data_processing/CMakeLists.txt @@ -12,7 +12,7 @@ target_link_libraries(data_processing target_include_directories(data_processing PUBLIC - ${CMAKE_SOURCE_DIR}/include + include PRIVATE src ) \ No newline at end of file diff --git a/scripts/bash/clang-tidy.sh b/scripts/bash/clang-tidy.sh index 20edddd..ff03c38 100644 --- a/scripts/bash/clang-tidy.sh +++ b/scripts/bash/clang-tidy.sh @@ -1,30 +1,50 @@ #!/bin/bash -PROJECT_DIR=$1 -COMPILE_COMMANDS=$2 + + +BUILD_DIR=$1 +SRC_DIR=$2 CONFIG_FILE=$3 -SRC_DIR=$4 -CPP_STD=$5 -NUMBER_OF_ARGUMENTS=5 +CPP_STD=$4 # Check if enough arguments are passed +NUMBER_OF_ARGUMENTS=5 if [ "$#" -ne ${NUMBER_OF_ARGUMENTS} ]; then - echo "Usage: $0 " + echo "Usage: $0 " exit 1 fi -# Check if compile_commands.json exists -if [ ! -f ${COMPILE_COMMANDS} ]; then - echo "${COMPILE_COMMANDS} not found!" - exit 1 -fi +# Find compile_commands.json in build dir +COMPILE_COMMANDS_FILE="compile_commands.json" +INCLUDE_PATHS_EXT_FILE="include_paths.txt" +BUILDS=$(find "${BUILD_DIR}" -maxdepth 1 -type d) +COMPILE_COMMANDS="" +INCLUDE_PATHS_EXT=() +for BUILD in ${BUILDS}; do + if [ -d "${BUILD}" ]; then + COMPILE_COMMANDS="${BUILD}/${COMPILE_COMMANDS_FILE}" + mapfile -t INCLUDE_PATHS_EXT < "${BUILD}/${INCLUDE_PATHS_EXT_FILE}" + echo "Running clang-tidy with ${COMPILE_COMMANDS}..." + fi +done +if [ -z ${COMPILE_COMMANDS} ]; then\ + echo "Could not find ${COMPILE_COMMANDS_FILE}. Exit..." + exit +fi + # Find all directories named "include" and generate the include string -INCLUDE_PATHS=$(find "$PROJECT_DIR" -type d -name "include" -print | awk '{printf "-I%s ", $0}') +INCLUDE_PATHS_INT=$(find "$SRC_DIR" -type d -name "include" -print) +INCLUDE_PATHS_LIST=("${INCLUDE_PATHS_EXT[@]}" "${INCLUDE_PATHS_INT[@]}") +INCLUDE_PATHS="" +for LIB in ${INCLUDE_PATHS_LIST[@]}; do + INCLUDE_PATHS+="-I${LIB} " +done + # Run clang-tidy for all cpp files for file in $(find ${SRC_DIR} -name '*.cpp'); do echo "Running clang-tidy on $file " - clang-tidy ${file} --config-file=${CONFIG_FILE} -- -std=${CPP_STD} ${INCLUDE_PATHS} "-I/usr/include/eigen3" "-I/usr/include/catch2" + clang-tidy ${file} --config-file=${CONFIG_FILE} -- -std=${CPP_STD} ${INCLUDE_PATHS} done