diff --git a/io1_add_target.cmake b/io1_add_target.cmake index bf573a0..6b2fc71 100644 --- a/io1_add_target.cmake +++ b/io1_add_target.cmake @@ -227,34 +227,16 @@ function(fetch_source_files out_sources) PARENT_SCOPE) endfunction() - -function(apply_source_files_properties) - foreach(str IN LISTS ARGN) - is_source_group("${str}" out) - if(out) - continue() - endif() - - parse_file_options("${str}" file options) - - cmake_parse_arguments(io1 "cpp;header" "" "" ${options}) - if(io1_cpp) - set_source_files_properties("${file}" PROPERTIES LANGUAGE CXX) - endif() - if(io1_header) - set_source_files_properties("${file}" PROPERTIES HEADER_FILE_ONLY ON) - endif() - endforeach() -endfunction() - -# adds src to target, applying options -function(io1_add_source_file target file props) +# adds src to target, applying options and source group +function(io1_add_source_file target file props group) get_target_property(type ${target} TYPE) if (${type} STREQUAL "INTERFACE_LIBRARY") target_sources(${target} INTERFACE ${file}) else() target_sources(${target} PRIVATE ${file}) endif() + + source_group(NAME "${group}" FILES "${file}") cmake_parse_arguments(io1 "cpp;header" "" "" ${props}) if(io1_header) @@ -275,34 +257,24 @@ function(io1_is_source_group str res) endfunction() # expects "file.c[:opt1,opt2,opt3,...]" and parse it into "file.c" and the list -# "opt1;opt2;opt3" +# "opt1 opt2 opt3" function(io1_parse_file_options str out_file out_options) if("${str}" MATCHES "^(.*):(.*)$") if ("${CMAKE_MATCH_1}" STREQUAL "") message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: ignored orphaned source option '${CMAKE_MATCH_2}'.") else() - set(${out_file} - "${CMAKE_MATCH_1}" - PARENT_SCOPE) + set(${out_file} "${CMAKE_MATCH_1}" PARENT_SCOPE) if("${CMAKE_MATCH_2}" STREQUAL "") - unset(${out_options} - PARENT_SCOPE) + unset(${out_options} PARENT_SCOPE) else() string(REPLACE "," ";" temp_out_options "${CMAKE_MATCH_2}") - set(${out_options} - "${temp_out_options}" - PARENT_SCOPE) + set(${out_options} "${temp_out_options}" PARENT_SCOPE) endif() endif() else() - set(${out_file} - "${str}" - PARENT_SCOPE - ) - unset(${out_options} - PARENT_SCOPE - ) + set(${out_file} "${str}" PARENT_SCOPE) + unset(${out_options} PARENT_SCOPE) endif() endfunction() diff --git a/test/add_source_file.cmake b/test/add_source_file.cmake index 76899a6..0db2150 100644 --- a/test/add_source_file.cmake +++ b/test/add_source_file.cmake @@ -6,7 +6,7 @@ function(${CMAKETEST_TEST}) project(foo LANGUAGES CXX) add_library(foo STATIC) - io1_add_source_file(foo "foo/main.cpp" "") + io1_add_source_file(foo "foo/main.cpp" "" "") get_target_property(prop foo SOURCES) ct_assert_equal(prop "foo/main.cpp") # main.cpp was added to sources @@ -25,7 +25,7 @@ function(${CMAKETEST_TEST}) project(foo_header LANGUAGES CXX) add_library(foo_header STATIC "foo_header/main.cpp") - io1_add_source_file(foo_header "foo_header/header.cpp" "header") + io1_add_source_file(foo_header "foo_header/header.cpp" "header" "") get_target_property(prop foo_header SOURCES) ct_assert_equal(prop "foo_header/main.cpp;foo_header/header.cpp") # header.cpp was added to sources @@ -43,7 +43,7 @@ function(${CMAKETEST_TEST}) project(foo_cpp LANGUAGES CXX) add_library(foo_cpp STATIC) - io1_add_source_file(foo_cpp "foo_cpp/main.c" "cpp") + io1_add_source_file(foo_cpp "foo_cpp/main.c" "cpp" "") get_target_property(prop foo_cpp SOURCES) ct_assert_equal(prop "foo_cpp/main.c") # main.c was added to sources @@ -62,7 +62,7 @@ function(${CMAKETEST_TEST}) project(foo_cpp_header LANGUAGES CXX) add_library(foo_cpp_header STATIC foo_cpp_header/main.cpp) - io1_add_source_file(foo_cpp_header "foo_cpp_header/header.c" "cpp;header") + io1_add_source_file(foo_cpp_header "foo_cpp_header/header.c" "cpp;header" "") get_target_property(prop foo_cpp_header SOURCES) ct_assert_equal(prop "foo_cpp_header/main.cpp;foo_cpp_header/header.c") # header.c was added to sources @@ -81,7 +81,7 @@ function(${CMAKETEST_TEST}) project(foo_header_cpp LANGUAGES CXX) add_library(foo_header_cpp STATIC foo_header_cpp/main.cpp) - io1_add_source_file(foo_header_cpp "foo_header_cpp/header.c" "header;cpp") + io1_add_source_file(foo_header_cpp "foo_header_cpp/header.c" "header;cpp" "") get_target_property(prop foo_header_cpp SOURCES) ct_assert_equal(prop "foo_header_cpp/main.cpp;foo_header_cpp/header.c") # header.c was added to sources