Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make multiple properties valid to one file by set_source_files_properties in cmake?

Tags:

cmake

I am writing a CMakeLists.txt for a project, and encounter a problem with set_source_files_properties.

The original working expression is:

set_source_files_properties (a.cpp PROPERTIES COMPILE_DEFINITIONS
    DIR1="/home/xxx/b.i")

Then I try to add more COMPILE_DEFINITIONSs, but get failure.

try 1:

set_source_files_properties (a.cpp PROPERTIES COMPILE_DEFINITIONS
    DIR1="/home/xxx/b.i" DIR2="/home/xxx/c.i" DIR3="/home/xxx/d.i")

try 2:

set_source_files_properties (a.cpp PROPERTIES COMPILE_DEFINITIONS
    DIR1="/home/xxx/b.i")
set_source_files_properties (a.cpp PROPERTIES COMPILE_DEFINITIONS
    DIR2="/home/xxx/c.i")
set_source_files_properties (a.cpp PROPERTIES COMPILE_DEFINITIONS
    DIR3="/home/xxx/d.i")

result: only last define DIR3 can be recognized in a.cpp when compiling by make, first two are reported undefined in make phase.

Any suggestions?

Thank you!

like image 839
jxj Avatar asked Dec 11 '22 19:12

jxj


2 Answers

The set_*_properties() functions are shorthands for basic usage. For "advanced" cases, it's better to use the full power of set_property():

set_property(
  SOURCE a.cpp
  APPEND
  PROPERTY COMPILE_DEFINITIONS
  DIR1="/home/xxx/b.i" DIR2="/home/xxx/c.i" DIR3="/home/xxx/d.i"
)
like image 198
Angew is no longer proud of SO Avatar answered Jun 22 '23 12:06

Angew is no longer proud of SO


I manage to provide several COMPILE_DEFINITIONS using set_source_files_properties with the following command:

set_source_files_properties (a.cpp PROPERTIES COMPILE_DEFINITIONS
    "DIR1=\"/home/xxx/b.i\";DIR2=\"/home/xxx/c.i\";DIR3=\"/home/xxx/d.i\")"

source: https://cmake.org/cmake/help/v3.5/prop_sf/COMPILE_DEFINITIONS.html

like image 29
RedWark Avatar answered Jun 22 '23 11:06

RedWark