Here is what I’m expecting after running “cmake …”
simple.sln
++ simple.vcxproj for Debug configuration
++++ use ../debug/lib/a_lib.lib for linking
++ simple.vcxproj for Release configuration
++++ use ../release/lib/a_lib.lib for linking
I’m aware that my CMakeLists.txt can’t do what I’m expecting, how can I fix my CMakeLists.txt ?
If it is built by CMake, you can use the target as is in your target_link_libraries() command. In this case the debug and release versions of the library is handled by CMake:
In my post, the a_lib is a pre-built library, I only need to link to it.
But in my practical situation, it is another library generated by cmake, and I need to link to its binary.
And include the exported config file to consume the exported library:
set (INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install")
include ("${INSTALL_PREFIX}/my_export/my_lib.cmake")
...
target_link_libraries (simple PRIVATE A_LIB::lib_a)
In 1st fix, I’ve noticed that you missed ‘EXPORT my_lib’ on purpose, then for Release configuration, because a_lib is already exported, then CMake will export the Release configuration of ‘a_lib’ by itself, right ?