catkin_make

This commit is contained in:
2025-12-31 15:34:02 +07:00
parent b64702260f
commit bb14979b8a
21 changed files with 137 additions and 91 deletions

View File

@@ -1,14 +1,67 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.0.2)
# ========================================================
# Dual-mode CMakeLists.txt: Supports both Catkin and Standalone CMake
# ========================================================
# Detect if building with Catkin
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
set(BUILDING_WITH_CATKIN TRUE)
message(STATUS "Building robot_xmlrpcpp with Catkin")
else()
set(BUILDING_WITH_CATKIN FALSE)
message(STATUS "Building robot_xmlrpcpp with Standalone CMake")
endif()
project(robot_xmlrpcpp)
## Compile as C++17
add_compile_options(-std=c++17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -fPIC)
# ========================================================
# Find Packages
# ========================================================
if(BUILDING_WITH_CATKIN)
## Find catkin macros and libraries
find_package(catkin REQUIRED)
endif()
## System dependencies are found with CMake's conventions
find_package(console_bridge REQUIRED)
# ========================================================
# Catkin specific configuration
# ========================================================
if(BUILDING_WITH_CATKIN)
## The catkin_package macro generates cmake config files for your package
catkin_package(
INCLUDE_DIRS include
LIBRARIES robot_xmlrpcpp
CATKIN_DEPENDS
DEPENDS console_bridge
)
endif()
###########
## Build ##
###########
## Specify additional locations of header files
include_directories(
include
${console_bridge_INCLUDE_DIRS}
)
if(BUILDING_WITH_CATKIN)
include_directories(${catkin_INCLUDE_DIRS})
endif()
## Declare a C++ library
add_library(robot_xmlrpcpp
src/XmlRpcClient.cpp
src/XmlRpcDispatch.cpp
@@ -21,33 +74,54 @@ add_library(robot_xmlrpcpp
src/XmlRpcValue.cpp
)
## Target include directories
target_include_directories(robot_xmlrpcpp
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
$<INSTALL_INTERFACE:include>
)
# --- Cài đặt thư viện vào hệ thống khi chạy make install ---
install(TARGETS robot_xmlrpcpp
EXPORT robot_xmlrpcpp-targets
ARCHIVE DESTINATION lib # Thư viện tĩnh .a
LIBRARY DESTINATION lib # Thư viện động .so
RUNTIME DESTINATION bin # File thực thi (nếu có)
INCLUDES DESTINATION include # Cài đặt include
## Add cmake target dependencies of the library
if(BUILDING_WITH_CATKIN)
add_dependencies(robot_xmlrpcpp ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
endif()
## Specify libraries to link a library or executable target against
target_link_libraries(robot_xmlrpcpp
${console_bridge_LIBRARIES}
)
install(
if(BUILDING_WITH_CATKIN)
target_link_libraries(robot_xmlrpcpp ${catkin_LIBRARIES})
endif()
## Compiler flags
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(robot_xmlrpcpp PRIVATE -Wall -Wextra -Wpedantic -fPIC -Wno-unused-parameter)
endif()
# ========================================================
# Installation (Standalone CMake only)
# ========================================================
if(NOT BUILDING_WITH_CATKIN)
install(TARGETS robot_xmlrpcpp
EXPORT robot_xmlrpcpp-targets
ARCHIVE DESTINATION lib # Thư viện tĩnh .a
LIBRARY DESTINATION lib # Thư viện động .so
RUNTIME DESTINATION bin # File thực thi (nếu có)
INCLUDES DESTINATION include # Cài đặt include
)
install(
DIRECTORY include/
DESTINATION include/
)
)
# --- Xuất export set robot_xmlrpcpp-targets thành file CMake module ---
# --- Tạo file lib/cmake/robot_xmlrpcpp/robot_xmlrpcpp-targets.cmake ---
# --- File này chứa cấu hình giúp project khác có thể dùng ---
# --- Find_package(robot_xmlrpcpp REQUIRED) ---
# --- Target_link_libraries(my_app PRIVATE robot_xmlrpcpp::robot_xmlrpcpp) ---
install(EXPORT robot_xmlrpcpp-targets
FILE robot_xmlrpcpp-targets.cmake
NAMESPACE robot_xmlrpcpp::
DESTINATION lib/cmake/robot_xmlrpcpp
)
# --- Xuất export set robot_xmlrpcpp-targets thành file CMake module ---
install(EXPORT robot_xmlrpcpp-targets
FILE robot_xmlrpcpp-targets.cmake
NAMESPACE robot_xmlrpcpp::
DESTINATION lib/cmake/robot_xmlrpcpp
)
endif()