0

there is a .pri as a part of qmake project which contains some global string definitions :

STR1 = string literal 1
STR2 = string literal 2
GIT_VERSION = $$system($$ENV_GIT_EXE_PATH describe --long)

and these strings used in a code :

QString str1 = QStringLiteral(STR1);
QString str2 = QStringLiteral(STR2);
QString str3 = QStringLiteral(GIT_VERSION);

How to implement this functionality using cmake project? I can't change the sources (C++.h/.cpp) and have to prepare those strings somehow using cmake abilities

amigo421
  • 2,429
  • 4
  • 26
  • 55

1 Answers1

1

Qmake’s string literals are nothing but a preprocessor macro definitions. In CMake this can be done with add_compile_definitions or with target_compile_definitions

So the analogue would be:

add_compile_definitions(STR1="string literal 1")
add_compile_definitions(STR2="string literal 2")
execute_process(COMMAND ${ENV_GIT_EXE_PATH} describe --long
OUTPUT_VARIABLE git_version)
add_compile_definitions(GIT_VERSION="${git_version}")

PS. You can access environment variables with $ENV{GIT_EXE_PATH}

Teivaz
  • 5,462
  • 4
  • 37
  • 75
  • what is a difference between add_compile_definitions and add_definitions ? – amigo421 Feb 21 '19 at 07:08
  • 1
    @amigo421 add_definitions is an old version of the mentioned commands and as far as I know it is there only for backwards compatibility – Teivaz Feb 21 '19 at 07:12