Skip to content

Commit

Permalink
cmt-20240921-1: +CMakeList.txt
Browse files Browse the repository at this point in the history
+CMakeList.txt
  • Loading branch information
nicewang committed Sep 20, 2024
1 parent f4c759c commit 4b9ae61
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*.a
*.so
*.dylib
*.dll
*.dll
**/build/
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.10)
project(MyProject)

# Set C++ 11 standard
set(CMAKE_CXX_STANDARD 11)

# Add subdirectories and compile separately
add_subdirectory(monte_carlo_tree_search)
add_subdirectory(rapidly_exploring_random_tree)

# Clean all
add_custom_target(clean_all
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target clean
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Robot Path Planning
* [Monte Carlo Tree Search](monte_carlo_tree_search/README.md)
* [Rapidly Exploring Random Tree](rapidly_exploring_random_tree/README.md)
* [Rapidly Exploring Random Tree (RRT)](rapidly_exploring_random_tree/README.md)
48 changes: 48 additions & 0 deletions monte_carlo_tree_search/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.10)
project(mcts_project)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-Wall")

# Load configs from config.properties
file(READ ${CMAKE_CURRENT_LIST_DIR}/config.properties CONFIG_CONTENT)

string(REGEX MATCH "CONFIG_GRID_SIZE=[0-9]+" GRID_SIZE_MATCH ${CONFIG_CONTENT})
string(REGEX MATCH "CONFIG_GOAL_X=[0-9]+" GOAL_X_MATCH ${CONFIG_CONTENT})
string(REGEX MATCH "CONFIG_GOAL_Y=[0-9]+" GOAL_Y_MATCH ${CONFIG_CONTENT})
string(REGEX MATCH "CONFIG_MAX_SIM_STEPS=[0-9]+" MAX_SIM_STEPS_MATCH ${CONFIG_CONTENT})
string(REGEX MATCH "CONFIG_C=[0-9.]+" CONFIG_C_MATCH ${CONFIG_CONTENT})

# config values
string(REPLACE "CONFIG_GRID_SIZE=" "" CONFIG_GRID_SIZE ${GRID_SIZE_MATCH})
string(REPLACE "CONFIG_GOAL_X=" "" CONFIG_GOAL_X ${GOAL_X_MATCH})
string(REPLACE "CONFIG_GOAL_Y=" "" CONFIG_GOAL_Y ${GOAL_Y_MATCH})
string(REPLACE "CONFIG_MAX_SIM_STEPS=" "" CONFIG_MAX_SIM_STEPS ${MAX_SIM_STEPS_MATCH})
string(REPLACE "CONFIG_C=" "" CONFIG_C ${CONFIG_C_MATCH})

# compile options
add_compile_definitions(
CONFIG_GRID_SIZE=${CONFIG_GRID_SIZE}
CONFIG_GOAL_X=${CONFIG_GOAL_X}
CONFIG_GOAL_Y=${CONFIG_GOAL_Y}
CONFIG_MAX_SIM_STEPS=${CONFIG_MAX_SIM_STEPS}
CONFIG_C=${CONFIG_C}
)

# source
set(SRC
src/main.cpp
src/mcts.cpp
src/state.cpp
)

# header
include_directories(include)

# executable file
add_executable(mcts.so ${SRC})

# clean
add_custom_target(clean_mcts
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/mcts.so
)
37 changes: 37 additions & 0 deletions rapidly_exploring_random_tree/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.10)
project(rrt_project)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-Wall")

# Set dir of include, src and obj
set(INCDIR ${CMAKE_SOURCE_DIR}/include)
set(SRCDIR ${CMAKE_SOURCE_DIR}/src)
set(OBJDIR ${CMAKE_BINARY_DIR}/obj)

# Set obj files and src files
set(SRCFILES ${CMAKE_CURRENT_LIST_DIR}/src/rrt.cpp ${CMAKE_CURRENT_LIST_DIR}/src/main.cpp)
set(OBJFILES ${OBJDIR}/rrt.o ${OBJDIR}/main.o)

# Include Dir
include_directories(${INCDIR})

# Add an object library to control the generation of object files
add_library(rrt_objects OBJECT ${SRCFILES})

# Set the output directory to the obj folder
set_target_properties(rrt_objects PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${OBJDIR}
LIBRARY_OUTPUT_DIRECTORY ${OBJDIR}
RUNTIME_OUTPUT_DIRECTORY ${OBJDIR}
)

# executable file
add_executable(rrt.so $<TARGET_OBJECTS:rrt_objects>)

# clean
add_custom_target(clean_rrt
COMMAND ${CMAKE_COMMAND} -E remove_directory ${OBJDIR}
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/rrt.so
)

2 changes: 1 addition & 1 deletion rapidly_exploring_random_tree/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## Rapidly Exploring Random Tree
## Rapidly Exploring Random Tree (RRT)

0 comments on commit 4b9ae61

Please sign in to comment.