Is there a way to concatenate strings in cmake?
I have a folder that only contains .cpp files with main methods. I thought this would be easy by just using a foreach through all src files. This is what I've got this far:
project(opengl-tutorial) cmake_minimum_required(VERSION 2.8) aux_source_directory(. SRC_LIST) add_definitions( --std=c++11 ) foreach (src ${SRC_LIST}) # name = ${src} + ".out" add_executable(${name} ${src}) target_link_libraries(${name} GL GLU GLEW glfw) endforeach(src ${SRC_LIST})
How can I do what's described in the comment?
For better performance use str1. concat(str2) where str1 and str2 are string variables. Show activity on this post. In java concatenate symbol is " + ".
A list in cmake is a ; separated group of strings. To create a list the set command can be used. For example, set(var a b c d e) creates a list with a;b;c;d;e , and set(var "a b c d e") creates a string or a list with one item in it.
String concatenation using + Operator For example "One" + "Two" will produce a String object "OneTwo". You can use this operator to combine more than one String e.g. two, three, four or any number of String object like "abc" + "def" + "ghi" + "jklm" will result in "abcdefghijklm".
Local Variables You access a variable by using ${} , such as ${MY_VARIABLE} . 1. CMake has the concept of scope; you can access the value of the variable after you set it as long as you are in the same scope. If you leave a function or a file in a sub directory, the variable will no longer be defined.
"${src}.out"
should work fine, so you can write set(NAME "${src}.out")
and use ${NAME}
wherever you need to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With