简体   繁体   English

cmake共享库

[英]cmake shared libraries

I'm building app with boost.python. 我正在使用boost.python构建应用程序。 I want to make each cpp-module as a single shared library. 我想将每个cpp模块作为一个共享库。

I have a list of cpp-files, how to make in cycle different subprojects with name taken from cpp file? 我有一个cpp文件列表,如何用cpp文件中的名称循环制作不同的子项目?

For example: 例如:

set(Script_srcs
    Module1.cpp
    Module2.cpp
    Module3.cpp
)

some_cycle
  add_library( {NAME} SHARED {PATH} )

Thanks. 谢谢。

You could use foreach to iterate over your source-files and use a the function get_filename_component with NAME_WE to get only the filename, something like: 您可以使用foreach遍历源文件,并使用带有NAME_WE的函数get_filename_component来仅获取文件名,例如:

set(Script_srcs Module1.cpp Module2.cpp Module3.cpp )

foreach( f ${Script_srcs} )
    get_filename_component( ff ${f} NAME_WE )
    add_library( ${ff} SHARED ${f} )
endforeach( f )

But, instead of deriving library-names from filenames, why not work the other way around? 但是,为什么不从文件名中导出库名,为什么不反过来工作呢? Derive your filenames from the desired module-names and append ".cpp" in the for-loop: 从所需的模块名称中导出文件名,并在for循环中附加“ .cpp”:

set( MyModules Module1 Module2 Module3 ) 
foreach( Mod ${MyModules} )
    add_library( ${Mod} SHARED ${Mod}.cpp )
endforeach( Mod )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM