這兩天學習了CMakeLists.txt的規則和寫法
先給大家發幾個CMakeLists.txt的學習網址和官網doc
https://cmake.org/cmake-tutorial/ 【入門學習步驟】
http://blog.csdn.net/sunbaigui/article/details/6625547 【簡單示例】
https://cmake.org/Wiki/CMake_Useful_Variables 【常用變量名】
https://github.com/carl-wang-cn/demo/tree/master/cmake 【大量有實用價值的demo】
ok現在開始看openwrt下的cmakelists.txt,其實完全沒啥不一樣的,就幾行代碼就可以搞定了。。。
首先helloworld的makefile相比以前的有些變化
package/helloworld/Makefile
添加一行
1 | include $(INCLUDE_DIR)/cmake.mk |
然後在src下沒有了makefile,而是CMakeLists.txt,注意文件的名的大小寫,出錯了就認不得了。。
#vim package/helloworld/src/CMakeLists.txt
1
2
3
4
5
6
7
8
|
cmake_minimum_required(VERSION
2.6) #要求的最低cmake版本號
PROJECT(hello_world) #項目名稱
SET(SOURCES
hello_world.c)
#設置變量SOURCES所指定的C文件
ADD_EXECUTABLE(hello_world
${SOURCES})
#設置最終生成的可執行文件名
INSTALL(TARGETS
hello_world
RUNTIME
DESTINATION
bin)
#最後的install,必要的
|
把整體的源碼也貼出來吧!
歡迎任何人在此代碼的基礎上修改成自己的軟件包!