Skip to content

Latest commit

 

History

History
180 lines (122 loc) · 5.82 KB

README_building.md

File metadata and controls

180 lines (122 loc) · 5.82 KB

Build Instructions

A full build has different steps:

  1. Specifying the compiler using environment variables
  2. Configuring the project
  3. Building the project

For the subsequent builds, in case you change the source code, you only need to repeat the last step.

(1) Specify the compiler using environment variables

By default (if you don't set environment variables CC and CXX), the system default compiler will be used.

Conan and CMake use the environment variables CC and CXX to decide which compiler to use. So to avoid the conflict issues only specify the compilers using these variables.

CMake will detect which compiler was used to build each of the Conan targets. If you build all of your Conan targets with one compiler, and then build your CMake targets with a different compiler, the project may fail to build.

Commands for setting the compilers
  • Unix like OSs (GNU/Linux, MacOS, BSDs): Set your desired compiler (clang, gcc, etc):

    • Temporarily (only for the current shell)
      • clang CC=clang CXX=clang++
      • gcc CC=gcc CXX=g++
    • Permanent: Open ~/.bashrc using your text editor: gedit ~/.bashrc Add CC and CXX to point to the compilers: export CC=clang export CXX=clang++ Save and close the file.
  • Windows:

    • Permanent: Run one of the followings in PowerShell:
      • Visual Studio generator and compiler (cl) [Environment]::SetEnvironmentVariable("CC", "cl.exe", "User") [Environment]::SetEnvironmentVariable("CXX", "cl.exe", "User") refreshenv Set the architecture using vcvarsall: vcvarsall.bat x64
      • clang [Environment]::SetEnvironmentVariable("CC", "clang.exe", "User") [Environment]::SetEnvironmentVariable("CXX", "clang++.exe", "User") refreshenv
      • gcc [Environment]::SetEnvironmentVariable("CC", "gcc.exe", "User") [Environment]::SetEnvironmentVariable("CXX", "g++.exe", "User") refreshenv
    • Temporarily (only for the current shell): $Env:CC="clang.exe" $Env:CXX="clang++.exe"

(2) Configure your build

To configure the project, you could use cmake, or ccmake or cmake-gui. Each of them are explained in the following:

(2.a) Configuring via cmake:

With Cmake directly:

cmake -S . -B ./out/build

Cmake will automatically create the ./build folder if it does not exist, and it wil configure the project.

Instead, if you have CMake version 3.21+, you can use one of the configuration presets that are listed in the CmakePresets.json file.

cmake . --preset <configure-preset>
cmake --build

(2.b) Configuring via ccmake:

With the Cmake Curses Dialog Command Line tool:

ccmake -S . -B ./out/build

Once ccmake has finished setting up, press 'c' to configure the project, press 'g' to generate, and 'q' to quit.

(2.c) Configuring via cmake-gui:

To use the GUI of the cmake:

2.c.1) Open cmake-gui from the project directory:

cmake-gui .

2.c.2) Set the build directory:

build_dir

2.c.3) Configure the generator:

In cmake-gui, from the upper menu select Tools/Configure.

Warning: if you have set CC and CXX always choose the use default native compilers option. This picks CC and CXX. Don't change the compiler at this stage!

Windows - MinGW Makefiles

Choose MinGW Makefiles as the generator:

mingw
Windows - Visual Studio generator and compiler

You should have already set C and CXX to cl.exe.

Choose "Visual Studio 16 2019" as the generator:

default_vs
Windows - Visual Studio generator and Clang Compiler

You should have already set C and CXX to clang.exe and clang++.exe.

Choose "Visual Studio 16 2019" as the generator. To tell Visual studio to use clang-cl.exe:

  • If you use the LLVM that is shipped with Visual Studio: write ClangCl under "optional toolset to use".
visual_studio
  • If you use an external LLVM: write LLVM_v142 under "optional toolset to use".
visual_studio

2.c.4) Choose the Cmake options and then generate:

generate

(3) Build the project

Once you have selected all the options you would like to use, you can build the project (all targets):

cmake --build ./build

For Visual Studio, give the build configuration (Release, RelWithDeb, Debug, etc) like the following:

cmake --build ./build -- /p:configuration=Release

Running the tests

You can use the ninja test_suite or make test_suite command to run the Tx test suite with the tx CLI binary.

You can use the ctest command to run the tests.

cd ./build
ninja test_suite  # run the Tx test suite
ctest -C Debug    # cmake test driver for C++ code unit tests
ninja test        # also run ctest
cd ../