user1503944
user1503944

Reputation: 397

cmake - how to define symbol for target library depending on who use it

I have cmake project, with 3 sub-projects.

Let's call it A,B,C .

A - common library(static) for both subproject B and C. B and C - standalone executables .

So I need, somehow, compile "A" library for using within "B" with specific declared defines(like -DUSED_WITHIN_B_MODULE) .

On the other hand "C" executable should use "A" compiled with another set of defines (like -DUSED_WITHIN_C_MODULE)

Please suggest me how to implement it . I know about PUBLIC/PRIVATE/INTERFACE modificator for target_compile_definitions but I don't sure how to use it correctly for dependency tree .

Will be grateful for help, Thank you.

Upvotes: 1

Views: 1443

Answers (1)

John Zwinck
John Zwinck

Reputation: 249592

Do something like this:

add_library(AforB a.cpp)
set_target_properties(AforB PROPERTIES COMPILE_FLAGS -DUSED_WITHIN_B_MODULE)
add_library(AforC a.cpp)
set_target_properties(AforC PROPERTIES COMPILE_FLAGS -DUSED_WITHIN_C_MODULE)

Upvotes: 1

Related Questions