I am using CMAKE 3.4.3
on Windows and what I am trying to do is set a path in CMAKE and try to refer to that in my C++ file.
What I tried was as follows:
In CMakeLists.txt file
ADD_DEFINITIONS(-DNV12_2_ARGB_PTX_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ptx")
Now, I try and refer to 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 refer to it as:
std::cout << PTX_DIR << std::endl;
I get the error:
'C:/Users/Luca/project/src/lib/ptx': No such file or directory
Also, Visual studio intellisense complains:
IntelliSense: identifier "PTX_DIR" is undefined
Not sure why it wants to open a file with this variable...
You access a variable by using ${} , such as ${MY_VARIABLE} . 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.
Run CMake and have a look at the cache with the ccmake GUI tool. Then you'll get all the variables. Or run CMake with -LH then you will get all variables printed after configuration.
Use the syntax $ENV{VAR} to read environment variable VAR . To test whether an environment variable is defined, use the signature if(DEFINED ENV{<name>}) of the if() command. For general information on environment variables, see the Environment Variables section in the cmake-language(7) manual.
The problem is with your use of add_definitions
. You're effectively passing the value of ${CMAKE_CURRENT_SOURCE_DIR}/ptx
as an additinal argument on the compiler's command line, which the compiler probably interprets as a source file it should compile. Check the full command line invoked to be sure.
You probably intended this:
add_definitions(-DNV12_2_ARGB_PTX_DIR="${CMAKE_CURRENT_SOURCE_DIR}/ptx")
Note that you may have to play around with escaping the quotation marks to get them all the way down to C++. Alternatively, you could use configure_file()
.
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