File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -106,3 +106,39 @@ function(_cpp_library_setup_core)
106106 endif ()
107107
108108endfunction ()
109+
110+ # Function to copy static template files
111+ function (_cpp_library_copy_templates)
112+ set (options FORCE_INIT)
113+ cmake_parse_arguments (ARG "${options} " "" "" ${ARGN} )
114+
115+ # List of static template files to copy
116+ set (TEMPLATE_FILES
117+ ".clang-format"
118+ ".gitignore"
119+ ".gitattributes"
120+ ".vscode/extensions.json"
121+ "docs/index.html"
122+ )
123+
124+ foreach (template_file IN LISTS TEMPLATE_FILES)
125+ set (source_file "${CPP_LIBRARY_ROOT} /templates/${template_file} " )
126+ set (dest_file "${CMAKE_CURRENT_SOURCE_DIR} /${template_file} " )
127+
128+ # Check if template file exists
129+ if (EXISTS "${source_file} " )
130+ # Copy if file doesn't exist or FORCE_INIT is enabled
131+ if (NOT EXISTS "${dest_file} " OR ARG_FORCE_INIT)
132+ # Create directory if needed
133+ get_filename_component (dest_dir "${dest_file} " DIRECTORY )
134+ file (MAKE_DIRECTORY "${dest_dir} " )
135+
136+ # Copy the file
137+ file (COPY "${source_file} " DESTINATION "${dest_dir} " )
138+ message (STATUS "Copied template file: ${template_file} " )
139+ endif ()
140+ else ()
141+ message (WARNING "Template file not found: ${source_file} " )
142+ endif ()
143+ endforeach ()
144+ endfunction ()
Original file line number Diff line number Diff line change @@ -113,6 +113,9 @@ function(cpp_library_setup)
113113 if (NOT ARG_NO_PRESETS)
114114 _cpp_library_generate_presets(FORCE_INIT ${ARG_FORCE_INIT} )
115115 endif ()
116+
117+ # Copy static template files (like .clang-format, .gitignore, etc.)
118+ _cpp_library_copy_templates(FORCE_INIT ${ARG_FORCE_INIT} )
116119
117120 # Setup testing (if tests are specified)
118121 if (BUILD_TESTING AND ARG_TESTS)
You can’t perform that action at this time.
0 commit comments