Use cmake on Linux to create the CodeBlocks project, cmakecodeblocks
Recently, cmake has been used in linux, and it is really difficult to adapt to the use of GUI. I am trying my best to create the project that used cmake as a CodeBlocks project. The project is acceptable when it is small, and it is too much trouble.
After reading the official cmake documentation, you can use commands to generate the codeblocks project in Versions later than 2.2.8... however, there are not many related articles, and there may not be too many things I think about. Generally, CMake is a master and won't be so cool, let's start with the simplest project.
Because the cmake official Recommendation uses external compilation, we 'd better use external compilation. Create a folder named t1, and create two directories, Hello_src and build, respectively. Hello_src stores the source file and cmakelists.txt, and build the generated codeblocks project.
The main. c code is
1 #include <stdio.h>2 int main()3 {4 printf("Hello World from t1 Main!\n");5 return 0;6 }
CMakeLists.txt
1 PROJECT (HELLO)2 SET(SRC_LIST main.c)3 MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR})4 MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR})5 ADD_EXECUTABLE(hello ${SRC_LIST})
Cmake ../Hello_src-G "CodeBlocks-Unix Makefiles"
Go to build and you will see the codeblocks project.
However, there is a problem with directly compiling and running,
Select project-> properties-> Build targets
Change
Then click compile to run successfully: