我有以下代码结构
Project->
project.cxx
CMakeLists.txt
meta->
CMakeLists.txt
first->
first.cxx
CMakeLists.txt
second->
second.cxx
CMakeLists.txt
其中first / CMakeLists.txt包含:
FILE(GLOB first_sources "*.cxx")
ADD_LIBRARY(first OBJECT ${first_sources})
second / CMakeLists.txt包含:
FILE(GLOB second_sources "*.cxx")
ADD_LIBRARY(second OBJECT ${second_sources})
meta / CMakeLists.txt包含:
ADD_SUBDIRECTORY(first)
ADD_SUBDIRECTORY(second)
ADD_LIBRARY(meta OBJECT $<TARGET_OBJECTS:first> $<TARGET_OBJECTS:second>)
最后,Project / CMakeLists.txt包含:
ADD_SUBDIRECTORY(meta)
FILE(GLOB Project_SOURCES "*.cxx")
ADD_LIBRARY(Project SHARED ${Project_SOURCES} $<TARGET_OBJECTS:meta>)
然而,
ADD_LIBRARY(meta OBJECT $<TARGET_OBJECTS:first> $<TARGET_OBJECTS:second>)
如果OBJECT库需要c / cxx源而不是目标文件,则失败。
我想要实现的是一个可重定位目标文件,它将first.o和second.o结合到meta.o中:
ld -r first.o second.o -o meta.o
同样的CMake选择是什么?