将Makefile转换为CMakeLists.txt

时间:2013-08-04 22:30:57

标签: c++ linux makefile cmake ros

我正在使用一个拥有自己的库的开发板。我已在其上安装了ROS,现在我需要通过将其库包含在包的CMakeLists.txt中来使用发布/订阅。我还要注意,我使用Eclipse进行编译,因此CMakeLists.txt就是这种形式。这是我想在CMakeLists.txt中使用的硬件库的Makefile:

DIR=$(shell pwd)/../

INCS = -I.\
        -I$(DIR) \
        -I$(DIR)/hardware \
        -I$(DIR)/hardware/environment \
        -I$(DIR)/hardware/environment/cores \
        -I$(DIR)/hardware/environment/cores/environment \
        -I$(DIR)/hardware/environment/variants \
        -I$(DIR)/hardware/environment/variants/sunxi \
        -I$(DIR)/libraries \
        -I$(DIR)/libraries/Serial \
        -I$(DIR)/libraries/SPI \
    -I$(DIR)/libraries/Wire \
    -I$(DIR)/libraries/LiquidCrystal \
    -I$(DIR)/Basibos/include LIBS=../libenvironment.a TARGET=../output/test

OBJS = BasibosAnaProgram

all: 
    @mkdir -p $(TARGET)
    for i in $(OBJS); do echo "$(CXX) $(INCS) $$i.cpp -o $(TARGET)/$$i $(LIBS)"; done
    @for i in $(OBJS); do $(CXX) $(INCS) $$i.cpp -o $(TARGET)/$$i $(LIBS); done

clean:
    @for i in $(OBJS); do rm -f $(TARGET)/$$i; done

以下是应该包含Makefile的示例CMakeLists.txt:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_init()

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

rosbuild_add_library(${PROJECT_NAME} src/Basibos.cpp)
rosbuild_add_library(${PROJECT_NAME} src/HedefeGitme.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Konum.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Robot.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Sonar.cpp)
rosbuild_add_library(${PROJECT_NAME} src/Zaman.cpp)
rosbuild_add_library(${PROJECT_NAME} src/XMLAyiklayici.cpp)

rosbuild_add_executable(srctest RobotKontrol.cpp)

target_link_libraries(srctest ${PROJECT_NAME})

我被困住了,没有帮助就无法前进。任何帮助将非常感激。提前致谢

1 个答案:

答案 0 :(得分:1)

来源:http://www.ros.org/wiki/rosbuild/CMakeLists

您必须以下列方式添加源文件:

rosbuild_add_library(XmlRpc 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)