How to Build the Project¶
Step-by-Step Instructions¶
Assuming you already have the project available locally and your Docker container is running with /workspace
set as the project root, follow these steps to build the project:
-
Navigate to the Project Root:
Ensure you are in the project root directory (i.e.,
/workspace
). You can verify this by running:It should display
/workspace
(the project root). -
Run the Build Script:
From the project root, execute the build script to configure and compile the project:
This script will:
- Create a build directory
- Change into the build directory.
- Run CMake to generate the build system.
- Invoke make to compile the source code into executables.
- Return you to the project root once the build is complete.
-
Run the Executables:
You can now run the executables using the
run
command from anywhere. For example:-
To generate vectors:
-
To compute the vector sum:
More details on properly using the executables are provided in the subsequent sections of this documentation. You can skip to the next page if not interested in the build process details.
-
In-Depth Build Process Explanation¶
After running the build script, a series of automated steps are performed behind the scenes to transform the source code into executable programs. Below is an in-depth explanation of what happens during the build process and how to use the run command.
Build Process Overview¶
-
Build Directory Creation:
The build script first checks for the existence of the
build/
directory in the project root. If it doesn’t exist, it creates it. This out-of-source build practice keeps all generated files separate from the source code, which simplifies cleanup and avoids polluting the source tree.scripts/buildProject.sh -
CMake Configuration:
-
Once inside the
build/
directory, the script runs the command -
CMake reads the
CMakeLists.txt
file located in the project root. This file specifies the project’s configuration:-
It sets the C++ standard to C++11 and enables common compiler flags like
-Wall
,-Wextra
, and-O3
for optimization. -
It defines where the executables will be placed (specifically, in
build/bin
).CMakelists.txt The absolute path (
BIN_DIR_ABS
) is later used in the run script. -
It locates and configures external dependencies such as yaml-cpp, HDF5, and GSL.
-
It defines the build targets (executables like
generateVectors
andvectorSum
) and links them with the required libraries. -
It configures a run script from a template (located in
commands/run.in
), replacing placeholders (such as the project root and the absolute path tobuild/bin
) with actual values. -
It ensures that both executables depend on the copy_run target, so that the run script is always copied when building the project.
-
-
-
Compilation with Make:
-
After CMake has successfully configured the project, the build script invokes make:
-
Make reads the generated Makefiles (created by CMake) and compiles all source files according to the defined rules. This step builds the executables and places them in the
build/bin
directory. - The custom target defined in CMake also ensures that the run script is copied to
/usr/local/bin
, so that it is globally accessible.
-