-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
74 lines (60 loc) · 2.27 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
#CMake minimum requirement
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
#Project name
set(project_name "CUDATemplate")#<TODO> change this to the name of your project
project(${project_name} LANGUAGES CXX C CUDA)
#toggle between building a shared or static library
option(MY_BUILD_SHARED_LIBS "Build as shared library" OFF)
#default build type is Release
if (CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
endif ()
# Direct all output to /bin directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
include(FetchContent)
# GoogleTest
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG eaf9a3fd77869cf95befb87455a2e2a2e85044ff
)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)
# Auto-detect GPU architecture
include("cmake/AutoDetectCudaArch.cmake")
# CUDA and C++ compiler flags
set(cxx_flags
$<$<CXX_COMPILER_ID:MSVC>:-D_SCL_SECURE_NO_WARNINGS /openmp /std:c++17> #<TODO> Add MSVC-specific compiler flags here
$<$<CXX_COMPILER_ID:GNU>:-Wall -m64 -fopenmp -O3 -std=c++17> #<TODO> Add GCC compiler flags here
$<$<CXX_COMPILER_ID:Clang>:-Wall -m64 -fopenmp -O3 -std=c++17> #<TODO> Add Clang compiler flags here
)
set(MSVC_XCOMPILER_FLAGS "/openmp /std:c++17")
set(cuda_flags
$<$<CXX_COMPILER_ID:GNU>:-Xcompiler -Wall -fopenmp -O3>
$<$<CXX_COMPILER_ID:Clang>:-Xcompiler -Wall -fopenmp -O3>
$<$<CXX_COMPILER_ID:MSVC>:-Xcompiler ${MSVC_XCOMPILER_FLAGS}>
-Xcudafe=--display_error_number
-lineinfo
--expt-extended-lambda
-use_fast_math
$<$<CXX_COMPILER_ID:GNU>:-O3>
--expt-relaxed-constexpr
-Xptxas -warn-spills -res-usage
--ptxas-options=-v
#-G
)
add_library(developer_flags INTERFACE)
target_compile_options(developer_flags INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>
$<$<COMPILE_LANGUAGE:CUDA>:${cuda_flags}>
)
target_include_directories(developer_flags INTERFACE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
target_compile_features(developer_flags INTERFACE cxx_std_17)
#OpenMP
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(developer_flags INTERFACE OpenMP::OpenMP_CXX)
endif()
enable_testing()
add_subdirectory(CUDALib)
add_subdirectory(CUDAExec)