将 Makefile 转换为 CMakeLists.txt
Posted
技术标签:
【中文标题】将 Makefile 转换为 CMakeLists.txt【英文标题】:Converting Makefile to CMakeLists.txt 【发布时间】:2013-08-04 22:30:57 【问题描述】:我正在使用具有自己的库的开发板。我已经在上面安装了 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($ENVROS_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】:来源: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)
【讨论】:
以上是关于将 Makefile 转换为 CMakeLists.txt的主要内容,如果未能解决你的问题,请参考以下文章
[forward] cmake, CMakeLists.txt梳理
将编译器命令行转换为 Casablanca Rest SDK 的 CMakeLists.txt