Referring to the CMAKE variable from code

I am using CMAKE 3.4.3 for Windows, and what I'm trying to do is set the path in CMAKE and try to access this in my C ++ file.

What I tried was as follows:

In the CMakeLists.txt file

 ADD_DEFINITIONS(-DNV12_2_ARGB_PTX_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ptx") 

Now I will try to access it from my C ++ file as follows:

 #ifdef NV12_2_ARGB_PTX_DIR #define PTX_DIR D_NV12_2_ARGB_PTX_DIR #endif 

And when I try to reference it as:

 std::cout << PTX_DIR << std::endl; 

I get an error message:

 'C:/Users/Luca/project/src/lib/ptx': No such file or directory 

In addition, Visual Studio intellisense complains:

 IntelliSense: identifier "PTX_DIR" is undefined 

Not sure why he wants to open a file with this variable ...

+6
source share
1 answer

The problem is using add_definitions . You effectively pass the value of ${CMAKE_CURRENT_SOURCE_DIR}/ptx as an additional argument on the compiler command line, which the compiler will probably interpret as the source file that it should compile. Verify that the command line you entered is correct.

Perhaps you intended to do this:

 add_definitions(-DNV12_2_ARGB_PTX_DIR="${CMAKE_CURRENT_SOURCE_DIR}/ptx") 

Note that you may have to play around with quotes escaping to bring them to C ++. Alternatively, you can use configure_file() .

+8
source

Source: https://habr.com/ru/post/1011652/


All Articles