128 lines
3.4 KiB
CMake
128 lines
3.4 KiB
CMake
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)
|
|
|
|
# ========================================================
|
|
# 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
|
|
src/XmlRpcServer.cpp
|
|
src/XmlRpcServerConnection.cpp
|
|
src/XmlRpcServerMethod.cpp
|
|
src/XmlRpcSocket.cpp
|
|
src/XmlRpcSource.cpp
|
|
src/XmlRpcUtil.cpp
|
|
src/XmlRpcValue.cpp
|
|
)
|
|
|
|
## Target include directories
|
|
target_include_directories(robot_xmlrpcpp
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE: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}
|
|
)
|
|
|
|
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 ---
|
|
install(EXPORT robot_xmlrpcpp-targets
|
|
FILE robot_xmlrpcpp-targets.cmake
|
|
NAMESPACE robot_xmlrpcpp::
|
|
DESTINATION lib/cmake/robot_xmlrpcpp
|
|
)
|
|
endif()
|