-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
117 lines (97 loc) · 3.61 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
cmake_minimum_required(VERSION 3.16)
project(mace VERSION 1.0)
# -----------------------------------------------------------------------------
# CMake options - build arguments
# -----------------------------------------------------------------------------
option(USE_CUDA "Compile with CUDA support" OFF)
option(WITH_TESTS "Compile test suite" ON)
# -----------------------------------------------------------------------------
# Languages
# -----------------------------------------------------------------------------
# C++
set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Fortran
enable_language(Fortran)
set(CMAKE_Fortran_FORMAT FREE)
set(CMAKE_Fortran_STANDARD f2003)
# CUDA
if (USE_CUDA)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 17)
find_package(CUDA REQUIRED)
else ()
message(STATUS "Not using CUDA.")
endif ()
# -----------------------------------------------------------------------------
# Dependencies
# -----------------------------------------------------------------------------
# include LibTorch
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
# MPI
find_package(MPI REQUIRED)
# -----------------------------------------------------------------------------
# Our code
# -----------------------------------------------------------------------------
# C++ source files
set(MACE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
set(SOURCES src/neighbour_list.cpp src/mace.cpp src/mace_c_api.cpp)
# mace library: underlying C++ code
add_library(mace STATIC ${SOURCES})
target_include_directories(mace PUBLIC
# for compatibility with install setup
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# public headers
target_include_directories(mace PRIVATE ${MACE_SOURCE_DIR}) # private headers & implementation
target_link_libraries(mace PUBLIC "${TORCH_LIBRARIES}") # torch
# MACE Fortran module: interface only, needs MPI
add_library(mace_fortran INTERFACE)
target_sources(mace_fortran INTERFACE src/fortran/mace.f90)
target_include_directories(mace_fortran INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/src/fortran
${MPI_Fortran_INCLUDE_DIRS}
)
target_link_libraries(mace_fortran INTERFACE
mace
${MPI_Fortran_LIBRARIES}
)
# -----------------------------------------------------------------------------
# Tests & Examples
# -----------------------------------------------------------------------------
if (WITH_TESTS)
enable_testing()
# library for testing: internals are available to test code as well
add_library(mace_testing INTERFACE)
target_link_libraries(mace_testing INTERFACE mace)
target_include_directories(mace_testing INTERFACE ${MACE_SOURCE_DIR})
# tests
set(INSTALL_GTEST OFF) # see https://github.com/google/googletest/issues/2829
add_subdirectory(tests)
endif ()
# examples
add_subdirectory(examples)
# -----------------------------------------------------------------------------
# Installation & other settings
# -----------------------------------------------------------------------------
# Specify installation rules
# targets: libraries & executables
install(TARGETS mace
EXPORT maceTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install(FILES src/fortran/mace.f90 src/fortran/mace.stub.f90
DESTINATION include)
# CMake package: namespace & contents
install(EXPORT maceTargets
FILE maceTargets.cmake
NAMESPACE MACE::
DESTINATION cmake
)
install(FILES cmake/maceConfig.cmake cmake/maceConfigVersion.cmake
DESTINATION cmake)