-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
109 lines (93 loc) · 4.03 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
# ----------------------------------------------------------------------------
# Project metadata
# ----------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.28)
project(NEML2 VERSION 1.4.0 LANGUAGES CXX)
# ----------------------------------------------------------------------------
# Policy
# ----------------------------------------------------------------------------
# FindPython should return the first matching Python
if(POLICY CMP0094)
cmake_policy(SET CMP0094 NEW)
endif()
# Suppress the warning related to the new policy on fetch content's timestamp
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
# Suppress the warning related to the new policy on FindPythonXXX
if(POLICY CMP0148)
cmake_policy(SET CMP0148 NEW)
endif()
# ----------------------------------------------------------------------------
# Project-level settings, options, and flags
# ----------------------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH ${NEML2_SOURCE_DIR}/cmake/Modules) # CMake modules and macros
set(CMAKE_CXX_FLAGS_COVERAGE "-O0 -fprofile-arcs -ftest-coverage" CACHE STRING "Flags used by C++ compiler during coverage builds." FORCE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(NEML2_TESTS ON CACHE BOOL "Build NEML2 tests")
set(NEML2_RUNNER OFF CACHE BOOL "Build a simple runner for benchmarking, profiling, debugging, etc.")
set(NEML2_PYBIND OFF CACHE BOOL "Build NEML2 Python bindings")
set(NEML2_DOC OFF CACHE BOOL "Build NEML2 documentation (html)")
set(NEML2_CLANG_TIDY OFF CACHE BOOL "Enable clang-tidy linting")
set(NEML2_CLANG_TIDY_PATH "clang-tidy" CACHE STRING "Path to the clang-tidy executable")
# ----------------------------------------------------------------------------
# Dependencies and 3rd party packages
# ----------------------------------------------------------------------------
set(PYTORCH_VERSION "2.2.2")
set(DOXYGEN_VERSION "1.10.0")
set(DOXYGEN_AWESOME_VERSION "2.3.2")
set(PYBIND11_VERSION "2.12.0")
set(WASP_VERSION "c8c9ce4259115973f147e345608450d87dc390c4")
set(HIT_VERSION "2b56209d3f1a1c5f0bede15a3e13981b599a5f91")
set(CATCH2_VERSION "3.5.4")
set(GPERFTOOLS_VERSION "2.15")
set(ARGPARSE_VERSION "3.0")
include(NEML2Dependencies)
# ----------------------------------------------------------------------------
# PyTorch ships libraries with or without CXX11 ABI
# ----------------------------------------------------------------------------
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI})
# ----------------------------------------------------------------------------
# For relocatable install
# ----------------------------------------------------------------------------
if(UNIX AND APPLE)
set(EXEC_DIR "@loader_path")
elseif(UNIX AND NOT APPLE)
set(EXEC_DIR "$ORIGIN")
endif()
# ----------------------------------------------------------------------------
# Build types
# ----------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" "Coverage")
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(FATAL_ERROR "Build type Coverage must use gcc/g++ as the compiler")
endif()
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)
configure_file(scripts/coverage.sh.in ${NEML2_BINARY_DIR}/scripts/coverage.sh)
endif()
# ----------------------------------------------------------------------------
# Subdirectories
# ----------------------------------------------------------------------------
# base neml2 library
add_subdirectory(src/neml2)
# tests
if(NEML2_TESTS)
add_subdirectory(tests)
endif()
# runner
if(NEML2_RUNNER)
add_subdirectory(runner)
endif()
# Python bindings
if(NEML2_PYBIND)
add_subdirectory(python)
endif()
# Documentation
if(NEML2_DOC)
add_subdirectory(doc)
endif()