Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake obtain source list

I have a big project already building under cmake. I am looking for a way to obtain the list of source files and their dependent header files to create a new target (in example etags for Emacs). I tried to find the answer on my own but it seems to not be that easy.

The ideal soultion would be something like that:

add_executable(my_project <some list of source files and libraries defined in different directories>)
add_custom_target(tags
  COMMAND etags <list of all *.cpp and *.h files used in 'my_project' target>
  DEPENDS <list of all *.cpp and *h used in 'my_project' target>
  COMMENT "Creates source code tags for Emacs")

Do you maybe know how to make 'tags' target import all dependencies from 'my_project' target without the need to rewrite all cmake configuration files in all directories?

like image 780
Mateusz Pusz Avatar asked Jan 09 '13 10:01

Mateusz Pusz


People also ask

How do I use a list in CMake?

A list in cmake is a ; separated group of strings. To create a list the set command can be used. For example, set(var a b c d e) creates a list with a;b;c;d;e , and set(var "a b c d e") creates a string or a list with one item in it.

What is sources CMake?

This specifies the list of paths to source files for the target. The following commands all set or add to the SOURCES target property and are the usual way to manipulate it: add_executable() add_library()

What is CMake target?

A CMake-based buildsystem is organized as a set of high-level logical targets. Each target corresponds to an executable or library, or is a custom target containing custom commands.


1 Answers

With command get_target_property and property SOURCES and eventually PUBLIC_HEADER or PRIVATE_HEADER?

get_target_property(MY_PROJECT_SOURCES my_project SOURCES)
like image 138
julp Avatar answered Oct 24 '22 19:10

julp