diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4776c23 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 # Use the latest stable tag + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files diff --git a/CMakeLists.txt b/CMakeLists.txt index 8828df5..f52865e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,38 @@ cmake_minimum_required(VERSION 3.14) -# Project name +# try to prevent modification of source directory +# note: some files may still be written before CMake can abort and need to be removed manually +if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) + message( + FATAL_ERROR + "In-source build not allowed. " + "Please create a new directory, preferably next to the source directory, and run CMake from there. " + "You may want to remove CMakeCache.txt and CMakeFiles/ which were created in the source directory." + ) +endif() + project(mirco VERSION 0.1.0) -# Check for out-of-source build -if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) - message(FATAL_ERROR "\nIn-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n\nTo clean-up, you may need to remove CMakeCache.txt and CMakeFiles from your source directory.") -endif() +# Print CMake version to screen +message(STATUS "Using CMake ${CMAKE_VERSION}") +# Enforce the C++ standard we are using and turn off compiler-specific extensions set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# We do not use C++ modules (yet). Turn off scanning to avoid issues with clang-tidy. +# If you want to add module support, this problem needs to be revisited. Our hope +# is that CMake and/or clang-tidy will be updated to handle modules better. +set(CMAKE_CXX_SCAN_FOR_MODULES OFF) + +# Ensure cmake setup the correct runtime path when installing +# see here for more information: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling +include(GNUInstallDirs) +set(CMAKE_SKIP_BUILD_RPATH FALSE) +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) +set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # Add libraries if(GTEST_IN_MIRCO) @@ -145,7 +169,7 @@ configure_package_config_file(cmake/mirco_libConfig.cmake.in install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mirco_libConfig.cmake - DESTINATION lib/cmake/mirco + DESTINATION lib/cmake/mirco ) install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ DESTINATION include/mirco FILES_MATCHING PATTERN "*.h") diff --git a/README.md b/README.md index 3be9cd2..ae4879d 100644 --- a/README.md +++ b/README.md @@ -22,18 +22,24 @@ cd mkdir git clone --recursive https://github.com/imcs-compsim/MIRCO.git ``` + where `` is some directory in your machine and `` will contain the `MIRCO` source code. If you have already cloned the repository using: + ```bash git clone https://github.com/imcs-compsim/MIRCO.git ``` + you can pull the submodules using: + ```bash cd git submodule update --init --recursive ``` + To update the submodules, you can use the following command from your source directory: + ```bash git submodule update --recursive --remote ``` @@ -41,33 +47,46 @@ git submodule update --recursive --remote ### Configure and build the code To create an out-of-source build, first create a build directory using: + ```bash cd mkdir ``` + where `` is the build directory. > Note: The exact location of `` is arbitrary, as long as it is _not_ a subdirectory of ``. Now, you have to navigate to the build directory and call the `do-configure` script in order to invoke `cmake`: + ```bash cd /do-configure ``` +Alternatively, you can use CMake presets: + +```bash +cd +cmake --preset= +``` + > **IMPORTANT** Make sure to set `Trilinos_DIR` to point to you Trilinos installation. Build the `mirco` executable in the build directory using: + ```bash cd make -j ``` + with `` specifying the number of processes used for compilation. The `mirco` executable will be created in the build directory. ### Run all tests You can run the tests from the build directory using: + ```bash ctest ``` @@ -75,9 +94,11 @@ ctest ### Run the code To run the code with an input file, use the following command in your build directory: + ```bash ./mirco /Input/ ``` + where `` is any input file in the prescribed format. ## How to cite MIRCO? diff --git a/create-mirco-python-venv b/create-mirco-python-venv old mode 100644 new mode 100755 index a5ffb39..c3a9f20 --- a/create-mirco-python-venv +++ b/create-mirco-python-venv @@ -1,16 +1,30 @@ #!/bin/bash +# Exit the script at the first failure +set -e + +if [ ! -f "./create-mirco-python-venv" ]; then + echo "Please run this script from the root directory of the repository." + exit 1 +fi + # Path to the python virtual environment. PYTHON_VENV="`dirname "$0"`/utilities/mirco-python-venv" # If the virtual environment already exists, delete it. if [ -d "$PYTHON_VENV" ]; then rm -Rf $PYTHON_VENV; fi +# Path to python +PYTHON_PATH=${1:-python3} + # Setup the virtual environment and source it. -python3 -m venv "${PYTHON_VENV}" +$PYTHON_PATH -m venv "${PYTHON_VENV}" source "${PYTHON_VENV}"/bin/activate # Install all the modules defined in requirements.txt. pip install --upgrade pip pip install wheel pip install -r requirements.txt + +# Install the pre-commit hooks. +pre-commit install diff --git a/requirements.txt b/requirements.txt index 65bf315..68af88f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ # Python modules that will be installed into the MIRCO python virtual environment -clang-format==14.0.0 \ No newline at end of file +clang-format==14.0.0 +pre-commit==3.5.0