-
Notifications
You must be signed in to change notification settings - Fork 36
Guide: Alternative Build Procedures (CLion and VScode)
While instructions to build Tudatpy in a standard way (recommended) are found in the README file of the Tudatpy repository, some users might need (or prefer to have) alternative ways to build it. Within this wiki, we show how to do that with two IDEs: CLion and VScode.
Note
- [Windows Users ∩ CLion Users] In CLion, be sure to set WSL as your Toolchain in
File>Settings>Build, Execution, Deployment>Toolchains
.- [CLion Users] In CLion, the convention to set CMake arguments is to add them to
File>Settings>Build, Execution, Deployment>CMake Options
.
- Open CLion, create a new project from
File > New Project
and select the directory where your project is located (e.g./Users/<your_username>/CLionProjects/tudatpy
).
Note
To avoid issues with CLion, the directory of the project should correspond exactly to the cloned directory namedtudatpy
!
- Create a build profile in
File > Settings > Build, Execution, Deployment > CMake
. A build profile is a set of configuration settings you can use to build your application on a particular platform.
Note
The CMake configuration optionCMAKE_BUILD_TYPE
will be determined by the the build profile'sBuild type
entry. ARelease
configuration will suppress a significant amount of harmless warnings during compilation. Currently, with the move to a later version of boost, some warnings have cropped up that have either not been fixed in the source code, or have not been suppressed viatudat/cmake_modules/compiler.cmake
.
- Add the CMake configuration to the
CLion > Settings > Build, Execution, Deployment > CMake > CMake options
text box:
-DCMAKE_PREFIX_PATH=<CONDA_PREFIX>
-DCMAKE_CXX_STANDARD=14
-DBoost_NO_BOOST_CMAKE=ON
Note
- The
CONDA_PREFIX
may be determined by activating the environment installed in step 4 and printing its value:conda activate tudat-bundle && echo $CONDA_PREFIX
- The following line can also be edited if you wish to build tudatpy with its debug info (switching from
Release
toRelWithDebInfo
; >note thatDebug
is also available):-DCMAKE_BUILD_TYPE=RelWithDebInfo
[Optional] Add
-j<n>
toFile > Settings > Build, Execution, Deployment > CMake > Build options
to use multiple processors. It is >likely that if you use all of your processors, your build will freeze your PC indefinitely. It is recommended to start at-j2
and work your >way up with further builds, ensuring no unsaved work in the background.
- In the source tree on the left, right click the top level
CMakeLists.txt
thenLoad/Reload CMake Project
. Build > Build Project
- VSCode with the following extensions:
- CMake installed on your system (minimum version 3.19).
- Conda environment for managing dependencies.
- Make/Ninja installed based on your operating system for build generation.
-
Create the
CMakePresets.json
file in the root directory of your project. Use the following template with necessary adjustments (adjustments to be made are indicated by a "<---- CHANGE THIS" comment on each relevant line):
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"hidden": false,
"generator": "Unix Makefiles", // Set this based on the OS: "Unix Makefiles" for Linux/macOS, "Ninja" or "Visual Studio" for Windows
"binaryDir": "${sourceDir}/build", // Build directory
"cacheVariables": {
"CMAKE_PREFIX_PATH": "/path/to/your/conda/environment", // <--- CHANGE THIS: Set this to your conda environment or other toolchain path
"CMAKE_INSTALL_PREFIX": "/path/to/your/conda/environment", // <--- CHANGE THIS
"CMAKE_CXX_STANDARD": "14", // The C++ standard to use
"Boost_NO_BOOST_CMAKE": "ON", // Ensures that the system-installed Boost CMake files are not used
"CMAKE_BUILD_TYPE": "Release", // Default to Release build
"TUDAT_BUILD_TESTS": "ON" // Set to ON to build tests by default
}
},
{
"name": "debug",
"inherits": "default",
"description": "Debug build configuration",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug" // Use Debug mode for this preset
}
},
{
"name": "no-tests",
"inherits": "default",
"description": "Build without tests",
"cacheVariables": {
"TUDAT_BUILD_TESTS": "OFF" // Disable test building in this preset
}
}
],
"buildPresets": [
{
"name": "default",
"hidden": false,
"configurePreset": "default", // Use the default configuration preset
"jobs": 8, //<--- CHANGE THIS: Parallel build with N cores
"targets": [
"all" // Build the default target (usually all)
]
},
{
"name": "debug-build",
"configurePreset": "debug", // Use the debug configuration preset
"jobs": 8, //<--- CHANGE THIS: Parallel build with N cores
"targets": [
"all"
]
},
{
"name": "build-no-tests",
"configurePreset": "no-tests", // Use the no-tests configuration preset
"jobs": 8, //<--- CHANGE THIS: Parallel build with N cores
"targets": [
"all"
]
},
{
"name": "clean",
"configurePreset": "default",
"jobs": 8, //<--- CHANGE THIS: Parallel build with N cores
"targets": [
"clean" // Run the clean target
]
}
]
}
Note
CMAKE_PREFIX_PATH: CMAKE_PREFIX_PATH
is the same as CMAKE_INSTALL_PREFIX
and it is the same path as the defined above. if you are unsure, type conda activate tudat-bundle && echo $CONDA_PREFIX
in the terminal to get the right path. Defining it properly critical to ensure CMake can find the necessary libraries and dependencies.
-
Generator: Depending on your OS, the generator should be:
-
"Unix Makefiles"
for macOS and Linux. -
"Ninja"
for Windows (if Ninja is installed). -
"Visual Studio"
for Windows if using Visual Studio.
-
-
Parallel Jobs: The
jobs
key is used to specify the number of jobs for parallel builds. Set the number of cores to be used for the >build. -
Presets:
-
default
: Builds the project in Release mode with tests. -
debug
: Builds the project in Debug mode. -
no-tests
: Builds the project without tests. -
clean
: Cleans the build directory.
-
Warning
Quitting and reopening VSCode is necessary if you create the CMakePresets.json
file within VSCode. Otherwise, your presets won't load in the CMake extension.
- Open VSCode in your project directory.
- Open the Command Palette (
F1
orCtrl+Shift+P
) and run the commandCMake: Select Configure Preset
. - Choose one of the configure presets:
-
default
: for Release builds. -
debug
: for Debug builds. -
no-tests
: to skip building tests.
-
- Once configured, run the command
CMake: Select Build Preset
from the Command Palette, and choose one of the build presets:-
default
: to build the project. -
debug-build
: to build in Debug mode. -
build-no-tests
: to build without tests. -
clean
: to clean the build directory.
-
- To start the build, run
CMake: Build
from the Command Palette or use the build button in the status bar.
-
CMake Errors: If CMake cannot find dependencies, check that the
CMAKE_PREFIX_PATH
andCMAKE_INSTALL_PREFIX
are set correctly in theCMakePresets.json
file. -
Wrong Generator: If the build fails due to an unsupported generator, change the
"generator"
field in the preset to match your OS and toolchain.
That's all for this wiki. Have a nice coding!