12.2.2 : Le CMakeLists.txt

On commence par définir notre projet :
1
2
project(CUFFT_HDF5)
cmake_minimum_required(VERSION 3.0)


Il faut utiliser le CMAKE_PREFIX_PATH et non le CMAKE_MODULE_PATH pour une raison qui m'échappe :
1
set(CMAKE_PREFIX_PATH "$ENV{NVHPC_CMAKE_MODULES}")


Donc on utilise HOSTUTILS pour les includes
1
find_package(NVHPC REQUIRED COMPONENTS HOSTUTILS thrust MATH CUDA)


Ensuite, on cherche HDF5 :
1
2
3
4
5
6
7
8
9
find_package(HDF5 COMPONENTS C CXX REQUIRED)

include_directories(${HDF5_INCLUDE_DIRS})
message(STATUS "HDF5_CXX_LIBRARIES = ${HDF5_CXX_LIBRARIES}")

#With nvhpc-22-7
if(DEFINED ENV{NVCPP})
	message(STATUS "Use nvc++ compiler at $ENV{NVCPP}")
	set(CMAKE_CXX_COMPILER $ENV{NVCPP})


On ajoute quelques flags de compilation (le fameux -stdpar, une option d'optimisation basique, les warnings et l'activation de C++17 noteOn pourrait activer C++20 avec g++, mais nvc++ râle avec HDF5 qui n'est pas encore completement compatible C++20) :
1
2
3
4
5
6
	set(CMAKE_CXX_FLAGS "-stdpar=gpu -O2 -Wall -std=c++17")
else()
	message(FATAL_ERROR "Cannot use a default compiler because we are mixing CURAND and -stdpar=gpu")
endif()

add_subdirectory(src)


Le CMakeLists.txt complet :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
project(CUFFT_HDF5)
cmake_minimum_required(VERSION 3.0)

set(CMAKE_PREFIX_PATH "$ENV{NVHPC_CMAKE_MODULES}")
find_package(NVHPC REQUIRED COMPONENTS HOSTUTILS thrust MATH CUDA)
find_package(HDF5 COMPONENTS C CXX REQUIRED)

include_directories(${HDF5_INCLUDE_DIRS})
message(STATUS "HDF5_CXX_LIBRARIES = ${HDF5_CXX_LIBRARIES}")

#With nvhpc-22-7
if(DEFINED ENV{NVCPP})
	message(STATUS "Use nvc++ compiler at $ENV{NVCPP}")
	set(CMAKE_CXX_COMPILER $ENV{NVCPP})
	set(CMAKE_CXX_FLAGS "-stdpar=gpu -O2 -Wall -std=c++17")
else()
	message(FATAL_ERROR "Cannot use a default compiler because we are mixing CURAND and -stdpar=gpu")
endif()

add_subdirectory(src)


Le fichier CMakeLists.txt est disponible ici.