-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
156 lines (133 loc) · 5.54 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
####################################################################################################
# CMakeLists file for NN
# Generated by Gianluca Elia
# 2023-05-31
####################################################################################################
####################################################################################################
# basic project config
cmake_minimum_required(VERSION 3.12)
set(project_name "nn.ar")
set(dest_dir ${project_name})
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(CMakePrintHelpers)
####################################################################################################
# load modules
include(SuperColliderServerPlugin RESULT_VARIABLE server_plugin_found)
if(NOT server_plugin_found)
message(FATAL_ERROR "Could not find server plugin functions module")
endif()
include(SuperColliderCompilerConfig RESULT_VARIABLE compiler_config_found)
if(NOT compiler_config_found)
message(FATAL_ERROR "Could not find compiler config module")
endif()
# Windows - puts redistributable DLLs in install directory
include(InstallRequiredSystemLibraries)
sc_check_sc_path("${SC_PATH}")
message(STATUS "Found SuperCollider: ${SC_PATH}")
set(SC_PATH "${SC_PATH}" CACHE PATH
"Path to SuperCollider source. Relative paths are treated as relative to this script" FORCE)
include("${SC_PATH}/SCVersion.txt")
message(STATUS "Building plugins for SuperCollider version: ${SC_VERSION}")
# set project here to avoid SCVersion.txt clobbering our version info
project(${project_name})
sc_do_initial_compiler_config() # do after setting project so compiler ID is available
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR NOT CMAKE_INSTALL_PREFIX)
message(WARNING "No install prefix provided, defaulting to $BUILD_DIR/install")
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install prefix" FORCE)
endif()
message(STATUS "Install directory set to: ${CMAKE_INSTALL_PREFIX}")
####################################################################################################
# options
option(SUPERNOVA "Build plugins for supernova" ON)
option(SCSYNTH "Build plugins for scsynth" ON)
option(NATIVE "Optimize for native architecture" OFF)
option(STRICT "Use strict warning flags" OFF)
option(NOVA_SIMD "Build plugins with nova-simd support." ON)
option(SYSTEM_TORCH "Use system-installed torch (and don't copy shared libraries)" OFF)
set(TORCH_PATH "" CACHE STRING "Path to libtorch")
####################################################################################################
# include libraries
if (NOVA_SIMD)
add_definitions(-DNOVA_SIMD)
include_directories(${SC_PATH}/external_libraries/nova-simd)
endif()
if (${SYSTEM_TORCH})
find_package(Torch REQUIRED)
else()
# find torch
message(STATUS "Torch install path: ${TORCH_PATH}")
if ("${TORCH_PATH}" STREQUAL "")
message(FATAL_ERROR "TORCH_PATH required but not provided")
endif()
if (NOT EXISTS "${TORCH_PATH}")
message(FATAL_ERROR "TORCH_PATH '${TORCH_PATH}' does not exist")
endif()
# on some systems it still finds systemwide torch if we don't set prefix_path
set(CMAKE_PREFIX_PATH ${TORCH_PATH})
find_package(Torch REQUIRED PATHS "${TORCH_PATH}" NO_DEFAULT_PATH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
# copy shared libs
set(TORCH_SO)
if (LINUX)
file(GLOB TORCH_SO
"${TORCH_INSTALL_PREFIX}/lib/libtorch.so"
"${TORCH_INSTALL_PREFIX}/lib/libtorch_cpu.so"
"${TORCH_INSTALL_PREFIX}/lib/libc10.so"
"${TORCH_INSTALL_PREFIX}/lib/libgomp*"
)
set(CMAKE_INSTALL_RPATH "$ORIGIN/ignore")
elseif (APPLE)
file(GLOB TORCH_SO
"${TORCH_INSTALL_PREFIX}/lib/libtorch.dylib"
"${TORCH_INSTALL_PREFIX}/lib/libtorch_cpu.dylib"
"${TORCH_INSTALL_PREFIX}/lib/libc10.dylib"
"${TORCH_INSTALL_PREFIX}/lib/libomp*"
)
set(CMAKE_INSTALL_RPATH "@loader_path/ignore")
elseif (MSVC)
file(GLOB TORCH_SO "${TORCH_INSTALL_PREFIX}/lib/*.dll")
endif()
install(FILES ${TORCH_SO} DESTINATION "${dest_dir}/ignore")
endif()
message(STATUS "Torch libs: ${TORCH_LIBRARIES}")
message(STATUS "Torch shared libraries to be copied:")
foreach(so ${TORCH_SO})
message(STATUS "> ${so}")
endforeach()
####################################################################################################
# Begin target NNUGens
set(NNUGens_cpp_files
plugins/NNModel/cpp/NNUGens.cpp
plugins/NNModel/cpp/NNModel.cpp
plugins/NNModel/cpp/NNModelCmd.cpp
plugins/NNModel/cpp/backend/backend.cpp
plugins/NNModel/cpp/backend/parsing_utils.cpp
)
set(NNUGens_sc_files
plugins/NNModel/sc/NN.sc
plugins/NNModel/sc/NN_nrt.sc
plugins/NNModel/sc/NNModel.sc
plugins/NNModel/sc/NNUGens.sc
plugins/NNModel/sc/platformUtils.sc
)
set(NNUGens_schelp_files
plugins/NNModel/schelp/NNModel.schelp
plugins/NNModel/schelp/NNModelMethod.schelp
plugins/NNModel/schelp/NN.schelp
)
sc_add_server_plugin(
"${dest_dir}" # desination directory
"NNUGens" # target name
"${NNUGens_cpp_files}"
"${NNUGens_sc_files}"
"${NNUGens_schelp_files}"
"${TORCH_LIBRARIES}"
)
# End target NNModel
####################################################################################################
####################################################################################################
# END PLUGIN TARGET DEFINITION
####################################################################################################
message(STATUS "Generating plugin targets done")