-
Notifications
You must be signed in to change notification settings - Fork 86
/
CMakeLists.txt
108 lines (100 loc) · 4.43 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
check_include_file_cxx(stdint.h HAVE_STDINT_H)
if(HAVE_STDINT_H)
add_definitions(-DHAVE_STDINT_H)
endif()
find_package(Boost REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIRS})
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(pybind11 CONFIG REQUIRED)
include_directories(${pybind11_INCLUDE_DIRS})
# we need CONFIG for debug mode in macOS
find_package(Protobuf CONFIG)
if(NOT Protobuf_FOUND)
find_package(Protobuf REQUIRED)
endif()
include_directories(${Protobuf_INCLUDE_DIRS})
# Check if C++-based ML frameworks are available
# Must do before build_lib (which adds examples/ subdirectory)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/model/libtensorflow)
message(STATUS "TensorFlow C library found, examples using libtensorflow are enabled")
set(NS3AI_LIBTENSORFLOW_EXAMPLES ON)
set(Libtensorflow_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/model/libtensorflow/include")
if(NOT EXISTS ${Libtensorflow_INCLUDE_DIR})
message(FATAL_ERROR "Include directory of TensorFlow C library does not exist")
endif()
set(Libtensorflow_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/model/libtensorflow/lib")
if(NOT EXISTS ${Libtensorflow_LIBRARY_DIR})
message(FATAL_ERROR "Library directory of TensorFlow C library does not exist")
else()
file(GLOB TensorFlow_LIBRARIES "${Libtensorflow_LIBRARY_DIR}/*.so" "${Libtensorflow_LIBRARY_DIR}/*.dylib")
endif()
else()
message(STATUS "TensorFlow C library not found, examples using libtensorflow are disabled")
set(NS3AI_LIBTENSORFLOW_EXAMPLES OFF)
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/model/libtorch)
message(STATUS "PyTorch C++ library found, examples using libtorch are enabled")
set(NS3AI_LIBTORCH_EXAMPLES ON)
set(Libtorch_INCLUDE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}/model/libtorch/include;${CMAKE_CURRENT_SOURCE_DIR}/model/libtorch/include/torch/csrc/api/include")
foreach(dir ${Libtorch_INCLUDE_DIRS})
if(NOT EXISTS ${dir})
message(FATAL_ERROR "Include directory ${dir} of PyTorch C++ library does not exist")
endif()
endforeach ()
set(Libtorch_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/model/libtorch/lib")
if(NOT EXISTS ${Libtorch_LIBRARY_DIR})
message(FATAL_ERROR "Library directory of PyTorch C++ library does not exist")
else()
file(GLOB Torch_LIBRARIES "${Libtorch_LIBRARY_DIR}/*.so" "${Libtorch_LIBRARY_DIR}/*.dylib")
endif()
else()
message(STATUS "PyTorch C++ library not found, examples using libtorch are disabled")
set(NS3AI_LIBTORCH_EXAMPLES OFF)
endif()
set(msg_interface_srcs )
set(msg_interface_hdrs model/msg-interface/ns3-ai-msg-interface.h)
set(gym_interface_srcs
model/gym-interface/cpp/ns3-ai-gym-interface.cc
model/gym-interface/cpp/ns3-ai-gym-env.cc
model/gym-interface/cpp/container.cc
model/gym-interface/cpp/spaces.cc
model/gym-interface/cpp/messages.pb.cc
)
set(gym_interface_hdrs
model/gym-interface/cpp/ns3-ai-gym-interface.h
model/gym-interface/cpp/ns3-ai-gym-env.h
model/gym-interface/cpp/container.h
model/gym-interface/cpp/spaces.h
)
build_lib(
LIBNAME ai
SOURCE_FILES ${msg_interface_srcs} ${gym_interface_srcs}
HEADER_FILES ${msg_interface_hdrs} ${gym_interface_hdrs}
LIBRARIES_TO_LINK ${libcore} protobuf
)
# protobuf_generate function is missing in some installations by package manager
check_function_exists(protobuf_generate protobuf_generate_exists)
if(${protobuf_generate_exists})
message(STATUS "protobuf_generate function found")
else()
message(STATUS "protobuf_generate function not found -> use a local copy from ${CMAKE_CURRENT_SOURCE_DIR}/protobuf-generate.cmake")
include(${CMAKE_CURRENT_SOURCE_DIR}/protobuf-generate.cmake)
endif()
# Compile proto files
add_library(proto-objects OBJECT "${CMAKE_CURRENT_SOURCE_DIR}/model/gym-interface/messages.proto")
protobuf_generate(
TARGET proto-objects
IMPORT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/model/gym-interface"
LANGUAGE cpp
PROTOC_OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/model/gym-interface/cpp"
)
protobuf_generate(
TARGET proto-objects
IMPORT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/model/gym-interface"
LANGUAGE python
PROTOC_OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/model/gym-interface/py"
)
add_dependencies(${libai} proto-objects)
# Build Gym msg binding module
add_subdirectory(model/gym-interface/py)