Can I get the Profile name inside CMake script?

I'm trying out CLion as an improvemtn on Netbeans since I'm increasingly fighting NB insistence that C++14 is the most recent version. I have a C++ project that builds 12 different ways with various combinations of flags and sanitisers (excluding unit tests!). That's all actually done on a CI setup that pushes the executables to docker images yadda yadda, the problem is generating the makefiles.

CLion/cmake seems to only support binary flags, and not supply the name the of the profile to the build environment. I really don't want a CMakeLists.txt that has 12 input flags plus a string variable, just because it's a maintenance nightmare. It's bad enough as it is.

I'd really like to be able to have a PROFILE variable like the CONFIG variable to make it easier to read intent, and because 12 lines  of that will do 90% of the work:

add_compile_definitions(__BUILD_DESC=\"$<PROFILE>\") # lets the executable dump the profile name into log files etc
add_compile_options("$<$<PROFILE:CLANG_MEMORY_SANITIZER>:-g -pthread -Og $(BUILD_NUMBER_LDFLAGS) -Wall -Wformat=2 -Wno-variadic-macros -Wcast-align -Wno-vla -Wextra -fsanitize-blacklist=../no-sanitize.txt -fsanitize=memory -fPIE -fno-omit-frame-pointer -fsanitize-memory-track-origins>")

The alternative I'm starting to grind my way through is a whole series of boolean tests:

if (BUILD_CLANG_MEMORY_SANITIZER)
add_compile_definitions(CLANG DEBUG)
add_compile_options(-Wall -Wformat=2 -Wno-variadic-macros -Wcast-align -Wno-vla -Wextra -fsanitize-blacklist=../no-sanitize.txt -fsanitize=memory -fPIE -fno-omit-frame-pointer -fsanitize-memory-track-origins)
add_library(profiler SHARED IMPORTED)
set_target_properties(profiler PROPERTIES IMPORTED_LOCATION "/lib64/libprofiler.so" INTERFACE_INCLUDE_DIRECTORIES "/usr/include/")
elseif(BUILD_CLANG_RELEASE)
add_compile_options(-O3)
....

Also, is there some way to get a one line or more readable version of the add_library/set_target_properties pair of calls? Having two lines makes it harder to see the common pattern when I have multiple libraries. Or is there a way to not have to say "this library I just added, here's the location and include location"? Most of the libraries I use are C-style and I don't want to set them up as proper dependencies (not least because it makes deploying harder for the DevOps people if potentially every build comes with new versions of every library).

 

Thanks for any tips

0

请先登录再写评论。