I'm using cmake to generate a Visual Studio project.
Let's say I need to use the following Microsoft-specific libraries and headers:
c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\VS\UnitTest\lib\x64\Microsoft.VisualStudio.TestTools.CppUnitTestFramework.lib
)c:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\crtdbg.h
)I don't want to hardcode these paths into my CMakeLists.txt, or force a developer to pass in the paths during the build.
I expect to be able to do something like this:
# 1. get include paths somehow
# 2. get lib paths somehow
include_directories(
${MSVS_UnitTest_INCLUDE_DIR}
${Windows_SDK_INCLUDE_DIR}/ucrt
)
link_directories(
${MSVS_UnitTest_LIBRARIES_DIR}/x64
${Windows_SDK_LIBRARIES_DIR}/ucrt/x64
)
add_library(MyTest mytest.cpp)
target_link_libraries(MyTest
libucrt
Microsoft.VisualStudio.TestTools.CppUnitTestFramework
)
What's the right way to do #1 and #2?
To include headers in CMake targets, use the command target_include_directories(...) . Depending on the purpose of the included directories, you will need to define the scope specifier – either PUBLIC , PRIVATE or INTERFACE .
At least for #1 (incldue paths to sdk) i found a solution. If you use the Generator for Visual Studio, the cmake variable CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION is filled with the paths to the include folder. Another way is using the environment variables $ENV{WindowsSdkDir} and $ENV{WindowsSDKVersion}, which is most likely the source cmake gets this information from as well.
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