I have a .so library target created by add_library
, and need to pass an absolute path to this library to an external script. Now I have ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}LangShared${CMAKE_SHARED_LIBRARY_SUFFIX}
for that (LIBRARY_OUTPUT_PATH
is defined in my CMakeLists.txt
). This looks like hard-coding to me, because it will break as soon as the target is renamed or some of its properties are changed. Is there a way to get an absolute path to add_library
's output?
相关问题
- Avoid cmake to add the flags -search_paths_first a
- CMakeList file to generate LLVM bitcode file from
- How to fix NDK build error for HelloCardboard samp
- Linking against GLEW with CMake
- Linking libavcodec in Cmake, find_library won'
相关文章
- Target requires the language dialect “CXX17” (with
- How do I tell cmake not to create a console window
- Do something for all targets
- CMake: Replace compile flags of an INTERFACE targe
- Generate Web Assembly from CMake Project with a Sp
- Integrate ITK (Insight Toolkit) into own project
- Is there a way to disallow “experimental” C++17 in
- CMake properties and expanding generator expressio
You should use a generator expression for this.
From the docs for
add_custom_command
and the docs for generator expressions:In this case, assuming your library target is called "MyLib", the generator expression representing the full path to the built library would be:
Try:
Where
fancy_lib
is the target created withadd_library (fancy_lib SHARED ...)
.I found that works directly with Makefile generators, but there is more work to be done for Visual Studio generators since the value of
fancy_lib_location
is not what you would expect:fancy_lib_location
will contain an embedded reference to a Visual-Studio-specific$(OutDir)
reference that you will have to replace with the value of theCMAKE_BUILD_TYPE
CMake variable (which resolves to something likeDebug
, orRelease
).CMAKE_DEBUG_POSTFIX
variable, then it will not be included in the value (which may or may not be a bug, I don't know).