Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build specific files in CMAKE everytime?

Tags:

cmake

I am looking for a way to build some c, c++ files in CMAKE everytime when I type the make command whatever I modify the file or not. Because those file include build information codes such as build time. It this possible in CMAKE?

Thank you in advance.

like image 924
gsoh83 Avatar asked Nov 04 '13 05:11

gsoh83


People also ask

How does CMake detect file changes?

It makes use of the --what-if= switch which tells make to act like the given file changed - that way the dependences of build targets on sources / headers are handled elegantly. You might want to also pass the path to source / include files as arguments so that those wouldn't be hardcoded inside.

How do I create a CMakeLists txt file?

In Qt Creator, go to File → Open File or Project… and choose CMakeLists. txt from the source folder you want to build. Qt Creator will prompt you for the location of the binary folder, calling it the “build directory”. By default, it suggests a path adjacent to the source folder.

How do you build with CMake?

To build with just cmake change directory into where you want the binaries to be placed. For an in-place build you then run cmake and it will produce a CMakeCache. txt file that contains build options that you can adjust using any text editor.

What is .CMake file?

CMake is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines). When you create a new CMake project in CLion, a CMakeLists. txt file is automatically generated under the project root.


1 Answers

You can use the add_custom_target command to add a target that will be executed for every build.

For example, you can use the CMake touch command to mark certain source files dirty, so they get rebuild on every run:

add_custom_target(invalidate_files ALL
                  COMMAND ${CMAKE_COMMAND} -E touch ${MY_SRC_FILE})
like image 151
ComicSansMS Avatar answered Sep 18 '22 13:09

ComicSansMS