Repository: mesonbuild/meson

Issue:
CMake: missing linking args in the generated meson.build for libarchive
**Describe the bug**
When I try to use a static version of [libarchive](https://github.com/libarchive/libarchive) as a subproject, the linking of the main project fails because of undefined references.

**To Reproduce**
1. Declare a subproject in the main meson.build:
```
cmake_mod = import('cmake')
libarchive_dep = dependency('libarchive', version: '>= 3.4.0', required: false)
if not libarchive_dep.found()
    libarchive_dep = cmake_mod.subproject('libarchive', cmake_options: [
        '-DCMAKE_BUILD_TYPE=Release',
        '-DCMAKE_INSTALL_LIBDIR=lib',
        '-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
        '-DENABLE_TEST=OFF',
        '-DENABLE_TAR=OFF',
        '-DENABLE_CPIO=OFF',
        '-DENABLE_CAT=OFF',
        '-DENABLE_LIBXML2=OFF'
    ]).dependency('archive_static')
endif
```
2. Check the [CMakeList.txt](https://github.com/libarchive/libarchive/blob/master/libarchive/CMakeLists.txt) of libarchive:
```CMake
# Libarchive is a shared library
ADD_LIBRARY(archive SHARED ${libarchive_SOURCES} ${include_HEADERS})
TARGET_INCLUDE_DIRECTORIES(archive PUBLIC .)
TARGET_LINK_LIBRARIES(archive ${ADDITIONAL_LIBS})
SET_TARGET_PROPERTIES(archive PROPERTIES SOVERSION ${SOVERSION})

# archive_static is a static library
ADD_LIBRARY(archive_static STATIC ${libarchive_SOURCES} ${include_HEADERS})
TARGET_LINK_LIBRARIES(archive_static ${ADDITIONAL_LIBS})
SET_TARGET_PROPERTIES(archive_static PROPERTIES COMPILE_DEFINITIONS
  LIBARCHIVE_STATIC)
```
3. Get the following declarations in the subprojects/libarchive-3.4.3/meson.build after configuration:
```Meson
cm_archive = shared_library(
  'cm_archive',
  [cm_archive_src],
  build_by_default : true,
  link_args : [
    '-lz',
    '-lbz2',
    '-llzma',
    '-llz4',
    '-lzstd',
    '-lcrypto',
    '-lexpat',
    '-lacl',
    '-lssl'
  ],
  link_with : [],
  include_directories : cm_archive_inc,
  install : true,
  install_dir : 'lib',
  override_options : [],
  objects : [],
  c_args : [
    '-Wformat',
    '-Wformat-security',
    '-O3',
    '-DNDEBUG',
    '-DHAVE_CONFIG_H',
    '-Darchive_EXPORTS'
  ]
)
cm_archive_static = static_library(
  'cm_archive_static',
  [cm_archive_static_src],
  build_by_default : true,
  link_args : [],
  link_with : [],
  include_directories : cm_archive_static_inc,
  install : true,
  install_dir : 'lib',
  override_options : [],
  objects : [],
  c_args : [
    '-Wformat',
    '-Wformat-security',
    '-O3',
    '-DNDEBUG',
    '-DHAVE_CONFIG_H',
    '-DLIBARCHIVE_STATIC'
  ],
  pic : true
)
```
4. The target 'cm_archive_static' has empty link_args field despite of `
TARGET_LINK_LIBRARIES(archive_static ${ADDITIONAL_LIBS})`, so linking fails with undefined references.

**Expected behavior**
The project should be built without errors.

**system parameters**
* Native build
* Archlinux
* Python 3.8.3
* Meson 0.54.2
* Ninja 1.10.0



Discussion:

Resolving patch:
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
--- a/mesonbuild/cmake/interpreter.py
+++ b/mesonbuild/cmake/interpreter.py
@@ -355,7 +355,7 @@ def postprocess(self, output_target_map: OutputTargetMap, root_src_dir: str, sub
                 if 'CONFIGURATIONS' in tgt.properties:
                     cfgs += [x for x in tgt.properties['CONFIGURATIONS'] if x]
                     cfg = cfgs[0]
-                
+
                 is_debug = self.env.coredata.get_builtin_option('debug');
                 if is_debug:
                     if 'DEBUG' in cfgs:
diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py
--- a/mesonbuild/cmake/traceparser.py
+++ b/mesonbuild/cmake/traceparser.py
@@ -64,6 +64,7 @@ def strip_properties(self) -> None:
             return
         for key, val in self.properties.items():
             self.properties[key] = [x.strip() for x in val]
+            assert all([';' not in x for x in self.properties[key]])
 
 class CMakeGeneratorTarget(CMakeTarget):
     def __init__(self, name):
@@ -574,10 +575,10 @@ def _parse_common_target_options(self, func: str, private_prop: str, interface_p
                 continue
 
             if mode in ['INTERFACE', 'LINK_INTERFACE_LIBRARIES', 'PUBLIC', 'LINK_PUBLIC']:
-                interface += [i]
+                interface += i.split(';')
 
             if mode in ['PUBLIC', 'PRIVATE', 'LINK_PRIVATE']:
-                private += [i]
+                private += i.split(';')
 
         if paths:
             interface = self._guess_files(interface)


Test patch:
diff --git a/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt
--- a/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt	
+++ b/test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt	
@@ -20,7 +20,7 @@ set_target_properties(cmModLib PROPERTIES VERSION 1.0.1)
 add_executable(testEXE main.cpp)
 
 target_link_libraries(cmModLib       ZLIB::ZLIB)
-target_link_libraries(cmModLibStatic ZLIB::ZLIB)
+target_link_libraries(cmModLibStatic ;ZLIB::ZLIB;)
 target_link_libraries(testEXE cmModLib)
 
 target_compile_definitions(cmModLibStatic PUBLIC CMMODLIB_STATIC_DEFINE)