-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
117 lines (92 loc) · 3.34 KB
/
CMakeLists.txt
File metadata and controls
117 lines (92 loc) · 3.34 KB
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
cmake_minimum_required(VERSION 3.28)
set(CMAKE_CUDA_ARCHITECTURES 86) # For RTX 3060
project(NeuralNetwork LANGUAGES CXX CUDA) # Add CUDA here
# ------------------------------------------------------------------
# Configuration
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_STANDARD 17) # Add CUDA standard
set(CMAKE_CUDA_STANDARD_REQUIRED ON) # Enforce it
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
enable_language(CUDA)
# Default to Debug build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()
# ------------------------------------------------------------------
# Paths
set(NN_RESOURCE_DIR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/resources/fonts")
# ------------------------------------------------------------------
# Dependencies
include(FetchContent)
FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 3.0.1
GIT_SHALLOW ON
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_Declare(nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.12.0
GIT_SHALLOW ON
SYSTEM
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(SFML nlohmann_json)
# ------------------------------------------------------------------
# Main library
# Add both C++ and CUDA sources
file(GLOB_RECURSE NN_SOURCES CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cu" # Include CUDA source files
)
add_library(NeuralNetwork STATIC ${NN_SOURCES})
set_target_properties(NeuralNetwork PROPERTIES POSITION_INDEPENDENT_CODE ON)
# Enable separable compilation for CUDA files
set_target_properties(NeuralNetwork PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_RESOLVE_DEVICE_SYMBOLS ON # <--- important for static libs
)
target_include_directories(NeuralNetwork
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_definitions(NeuralNetwork
PRIVATE "RESOURCE_DIR=\"${NN_RESOURCE_DIR_PATH}\""
)
find_package(CUDAToolkit REQUIRED)
target_link_libraries(NeuralNetwork
PUBLIC
SFML::Graphics
SFML::Window
SFML::System
nlohmann_json::nlohmann_json
CUDA::cudart
)
target_compile_options(NeuralNetwork PRIVATE -Wall -Wextra -Wpedantic)
# ------------------------------------------------------------------
# Tests
option(BUILD_NN_TESTS "Build NeuralNetwork tests" OFF)
if(BUILD_NN_TESTS)
enable_testing()
include(CTest)
file(GLOB TEST_SOURCES CONFIGURE_DEPENDS tests/*.cpp)
if(TEST_SOURCES)
foreach(test_file ${TEST_SOURCES})
get_filename_component(test_name "${test_file}" NAME_WE)
add_executable(${test_name} ${test_file})
target_link_libraries(${test_name} PRIVATE NeuralNetwork)
target_include_directories(${test_name} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
add_test(NAME ${test_name} COMMAND ${test_name})
endforeach()
else()
message(WARNING "No test sources found in tests/ directory.")
endif()
endif()
# ------------------------------------------------------------------
# Install
install(TARGETS NeuralNetwork ARCHIVE DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)