Archive

Posts Tagged ‘GUN’

cmake常见问题

March 31st, 2009 No comments

CMake 是一个跨平台的自动化建构系统,它使用一个名为 CMakeLists.txt 的文件来描述构建过程,
可以产生标准的构建文件,如 Unix 的 Makefile 或Windows Visual C++ 的 projects/workspaces 。
文件 CMakeLists.txt 需要手工编写,也可以通过编写脚本进行半自动的生成。CMake 提供了比 autoconfig 更简洁的语法.

之前想用automake autoconf来管理项目,但是看了一天也没有搞明白是怎么回事。最后只好投奔cmake.

经过一天的努力终于把项目从Makefile移植到cmake. 在移植的过程中遇到了些问题,简单记录如下.

网上关于cmake的的资料比较少,官方网站上的资料也特别少,有好多看了还看不懂, 哎。

从网上找到一篇“Cmake Practice(cmake 实践)”国人Cjacker写的。可以从这不下载 http://www.scribd.com/doc/13774019/Cmake-Practicecmake-

1. 在cmake中通过EXEC_PROGRAM来调用命令行来取得一些参数. 比如你要想通过取得gtkmm一些头部文件和库的路径。
[code lang="C"]
pkg-config gtkmm --cflags --libs
[/code]

Use the EXEC_PROGRAM command and then use the CACHE option of the SET
command to save the output to a variable like GTK_PKG_FLAGS.  Then use
the SET command to add the value.  Something like this:

[code lang="C"]
IF(NOT GTK_PKG_FLAGS)
EXEC_PROGRAM(pkg-config ARGS --cflags --libs gtkmm
OUTPUT_VARIABLE GTK_PKG_FLAGS)
SET(GTK_PKG_FLAGS "${GTK_PKG_FLAGS}" CACHE STRING "GTK Flags")
ENDIF(NOT GTK_PKG_FLAGS)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GTK_PKG_FLAGS}")
[/code]

2. 通过execute_process来实现文件, 目录的拷贝
[code lang="C"]
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/path/to/www
${CMAKE_BINARY_DIR}/path/to/www)
[/code]

PS: EXECUTE_PROCESS 和 EXEC_PROGRAM 基本相同,  EXECUTE_PROCESS是用来替代EXEC_PROGRAM的。
参见:  http://www.cmake.org/pipermail/cmake/2006-February/008250.html

参考:  http://www.cmake.org/pipermail/cmake/2009-March/028299.html

3. 常用的几个内置变量

通过set语句可以自定义变量,然而,CMake还包含大量的内置变量,这些变量和自定义变量的用法没有区别,下面就列出一些常用的变量:

* CMAKE_C_COMPILER

指定C编译器,通常,CMake运行时能够自动检测C语言编译器。进行嵌入式系统开发时,通常需要设置此变量,指定交叉编译器。
* CMAKE_CXX_COMPILER

指定C++编译器
* CMAKE_C_FLAGS

指定编译C文件时编译选项,比如-g指定产生调试信息。也可以通过add_definitions命令添加编译选项。
* EXECUTABLE_OUTPUT_PATH

指定可执行文件存放的路径。
* LIBRARY_OUTPUT_PATH

指定库文件放置的路径

4. 常用的命令

除了内置变量,我们还可以通过命令来修改编译选项,现将一些常用的命令列出来:

* include_directories

指定头文件的搜索路径,相当于指定gcc编译器的-I参数
* link_directories

动态链接库或静态链接库的搜索路径,相当于指>定gcc的-L参数
* add_subdirectory

包含子目录,当工程包含多个子目录时,此命令有用
* add_definitions

添加编译参数,比如add_definitions(-DDEBUG)将在gcc命令行添加DEBUG宏定义
* add_executable

编译可执行程序
* target_link_libraries

指定链接库,相同于指定-l参数

* AUX_SOURCE_DIRECTORY 将指定目录中的源文件名称赋值给变量DIR_SRCS

AUX_SOURCE_DIRECTORY(. DIR_SECS)

把当前目录下面的所有源文件名称赋值给变量DIR_SRCS

Cmake Practice(cmake 实践)   http://www.scribd.com/full/13774019?access_key=key-hkil010h7nnglwgk8x5

Links:
1. http://www.cmake.org/pipermail/cmake/2005-January/006051.html
2.  CMake Useful Variables http://www.vtk.org/Wiki/CMake_Useful_Variables
3.  http://www.cmake.org/pipermail/cmake/2009-March/028299.html
4.  http://www.scribd.com/doc/13774019/Cmake-Practicecmake-

Categories: Tech.Notes Tags: , , , ,

GNU Configure 中的 build target和host 的区别

August 2nd, 2008 No comments

这几天在做交叉编译的时候,对configure的build, target和host 一直搞不明白,搜了些资料记录一下:

一、 http://en.wikipedia.org/wiki/Cross_compile

The GNU autotools packages (i.e. autoconf, automake, and libtool) use the notion of a build platform, a host platform, and a target platform.

The build platform is where the code is actually compiled.

The host platform is where the compiled code will execute.

The target platform usually only applies to compilers. It represents what type of object code the package itself will produce (such as cross-compiling a cross-compiler); otherwise the target platform setting is irrelevant. For example, consider cross-compiling a video game that will run on a Dreamcast. The machine where the game is compiled is the build platform while the Dreamcast is the host platform.

二、 http://www.airs.com/ian/configure/configure_5.html#SEC30

When building cross compilation tools, there are two different systems involved: the system on which the tools will run, and the system for which the tools generate code.

The system on which the tools will run is called the host system.

The system for which the tools generate code is called the target system.

For example, suppose you have a compiler which runs on a GNU/Linux system and generates ELF programs for a MIPS embedded system. In this case the GNU/Linux system is the host, and the MIPS ELF system is the target. Such a compiler could be called a GNU/Linux cross MIPS ELF compiler, or, equivalently, a ‘i386-linux-gnu’ cross ‘mips-elf’ compiler.

简单说明一下:

  1. build 就是你现在使用的机器。
  2. host 就是你编译好的程序能够运行的平台。
  3. target 编译程序能够处理的平台。一般都用在构建编译本身的时候(gcc), 才用target, 也就是说平时我们所说的交叉编译用不到target.

Target usually have a meaning for developemt tool only.

比如: 在386的平台上编译可以运行在arm板的程序 ./configure –build=i386-linux,–host=arm-linux就可以了.

因为一般我们都是编译程序而不是编译工具.

如果我们编译工具,比如gcc,这个target就有用了.如果我们需要在一个我们的机器上为arm开发板编译一个可以处理 mips程序的gcc,那么target就是mips了.

比如:

1. ./configure --build=mipsel-linux --host=mipsel-linux
--target=mipsel-linux' will build native mipsel-linux binutils on
mipsel-linux.

2. ./configure --build=i386-linux --host=mipsel-linux
--target=mipsel-linux' will cross-build native mipsel-linux binutils on
i386-linux.

3. ./configure --build=i386-linux --host=i386-linux
--target=mipsel-linux' will build mipsel-linux cross-binutils on
i386-linux.

4. ./configure --build=mipsel-linux --host=i386-linux
--target=mipsel-linux' will cross-build mipsel-linux cross-binutils for
i386-linux on mipsel-linux.

As you see, only if $build != $host a cross-compilation is performed.
参考:
  1. http://en.wikipedia.org/wiki/Cross_compile
  2. http://www.airs.com/ian/configure/configure_5.html#SEC30
  3. http://oss.lzu.edu.cn/blog/blog.php?/do_showone/tid_116.html

– EOF –

Categories: Embedded Tags: ,