我最终使用了 cotire 模块(https://github.com/sakra/cotire)并配置了它的统一构建功能(它将所有源代码捆绑到一个文件中进行编译)并运行它。
虽然统一构建不是 100% 与 c++ 兼容,因为它们打破了文件级边界,但它对我有用。
设置它有点棘手,我不确定我是否做得最好,但我所做的是将以下内容放在子目录中并放入add_subdirectory(my_directory_name)
我的主 CMakeLists.txt 文件中:
MACRO(ADD_CXX_FLAGS)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGN}")
# MESSAGE(${CMAKE_CXX_FLAGS})
ENDMACRO(ADD_CXX_FLAGS)
# target_compile_options is the "better" way to do this but it dedupes flags,
# so the multiple -Xclang flags after the first one get lost. There is a cmake bug on this but no one
# is working on it at this time
ADD_CXX_FLAGS(-Xclang)
ADD_CXX_FLAGS(-load)
ADD_CXX_FLAGS(-Xclang)
ADD_CXX_FLAGS(my_plugin.dylib) <== substitute yours here
ADD_CXX_FLAGS(-Xclang)
ADD_CXX_FLAGS(-plugin)
ADD_CXX_FLAGS(-Xclang)
ADD_CXX_FLAGS(MyPluginRegisteredName) <== substitute yours here
#
add_library(apb-js-api-template OBJECT ${APB_SOURCE_FILES})
set_target_properties(some-project-name-template PROPERTIES COTIRE_UNITY_TARGET_NAME "some-project-name")
cotire(some-project-name-template)