-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
94 lines (83 loc) · 3 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
cmake_minimum_required(VERSION 3.25.2)
project(mastermind)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git log -1 --format=%cd --date=iso
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(
"${PROJECT_SOURCE_DIR}/mastermind_config.h.in"
"${PROJECT_SOURCE_DIR}/mastermind_config.h"
)
set(MASTERMIND_SOURCES_LIST
${PROJECT_SOURCE_DIR}/main.cpp
${PROJECT_SOURCE_DIR}/score.cpp
${PROJECT_SOURCE_DIR}/utils.cpp
)
add_executable(mastermind ${MASTERMIND_SOURCES_LIST})
target_include_directories(mastermind PUBLIC SYSTEM .)
set_target_properties(mastermind PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
)
target_compile_options(mastermind PRIVATE
-march=native
-fno-omit-frame-pointer
)
# https://github.com/anrieff/libcpuid to get CPU info like number of processors, L1 cache size, etc.
# On Ubuntu: sudo apt install cpuidtool libcpuid15 libcpuid-dev
find_library(LIBCPUID_LIBRARY NAMES libcpuid.so)
find_path(LIBCPUID_INCLUDE_DIR NAMES libcpuid)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBCPUID
FOUND_VAR LIBCPUID_FOUND
REQUIRED_VARS LIBCPUID_LIBRARY LIBCPUID_INCLUDE_DIR
)
if (LIBCPUID_FOUND AND NOT TARGET LIBCPUID)
add_library(LIBCPUID UNKNOWN IMPORTED)
set_target_properties(LIBCPUID PROPERTIES
IMPORTED_LOCATION "${LIBCPUID_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LIBCPUID_INCLUDE_DIR}/libcpuid"
)
target_link_libraries(mastermind PUBLIC LIBCPUID)
endif ()
include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.10.5/json.tar.xz)
FetchContent_MakeAvailable(json)
target_link_libraries(mastermind PRIVATE nlohmann_json::nlohmann_json)
include(CheckLanguage)
check_language(CUDA)
if (CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set_source_files_properties(${MASTERMIND_SOURCES_LIST} PROPERTIES LANGUAGE CUDA)
set_target_properties(mastermind PROPERTIES
CXX_STANDARD 20
CUDA_STANDARD 20
CUDA_STANDARD_REQUIRED ON
CUDA_SEPARABLE_COMPILATION ON
CUDA_ARCHITECTURES "86")
target_compile_options(mastermind PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:
--generate-line-info
--use_fast_math
--relocatable-device-code=true
--default-stream per-thread
-fno-omit-frame-pointer
--extended-lambda
-dc
--std=c++20
--forward-unknown-to-host-compiler -march=native
>)
endif ()