0

Suppose a CMake file with two targets libA and libCUDA. Moreover, there is an external library libExt, which shall be linked against libA. libExt is a header-only library and requires C++20 support. libCUDA has source .cu files and the most recent nvcc compilers does only suppport C++17. Is it possible to use a single CMakeList.txt file to compile libA with C++20 support, libCUDA with C++17 support and finally link both together?

Felix Crazzolara
  • 982
  • 9
  • 24
  • Just as it is possible to use Fortran, Pascal, C, and C++ together, it is likewise possible to use C++11, C++14, C++17, and C++20 together. – Eljay Jun 07 '22 at 22:20
  • Yes, it is possible to use different C++ standards in different targets in a single CMake project. Check [that question](https://stackoverflow.com/questions/10851247/how-do-i-activate-c-11-in-cmake) and choose any answer from it which uses `target_*` command. E.g. [that one](https://stackoverflow.com/a/30251215/3440745). – Tsyvarev Jun 07 '22 at 22:22
  • `target_compile_features(target_a PRIVATE cxx_std_17)`, see [documentation](https://cmake.org/cmake/help/latest/command/target_compile_features.html) – firmament Jun 08 '22 at 21:37

0 Answers0