Reputation: 1501
Is it possible to put a flag inside a cmake add_library function so that I reduce duplicate code. e.g.
add_library(somename SHARED
$<TARGET_OBJECTS:xxx_objs>
$<TARGET_OBJECTS:yyy_objs>
$<TARGET_OBJECTS:zzz_objs>
#if(INCLUDE_SOME_FLAG)
$<TARGET_OBJECTS:aaa_objs>
$<TARGET_OBJECTS:bbb_objs>
$<TARGET_OBJECTS:ccc_objs>
#endif(INCLUDE_SOME_FLAG)
)
If I try I get the error: "Cannot find source file:" If I remove the flag it works OK. I guess it thinks the flag is a source file, any way around that?
Upvotes: 1
Views: 467
Reputation: 3103
set(somename_objs
$<TARGET_OBJECTS:xxx_objs>
$<TARGET_OBJECTS:yyy_objs>
$<TARGET_OBJECTS:zzz_objs>)
if (INCLUDE_SOME_FLAG)
list(APPEND somename_objs
$<TARGET_OBJECTS:aaa_objs>
$<TARGET_OBJECTS:bbb_objs>
$<TARGET_OBJECTS:ccc_objs>)
endif ()
add_library(somename SHARED ${somename_objs})
Upvotes: 2