Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
astra-sim-alibabacloud/build/simai_analytical/build/
astra-sim-alibabacloud/build/astra_ns3/build/
astra-sim-alibabacloud/extern/
astra-sim-alibabacloud/inputs/config/
!astra-sim-alibabacloud/inputs/config/SimAI.conf
bin/
results/
test/log/
*.log
.cur*
.DS_Store

**/build
**/cmake-cache
!astra-sim-alibabacloud/build
104 changes: 104 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# CMake requirement
cmake_minimum_required(VERSION 3.15)

# C++ requirement
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_definitions("-Wall -g")

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE)
endif()

Comment on lines +7 to +12
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using add_definitions("-Wall -g") injects flags globally (and -g will also apply to Release unless overridden). Prefer add_compile_options / target_compile_options and make debug info conditional on the build type so Release builds aren’t forced to include -g.

Suggested change
add_definitions("-Wall -g")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE)
endif()
add_compile_options(-Wall)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-g)
endif()

Copilot uses AI. Check for mistakes.
# Compiler requirement
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.3)
message(FATAL_ERROR "g++ (GNU) version should be greater than 5.3, but found ${CMAKE_CXX_COMPILER_VERSION}")
endif()
endif()

project(SimAI)

set(NS3_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ns-3-alibabacloud/simulation")
set(ASTRA_SIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim-alibabacloud/astra-sim")
set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(RESULT_DIR "${CMAKE_CURRENT_SOURCE_DIR}}/result")

# Create required directories
file(MAKE_DIRECTORY ${BUILD_DIR})
file(MAKE_DIRECTORY ${RESULT_DIR})
Comment on lines +22 to +29
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RESULT_DIR has a stray } in the path ("${CMAKE_CURRENT_SOURCE_DIR}}/result"), which will produce an invalid directory name and can break directory creation. Please fix the path string (and consider aligning the directory name with the repo’s existing results/ vs result/ conventions so outputs land in the intended ignored location).

Copilot uses AI. Check for mistakes.

# Option to clean build and result directories
option(CLEAN_BUILD "Clean build directory" OFF)
option(CLEAN_RESULT "Clean result directory" OFF)
option(BUILD_SIM "Build NS3 simulation" ON)
option(BUILD_ANALYTICAL "Build analytical" OFF)
option(BUILD_PHY "Build physical" OFF)

if(CLEAN_BUILD)
message(STATUS "Cleaning build directory: ${BUILD_DIR}")
file(REMOVE_RECURSE ${BUILD_DIR})
file(REMOVE_RECURSE "${NS3_DIR}/simulation/build")
file(REMOVE_RECURSE "${NS3_DIR}/simulation/cmake-cache")
Comment on lines +41 to +42
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLEAN_BUILD block references NS3_DIR, but this variable is never defined in this CMake file (only NS3_SRC_DIR is). This makes the clean operation incorrect and likely leaves stale ns-3 build artifacts behind (or removes the wrong path if NS3_DIR is set externally). Use the correct variable/path for the ns-3 build and cmake-cache directories.

Suggested change
file(REMOVE_RECURSE "${NS3_DIR}/simulation/build")
file(REMOVE_RECURSE "${NS3_DIR}/simulation/cmake-cache")
file(REMOVE_RECURSE "${NS3_SRC_DIR}/build")
file(REMOVE_RECURSE "${NS3_SRC_DIR}/cmake-cache")

Copilot uses AI. Check for mistakes.
file(MAKE_DIRECTORY ${BUILD_DIR})
endif()

Comment on lines +39 to +45
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing ${BUILD_DIR} (which is ${CMAKE_CURRENT_BINARY_DIR}) during the configure step is unsafe because it deletes the active build tree (including CMake’s own files) while CMake is running. If you want a “clean” option, prefer generating a separate custom target/script that runs outside the configure step, or only delete a dedicated subdirectory owned by this project (not the entire binary dir).

Suggested change
message(STATUS "Cleaning build directory: ${BUILD_DIR}")
file(REMOVE_RECURSE ${BUILD_DIR})
file(REMOVE_RECURSE "${NS3_DIR}/simulation/build")
file(REMOVE_RECURSE "${NS3_DIR}/simulation/cmake-cache")
file(MAKE_DIRECTORY ${BUILD_DIR})
endif()
message(STATUS "Cleaning NS3 simulation build directories")
file(REMOVE_RECURSE "${NS3_DIR}/simulation/build")
file(REMOVE_RECURSE "${NS3_DIR}/simulation/cmake-cache")
endif()

Copilot uses AI. Check for mistakes.
if(CLEAN_RESULT)
message(STATUS "Cleaning result directory: ${RESULT_DIR}")
file(REMOVE_RECURSE ${RESULT_DIR})
file(MAKE_DIRECTORY ${RESULT_DIR})
endif()

if(BUILD_SIM)
# AstraSim
add_subdirectory(astra-sim-alibabacloud/build/astra_ns3)

file(GLOB_RECURSE astra_sim_files CONFIGURE_DEPENDS "${ASTRA_SIM_DIR}/*")
list(FILTER astra_sim_files EXCLUDE REGEX "/network_frontend/")
foreach(file ${astra_sim_files})
string(REPLACE "${ASTRA_SIM_DIR}/" "astra-sim/" relative_path ${file})
get_filename_component(output_dir ${NS3_SRC_DIR}/src/applications/${relative_path} DIRECTORY)
file(MAKE_DIRECTORY ${output_dir})
configure_file(${file} ${NS3_SRC_DIR}/src/applications/${relative_path} COPYONLY)
endforeach()
Comment on lines +56 to +63
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file(GLOB_RECURSE ... "${ASTRA_SIM_DIR}/*") will also return directories by default, and the loop then calls configure_file(... COPYONLY) on each entry. Passing a directory to configure_file fails at configure time. Configure the glob to exclude directories (e.g., LIST_DIRECTORIES false) or filter out directories before copying.

Copilot uses AI. Check for mistakes.

file(GLOB scratch_files
CONFIGURE_DEPENDS
${ASTRA_SIM_DIR}/network_frontend/ns3/*)
foreach(file ${scratch_files})
get_filename_component(filename ${file} NAME)
configure_file(${file} ${NS3_SRC_DIR}/scratch/${filename} COPYONLY)
endforeach()

# NS3
string(TOLOWER ${CMAKE_BUILD_TYPE} build_type)
if (build_type STREQUAL "release")
set(NS3_ASSERT OFF CACHE BOOL "Override NS3_ASSERT" FORCE)
set(NS3_LOG OFF CACHE BOOL "Override NS3_LOG" FORCE)
endif ()
if (NOT DEFINED NS3_WARNINGS_AS_ERRORS)
set(NS3_WARNINGS_AS_ERRORS OFF CACHE BOOL "Override NS3_WARNINGS_AS_ERRORS" FORCE)
endif ()
if (NOT DEFINED NS3_MTP)
set(NS3_MTP ON CACHE BOOL "Override NS3_MTP" FORCE)
endif ()
add_subdirectory(${NS3_SRC_DIR} ${NS3_SRC_DIR}/cmake-cache)

# Link binaries
add_custom_target(create_ns3_symlink
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/bin"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"$<TARGET_FILE:scratch_AstraSimNetwork>"
"${CMAKE_CURRENT_SOURCE_DIR}/bin/SimAI_simulator"
DEPENDS scratch_AstraSimNetwork
COMMENT "Creating simulator symlink..."
)
endif()

if(BUILD_ANALYTICAL)
add_subdirectory(astra-sim-alibabacloud/build/simai_analytical)
endif()

if(BUILD_PHY)
add_subdirectory(astra-sim-alibabacloud/build/simai_phy)
endif()
4 changes: 3 additions & 1 deletion astra-sim-alibabacloud/build/astra_ns3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ cmake_minimum_required(VERSION 3.15)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_definitions("-Wall -g")
SET(CMAKE_BUILD_TYPE "Debug")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" FORCE)
endif()

# Compiler requirement
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down
Loading