以前在Linux下看过一些auto make 工具生成的Makefile,感觉生成的Makefile有一个原则,就是死命让人看不懂,显得很高深莫测,我不甘心,一些网友又给我推荐cmake,搜索一下果然是吹的神乎其技,并且说大型工程,自己手工写Makefile的人就是SB。于是我就整起来,开始在windows下整,遇到一些问题始终很奇怪,解决不了,于是还是在ubuntu下来搞吧。
sudo apt-get install cmake 安装即可
于是随便整一个只有main 函数的一个c文件,修改 CMakeLists.txt进行编译,提示No CMAKE_CXX_COMPILER could be found
通过:
sudo apt-get update
sudo apt-get install -y build-essential
解决了,cmake 后生成了Makefile ,执行make 也能生成可执行文件,不过打开Makefile一看,我的神啊,就一个main 函数,居然生成这么多。。。。。。
default_target: all
.PHONY : default_target
.NOTPARALLEL:
.SUFFIXES:
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
$(VERBOSE).SILENT:
cmake_force:
.PHONY : cmake_force
SHELL = /bin/sh
CMAKE_COMMAND = /usr/bin/cmake
RM = /usr/bin/cmake -E remove -f
EQUALS = =
CMAKE_SOURCE_DIR = /home/gooogleman/test/test_code/cmake_test
CMAKE_BINARY_DIR = /home/gooogleman/test/test_code/cmake_test/build
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
/usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
.PHONY : edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/gooogleman/test/test_code/cmake_test/build/CMakeFiles /home/gooogleman/test/test_code/cmake_test/build/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /home/gooogleman/test/test_code/cmake_test/build/CMakeFiles 0
.PHONY : all
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean
clean/fast: clean
.PHONY : clean/fast
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
depend:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
cmake_test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 cmake_test
.PHONY : cmake_test
cmake_test/fast:
$(MAKE) -f CMakeFiles/cmake_test.dir/build.make CMakeFiles/cmake_test.dir/build
.PHONY : cmake_test/fast
align.o: align.c.o
.PHONY : align.o
align.c.o:
$(MAKE) -f CMakeFiles/cmake_test.dir/build.make CMakeFiles/cmake_test.dir/align.c.o
.PHONY : align.c.o
align.i: align.c.i
.PHONY : align.i
align.c.i:
$(MAKE) -f CMakeFiles/cmake_test.dir/build.make CMakeFiles/cmake_test.dir/align.c.i
.PHONY : align.c.i
align.s: align.c.s
.PHONY : align.s
align.c.s:
$(MAKE) -f CMakeFiles/cmake_test.dir/build.make CMakeFiles/cmake_test.dir/align.c.s
.PHONY : align.c.s
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... rebuild_cache"
@echo "... edit_cache"
@echo "... cmake_test"
@echo "... align.o"
@echo "... align.i"
@echo "... align.s"
.PHONY : help
cmake_check_build_system:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system
过于复杂,要知道Linux 这么大的代码,也是没这么晦涩的,也不智能,不能用,放弃!看来还是自己老老实实写Makefile改善,写好框架就简单了。