oferlivny
oferlivny

Reputation: 400

How to change cmake install() patterns with parameters?

My CMake build system supports several platforms and configurations, and supports installing some files as well.

I'm using the install() command, as follows:

install(
 DIRECTORY <some path>
 DESTINATION <some other path>
 FILES_MATCHING PATTERN "*" 
 PATTERN "<some regex 0>*" EXCLUDE
 PATTERN "<some regex 1>*" EXCLUDE
 ...
 PATTERN "<some regex N>*" EXCLUDE
)

Since I have several configuration, I'm looking for an easy way to use subsets of the regex patterns for each configuration, but without having to replicate the entire install command.

i.e.

install(
 DIRECTORY <some path>
 DESTINATION <some other path>
 FILES_MATCHING PATTERN "*" 
 if (confiugrationA || configurationB)
      PATTERN "<some regex 0>*" EXCLUDE
 endif
 if (configurationC)
    PATTERN "<some regex 1>*" EXCLUDE
 endif()
 ...
 PATTERN "<some regex N>*" EXCLUDE
)

Can this be done? Can I use a special regular expression for that?

Upvotes: 1

Views: 1928

Answers (1)

oferlivny
oferlivny

Reputation: 400

Ended up using regex:

set(exclude_regex_A "patternA|patternB|...")
set(exclude_regex_B "patternC|patternD|...")
set(exclude_regex_C "patternE|patternF|...")
if (some_var)
 set(exclude_regex "${exclude_regex_A}|${exclude_regex_B}")
else (some_var)
 set(exclude_regex "${exclude_regex_A}|${exclude_regex_C}")
endif (some_var)
install(
 DIRECTORY <some path>
 DESTINATION <some other path>
 FILES_MATCHING PATTERN "*" 
 REGEX "${exclude_regex}" EXCLUDE
)

Upvotes: 1

Related Questions