Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
866 views
in Technique[技术] by (71.8m points)

cmake - Path to target output file

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should use a generator expression for this.

From the docs for add_custom_command and the docs for generator expressions:

Arguments to COMMAND may use "generator expressions"...

Generator expressions are evaluted during build system generation to produce information specific to each build configuration.

In this case, assuming your library target is called "MyLib", the generator expression representing the full path to the built library would be:

$<TARGET_FILE:MyLib>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...