-
Notifications
You must be signed in to change notification settings - Fork 149
Native CMake integration #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # 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
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # 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
|
||||||||||||||||||||||||||
| 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
AI
Mar 31, 2026
There was a problem hiding this comment.
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).
| 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
AI
Mar 31, 2026
There was a problem hiding this comment.
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.
| +6 −6 | .gitignore | |
| +16 −1 | README.md | |
| + − | docs/images/simai_dingtalk.jpg | |
| + − | docs/images/simai_wechat.jpg | |
| +23 −2 | simulation/CMakeLists.txt | |
| +1 −1 | simulation/src/applications/CMakeLists.txt |
There was a problem hiding this comment.
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-gwill also apply to Release unless overridden). Preferadd_compile_options/target_compile_optionsand make debug info conditional on the build type so Release builds aren’t forced to include-g.