Используя некоторый код, найденный в разных источниках, я придумал эту функцию:
Код: Выделить всё
function(BuildFolder target)
# Split files between cpp and others
set(cpp_files "")
set(other_files "")
foreach(file_path ${ARGN})
if(file_path MATCHES "\\.cpp$")
list(APPEND cpp_files ${file_path})
else()
list(APPEND other_files ${file_path})
endif()
endforeach()
# Exclude all cpp from compilation
set_source_files_properties(${cpp_files} PROPERTIES HEADER_FILE_ONLY true)
# Create the unity build file and add an include statement for every cpp
set(unit_build_file ${CMAKE_CURRENT_SOURCE_DIR}/ub_index.cpp)
FILE(WRITE ${unit_build_file} "// Auto generated from Cmake\n")
foreach(source_file ${cpp_files})
FILE(APPEND ${unit_build_file} "#include \n")
endforeach()
target_sources(${target} PRIVATE ${unit_build_file})
target_sources(${target} PRIVATE ${cpp_files})
target_sources(${target} PRIVATE ${other_files})
endfunction()
Код: Выделить всё
BuildFolder(
${main_target}
A.cpp
A.h
B.cpp
B.h
...
)
Я также пытался заменить:
Код: Выделить всё
set_source_files_properties(${cpp_files} PROPERTIES HEADER_FILE_ONLY true)
Код: Выделить всё
set_source_files_properties(${cpp_files} PROPERTIES VS_SETTINGS "ExcludedFromBuild=true")
Как мне добиться такого результата?>
Подробнее здесь: https://stackoverflow.com/questions/798 ... sing-cmake
Мобильная версия