-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
120 lines (101 loc) · 3.83 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# cmake 3.22 is necessary to have FindCUDAToolkit.cmake
# actually find cublas library when using nvc++ compiler (from nvhpc
# package)
cmake_minimum_required(VERSION 3.18)
#
# check if we want to apply cmake policy CMP0104, i.e.
# raise an error if CUDA_ARCHITECTURES is empty, when using
# nvc++ compiler
#
message("Using CMake version ${CMAKE_VERSION}")
if(${CMAKE_VERSION} VERSION_LESS "3.18.0")
message("Using cmake policy CMP0104 OLD")
cmake_policy(SET CMP0104 OLD)
else()
message("Using cmake policy CMP0104 NEW")
cmake_policy(SET CMP0104 NEW)
endif()
project(cuda-proj-tmpl LANGUAGES CXX C)
if (CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC")
if(${CMAKE_VERSION} VERSION_LESS "3.22.0")
message(FATAL_ERROR "NVHPC requires cmake version >= 3.22.0")
endif()
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
# custom cmake macros location
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cuda")
# Prevent from build in source tree
include(preventBuildInSource)
# Init build type: Release, Debug, ...
include(initBuildType)
# useful for debugging cmake
include(print_target_properties)
# a simple macro to build executable avoiding copy paste
#include(build_macro)
# always export compile commands database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#####################################################################
enable_language(CUDA)
# FindCUDAToolkit.cmake is able to correctly find cuda library
# either when using nvcc from cuda toolkit or nvc++ from nvhpc
# only in cmake 3.22.0
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.22.0" )
message("Using CUDAToolkit macros")
find_package(CUDAToolkit REQUIRED)
else()
message("Using CUDALibs macros")
find_package(CUDALibs REQUIRED COMPONENTS CUBLAS)
endif()
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD 11)
endif()
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
# other third party libraries
find_package(OpenMP)
#find_package(OpenGL)
#find_package(GLUT)
# we also need extra stuff to make sure compile flags are correctly
# passed to nvcc / host compiler
include(protect_nvcc_flags)
include(protect_pthread_flag)
##########################################################
##########################################################
##########################################################
##########################################################
# build some executable
add_subdirectory(src)
# Testing
#enable_testing()
#-------------------------------------------------------------------#
# Configuration summary
#-------------------------------------------------------------------#
message("//===================================================")
message("// ${PROJECT_NAME} build configuration:")
message("// ${PROJECT_NAME} version : ${PROJECT_VERSION}")
message("//===================================================")
message(" CMake version : ${CMAKE_VERSION}")
if (NOT CMAKE_BUILD_TYPE)
message(" CMake build type : NOT SET !")
else()
message(" CMake build type : ${CMAKE_BUILD_TYPE}")
endif()
message(" CUDA compiler ID : ${CMAKE_CUDA_COMPILER_ID}")
message(" CUDA compiler Version : ${CMAKE_CUDA_COMPILER_VERSION}")
message(" C++ Compiler : ${CMAKE_CXX_COMPILER_ID} "
"${CMAKE_CXX_COMPILER_VERSION} "
"${CMAKE_CXX_COMPILER_WRAPPER}")
message(" ${CMAKE_CXX_COMPILER}")
message(" CXX STANDARD : ${CMAKE_CXX_STANDARD}")
message(" CUDA CXX STANDARD : ${CMAKE_CUDA_STANDARD}")
message(" CUDA Compiler : ${CMAKE_CUDA_COMPILER}")
message(" CUDA Compiler exec : ${CUDA_NVCC_EXECUTABLE}")
message(" CUDA Compile flags : ${CMAKE_CUDA_FLAGS}")
message("")
message(" OpenMP compile flags : ${OpenMP_CXX_FLAGS}")
message("")
#message(" Thrid party libraries")
#message(" OpenGL found : ${OPENGL_FOUND}")