Skip to content

Commit ba417ce

Browse files
refactor CMakeLists.txt to support all three build modes
1 parent 2fd28fe commit ba417ce

1 file changed

Lines changed: 47 additions & 10 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ file(MAKE_DIRECTORY ${RESULT_DIR})
3737
option(CLEAN_BUILD "Clean build directory" OFF)
3838
option(CLEAN_RESULT "Clean result directory" OFF)
3939

40-
# Build types
41-
option(BUILD_SIM "Build NS3 simulation" OFF)
42-
option(BUILD_ANALYTICAL "Build analytical" OFF)
43-
option(BUILD_PHY "Build physical" OFF)
40+
# Build mode
41+
set(SIMAI_MODE "analytical" CACHE STRING "SimAI build mode")
42+
set_property(CACHE SIMAI_MODE PROPERTY STRINGS analytical ns3 phy)
43+
set(_valid_simai_modes analytical ns3 phy)
44+
list(FIND _valid_simai_modes "${SIMAI_MODE}" _simai_mode_index)
45+
if(_simai_mode_index EQUAL -1)
46+
message(FATAL_ERROR
47+
"Invalid SIMAI_MODE='${SIMAI_MODE}'. "
48+
"Expected one of: analytical, ns3, phy")
49+
endif()
4450

4551
# Other options
4652
option(SYS_ASSERTS "Enable assert() in all profile with -UNDEBUG" OFF)
@@ -102,7 +108,7 @@ if(SYS_ASSERTS)
102108
message(STATUS "Asserts enabled for all profiles.")
103109
endif()
104110

105-
if(BUILD_SIM)
111+
if(SIMAI_MODE STREQUAL "ns3")
106112
# AstraSim
107113
add_subdirectory(astra-sim-alibabacloud/build/astra_ns3)
108114

@@ -164,10 +170,41 @@ if(BUILD_SIM)
164170
)
165171
endif()
166172

167-
if(BUILD_ANALYTICAL)
168-
add_subdirectory(astra-sim-alibabacloud/build/simai_analytical)
169-
endif()
173+
elseif(SIMAI_MODE STREQUAL "analytical")
174+
set(USE_ANALYTICAL TRUE CACHE BOOL "Set analytical build" FORCE)
175+
176+
# Build AstraSim library
177+
add_subdirectory(astra-sim-alibabacloud AstraSim)
178+
179+
# Build analytical frontend
180+
add_subdirectory(astra-sim-alibabacloud/astra-sim/network_frontend/analytical simai_analytical)
181+
182+
# Link binaries
183+
add_custom_target(create_analytical_symlink ALL
184+
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/bin"
185+
COMMAND ${CMAKE_COMMAND} -E create_symlink
186+
"$<TARGET_FILE:SimAI_analytical>"
187+
"${CMAKE_CURRENT_SOURCE_DIR}/bin/SimAI_analytical"
188+
DEPENDS SimAI_analytical
189+
COMMENT "Creating SimAI_analytical symlink..."
190+
)endif()
170191

171-
if(BUILD_PHY)
172-
add_subdirectory(astra-sim-alibabacloud/build/simai_phy)
192+
elseif(SIMAI_MODE STREQUAL "phy")
193+
set(USE_RDMA TRUE CACHE BOOL "Set RDMA build" FORCE)
194+
195+
# Build AstraSim library
196+
add_subdirectory(astra-sim-alibabacloud AstraSim)
197+
198+
# Build phynet frontend
199+
add_subdirectory(astra-sim-alibabacloud/astra-sim/network_frontend/phynet simai_phynet)
200+
201+
# Link binaries
202+
add_custom_target(create_phy_symlink ALL
203+
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/bin"
204+
COMMAND ${CMAKE_COMMAND} -E create_symlink
205+
"$<TARGET_FILE:SimAI_phynet>"
206+
"${CMAKE_CURRENT_SOURCE_DIR}/bin/SimAI_phynet"
207+
DEPENDS SimAI_phynet
208+
COMMENT "Creating SimAI_phynet symlink..."
209+
)
173210
endif()

0 commit comments

Comments
 (0)