Use cmake on the Linux platform for cross-compilation to replace makefile used by the embedded platform

Source: Internet
Author: User

Use cmake on the Linux platform for cross-compilation to replace makefile used by the embedded platform

A Zeng

2010.3.9

The embedded platform has compiled a large project that uses makefile all the time. Now we need to change it to cmake. We have never touched cmake before and are now learning to use it.

References:

Using cmake to build applications in Linux-an article on IBM developerworks


Cmake practices-a good tutorial


Http://blog.csdn.net/netnote/article/details/4051620 summary is good


I. cmake syntax Basics

There are three folders under the project directory hellofolder, which are respectively build, doc, SRC, and cmakelists.txt, copyright, R, and E.

, README, runhello. Sh.

Hello.txt.main.cand cmakelists.txt under doc2.

Contents of cmakelists.txt in the project directory

Project (Hello) <br/> set (cmake_install_prefix/tmp/cmake/hello2) <br/> install (Files copyright readme destination share/DOC) <br/> install (programs runhello. sh destination bin) <br/> install (directory DOC/destination share/DOC) <br/> # Install (targets Hello runtime destination bin) <br/> add_subdirectory (SRC bin)

Cmakelists.txt content in the srcdirectory

Set (src_list main. c) <br/> message (status "this is binary dir" $ {hello_binary_dir}) <br/> message (status "this is source dir" $ {hello_source_dir }) <br/> set (executable_output_path $ {project_binary_dir}/binary_output) <br/> add_executable (Hello $ {src_list}) <br/> install (targets Hello runtime destination bin)

Run the following command under build under the project directory.

Cmake ..

The intermediate products of various cmake will be generated under the build directory.

Then execute

Make

Make install

Install various installation files according to the cmake_install_prefix directory.

This will generate several directories under the/tmp/camke/hello2 directory

/Tmp/camke/hello2/bin, which contains hello, runhello. Sh

/Tmp/camke/hello2/share/doc,copyright,readme,hello.txt


Use jm11.0kta1.2as an example to compile cmakelists.txt

Jm11.0kta1.2 download Website: http://iphome.hhi.de/suehring/tml/download/KTA/

The folder name after jm11.0kta1.2.zip is extracted is jmkta.
The jmkta directory structure is as follows:
.
── Bin
│ ── Decoder. cfg
│ ── Encoder_baseline.cfg
│ ── Encoder. cfg
│ ── Encoder_extended.cfg
│ ── Xxxxxxxxxxxxxxxxxxxxxxxxx
│ ── Q_matrix_def.cfg
│ ── Q_offset.cfg
│ ── Sg0conf. cfg
│ ── Sg2conf. cfg
│ ── Sg6conf. cfg
── Changes_detail.txt
── Changes. txt
── Copyright.txt
── Disclaimer.txt
── Doc
│ ── Coding_style.doc
│ ── Doxygen.txt
│ ── Foot.html
│ ── H26l.css
│ ── Ldecod. Dox
│ ── Lencod. Dox
── Doxyfile
── Frext_changes.txt
── Kta_changes.txt
── Lcommon
│ ── Inc
│ ── SRC
── Ldecod
│ ── Inc
│ ── Adaptive_filter.h
│ ── Adaptive_quantization.h
│ ── Xxxxxxxxxxxxxxxxxxxxxxxxx
│ ── Output. h
│ ── Parsetcommon. h
│ ── PARSET. h
│ ── RTP. h
│ ── Sei. h
│ ── Spatial_domain_coding.h
│ ── Transform8x8. h
│ ── VLC. h
│ ── Makefile
│ ── OBJ
│ ── SRC
│ ── Adaptive_filter.c
│ ── Adaptive_quantization.c
│ ── Annexb. c
│ ── Xxxxxxxxxxxxxxxxxxxxxxxxx
│ ── Parsetcommon. c
│ ── RTP. c
│ ── Sei. c
│ ── Spatial_domain_coding.c
│ ── Transform8x8. c
│ ── VLC. c
── Ldecod. DSP
── Ldecod. DSW
── Ldecod. kdevelop
── Ldecod. kdevelop. filelist
── Ldecod. vcproj
── Lencod
│ ── Inc
│ ── Adaptive_filter.h
│ ── Adaptive_quantization.h
│ ── Annexb. h
│ ── Xxxxxxxxxxxxxxxxxxxxxxxxx
│ ── Refbuf. h
│ ── RTP. h
│ ── Sei. h
│ ├ ── Simplified_fast_me.h
│ ── Spatial_domain_coding.h
│ ── Transform8x8. h
│ ── VLC. h
│ ── Makefile
│ ── OBJ
│ ── SRC
│ ── Adaptive_filter.c
│ ── Adaptive_quantization.c
│ ── Annexb. c
│ ── Biariencode. c
│ ── Block. c
│ ── Xxxxxxxxxxxxxxxxxxxxxxxxx
│ ├ ── Simplified_fast_me.c
│ ── Slice. c
│ ── Spatial_domain_coding.c
│ ── Transform8x8. c
│ ── VLC. c
│ ── Weighted_prediction.c
├ ── Lencod. DSP
── Lencod. DSW
├ ── Lencod. kdevelop
── Lencod. kdevelop. filelist
├ ── Lencod. vcproj
── Readme.txt
├ ── Rtpdump
│ ── Readme.txt
│ ── Rtpdump. cpp
│ ── Rtpdump. DSP
│ ── Rtpdump. vcproj
│ ── Stdafx. cpp
│ ── Stdafx. h
── TMl. DSW
── TMl. sln
── Unixprep. Sh

The bin folder contains executable program configuration parameters.
The doc contains the document, and the word version is actually given.
The lencod and ldecod folders are used for encoding and decoding respectively.
Assume that the jmkta folder is in the personal directory. Go to the jmkta folder

Cd ~ /Jmkta
Vim cmakelists.txt

PROJECT(kta)CMAKE_MINIMUM_REQUIRED(VERSION 2.6)ADD_SUBDIRECTORY(lencod)

CD lencod

Vim cmakelists.txt

ADD_SUBDIRECTORY(src)

CD SRC

Vim cmakelists.txt

AUX_SOURCE_DIRECTORY(. DIR_SRCS)INCLUDE_DIRECTORIES(${kta_SOURCE_DIR}/lencod/inc)ADD_EXECUTABLE(lencod ${DIR_SRCS})SET(EXECUTABLE_OUTPUT_PATH ${kta_SOURCE_DIR}/bin)MESSAGE(STATUS "KTA BINARY DIR is ",${kta_SOURCE_DIR}/bin)TARGET_LINK_LIBRARIES(lencod m)

We recommend that you use an external build method to create a build folder build project in the KTA folder. Of course, this folder can be used anywhere.
Cd ~ /Jmkta
Mkdir build
Cmake ..
Make

Then the executable program lencod IN ~ /Jmkta/bin.

Now let's analyze several basic cmake statements.

  • Project (KTA) defines the project name, and the variable kta_source_dir after it refers to the project path.
  • Cmake_minimum_required (version 2.6) requires the lowest version number.
  • Add_subdirectory (lencod) adds subdirectories for storing all source files
  • Aux_source_directory (. dir_srcs) assigns the source file name in the current directory to the variable dir_srcs
  • Include_directories ($ {kta_source_dir}/lencod/INC) adds the path for storing the header file. Otherwise, the header file cannot be found.
  • Add_executable (lencod $ {dir_srcs}) defines the executable file name as lencod, and the relevant source file table is the value of the variable dir_srcs. At this time, the number of files in the current directory is not afraid. cmake will automatically compile and process the dependency.
  • Set (executable_output_path $ {kta_source_dir}/bin) to set the destination binary executable program storage address to the project source code storage path, depending on your situation. Here I am consistent with the makefile of KTA.
  • Message (status "KTA binary DIR is", $ {kta_source_dir}/bin) print the path where the target binary executable programs are stored.
  • Target_link_libraries (lencod m) can be used to link the shared library of executable programs, that is, it replaces the-LM command in makefile. It adds a shared library for arithmetic operations.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.