Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Include instructions from other file in CMakeLists.txt

I want to create a second file, for example Instructions.txt, and be able to include it’s CMake instructions to the main CMakeLists.txt, for example:

// Instructions.txt
set(MY_VARIABLE, value)
set(MY_SECOND_VARIABLE, 1234)
// CMakeLists.txt
<HERE INCLUDE INSTRUCTIONS.TXT>

// And be able to use those variables, for example
project(MY_VARIABLE)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You usually do that simply by using another cmake.

Contrary to what you might believe, the file extension is different for other file than build files.

Let’s call this file instructions.cmake:

set(MY_VARIABLE, value)
set(MY_SECOND_VARIABLE, 1234)

Then you can include it like this inside your CMakeLists.txt:

include(instructions)

There are some other filename that are important for CMake though.

For example, any file that start with Find then ends with .cmake like FindXYZ.cmake, the XYZ part is assumed to be a package name and in that case you should use find_package(XYZ REQUIRED).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading