build: Split c++ sources into a subdirectory

Change-Id: Iedea50c688189ae4953195105e323f7173d17a4b
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meson.build b/meson.build
index 2b3afba..ce8534a 100644
--- a/meson.build
+++ b/meson.build
@@ -21,9 +21,6 @@
   get_option('default-ipv6-accept-ra'))
 conf_data.set('NIC_SUPPORTS_ETHTOOL', get_option('nic-ethtool'))
 conf_data.set('SYNC_MAC_FROM_INVENTORY', get_option('sync-mac'))
-conf_header = configure_file(
-  output: 'config.h',
-  configuration: conf_data)
 
 sdbusplus_dep = dependency('sdbusplus', required: false)
 if sdbusplus_dep.found()
@@ -36,93 +33,14 @@
   sdbuspp_gen_meson_prog = sdbusplus_proj.get_variable('sdbuspp_gen_meson_prog')
 endif
 
-phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
-phosphor_logging_dep = dependency('phosphor-logging')
-
-generated_sources = [ conf_header ]
+generated_sources = []
 generated_others = []
 yaml_sources = []
 subdir('gen')
 subdir('gen/xyz')
+generated_includes = include_directories('gen')
 
-networkd_headers = include_directories('.', 'gen')
-
-executable(
-  'ncsi-netlink',
-  'argument.cpp',
-  'ncsi_netlink_main.cpp',
-  'ncsi_util.cpp',
-  implicit_include_directories: false,
-  include_directories: networkd_headers,
-  dependencies: [
-    dependency('libnl-3.0'),
-    dependency('libnl-genl-3.0'),
-    phosphor_dbus_interfaces_dep,
-    phosphor_logging_dep,
-  ],
-  install: true,
-  install_dir: get_option('bindir'))
-
-json_dep = declare_dependency()
-if get_option('sync-mac')
-  # nlohmann_json might not have a pkg-config. It is header only so just make
-  # sure we can access the needed symbols from the header.
-  has_json = meson.get_compiler('cpp').has_header_symbol(
-    'nlohmann/json.hpp',
-    'nlohmann::json::string_t',
-    required: false)
-  if not has_json
-    json_dep = dependency(
-      'nlohmann_json',
-      fallback: ['nlohmann_json', 'nlohmann_json_dep'],
-      required: true)
-  endif
-endif
-
-networkd_deps = [
-  json_dep,
-  phosphor_dbus_interfaces_dep,
-  phosphor_logging_dep,
-  sdbusplus_dep,
-  dependency('sdeventplus', fallback: ['sdeventplus', 'sdeventplus_dep']),
-  dependency('stdplus', fallback: ['stdplus', 'stdplus_dep']),
-]
-
-networkd_lib = static_library(
-  'networkd',
-  generated_sources,
-  'ethernet_interface.cpp',
-  'neighbor.cpp',
-  'ipaddress.cpp',
-  'netlink.cpp',
-  'network_config.cpp',
-  'network_manager.cpp',
-  'system_configuration.cpp',
-  'util.cpp',
-  'routing_table.cpp',
-  'config_parser.cpp',
-  'dhcp_configuration.cpp',
-  'vlan_interface.cpp',
-  'rtnetlink_server.cpp',
-  'dns_updater.cpp',
-  'watch.cpp',
-  implicit_include_directories: false,
-  include_directories: networkd_headers,
-  dependencies: networkd_deps)
-
-networkd_dep = declare_dependency(
-  sources: generated_sources,
-  dependencies: networkd_deps,
-  include_directories: networkd_headers,
-  link_with: networkd_lib)
-
-executable(
-  'phosphor-network-manager',
-  'network_manager_main.cpp',
-  implicit_include_directories: false,
-  dependencies: networkd_dep,
-  install: true,
-  install_dir: get_option('bindir'))
+subdir('src')
 
 configure_file(
   input: 'xyz.openbmc_project.Network.service.in',
diff --git a/argument.cpp b/src/argument.cpp
similarity index 100%
rename from argument.cpp
rename to src/argument.cpp
diff --git a/argument.hpp b/src/argument.hpp
similarity index 100%
rename from argument.hpp
rename to src/argument.hpp
diff --git a/config_parser.cpp b/src/config_parser.cpp
similarity index 100%
rename from config_parser.cpp
rename to src/config_parser.cpp
diff --git a/config_parser.hpp b/src/config_parser.hpp
similarity index 100%
rename from config_parser.hpp
rename to src/config_parser.hpp
diff --git a/dhcp_configuration.cpp b/src/dhcp_configuration.cpp
similarity index 100%
rename from dhcp_configuration.cpp
rename to src/dhcp_configuration.cpp
diff --git a/dhcp_configuration.hpp b/src/dhcp_configuration.hpp
similarity index 100%
rename from dhcp_configuration.hpp
rename to src/dhcp_configuration.hpp
diff --git a/dns_updater.cpp b/src/dns_updater.cpp
similarity index 100%
rename from dns_updater.cpp
rename to src/dns_updater.cpp
diff --git a/dns_updater.hpp b/src/dns_updater.hpp
similarity index 100%
rename from dns_updater.hpp
rename to src/dns_updater.hpp
diff --git a/ethernet_interface.cpp b/src/ethernet_interface.cpp
similarity index 100%
rename from ethernet_interface.cpp
rename to src/ethernet_interface.cpp
diff --git a/ethernet_interface.hpp b/src/ethernet_interface.hpp
similarity index 100%
rename from ethernet_interface.hpp
rename to src/ethernet_interface.hpp
diff --git a/ipaddress.cpp b/src/ipaddress.cpp
similarity index 100%
rename from ipaddress.cpp
rename to src/ipaddress.cpp
diff --git a/ipaddress.hpp b/src/ipaddress.hpp
similarity index 100%
rename from ipaddress.hpp
rename to src/ipaddress.hpp
diff --git a/src/meson.build b/src/meson.build
new file mode 100644
index 0000000..31371f9
--- /dev/null
+++ b/src/meson.build
@@ -0,0 +1,94 @@
+phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
+phosphor_logging_dep = dependency('phosphor-logging')
+
+src_includes = include_directories('.')
+
+executable(
+  'ncsi-netlink',
+  'argument.cpp',
+  'ncsi_netlink_main.cpp',
+  'ncsi_util.cpp',
+  implicit_include_directories: false,
+  include_directories: src_includes,
+  dependencies: [
+    dependency('libnl-3.0'),
+    dependency('libnl-genl-3.0'),
+    phosphor_dbus_interfaces_dep,
+    phosphor_logging_dep,
+  ],
+  install: true,
+  install_dir: get_option('bindir'))
+
+json_dep = declare_dependency()
+if get_option('sync-mac')
+  # nlohmann_json might not have a pkg-config. It is header only so just make
+  # sure we can access the needed symbols from the header.
+  has_json = meson.get_compiler('cpp').has_header_symbol(
+    'nlohmann/json.hpp',
+    'nlohmann::json::string_t',
+    required: false)
+  if not has_json
+    json_dep = dependency(
+      'nlohmann_json',
+      fallback: ['nlohmann_json', 'nlohmann_json_dep'],
+      required: true)
+  endif
+endif
+
+networkd_deps = [
+  json_dep,
+  phosphor_dbus_interfaces_dep,
+  phosphor_logging_dep,
+  sdbusplus_dep,
+  dependency('sdeventplus', fallback: ['sdeventplus', 'sdeventplus_dep']),
+  dependency('stdplus', fallback: ['stdplus', 'stdplus_dep']),
+]
+
+conf_header = configure_file(
+  output: 'config.h',
+  configuration: conf_data)
+
+networkd_generated = [
+  conf_header,
+] + generated_sources
+
+networkd_includes = [
+  src_includes,
+  generated_includes,
+]
+
+networkd_lib = static_library(
+  'networkd',
+  networkd_generated,
+  'ethernet_interface.cpp',
+  'neighbor.cpp',
+  'ipaddress.cpp',
+  'netlink.cpp',
+  'network_config.cpp',
+  'network_manager.cpp',
+  'system_configuration.cpp',
+  'util.cpp',
+  'routing_table.cpp',
+  'config_parser.cpp',
+  'dhcp_configuration.cpp',
+  'vlan_interface.cpp',
+  'rtnetlink_server.cpp',
+  'dns_updater.cpp',
+  'watch.cpp',
+  implicit_include_directories: false,
+  include_directories: networkd_includes,
+  dependencies: networkd_deps)
+
+networkd_dep = declare_dependency(
+  sources: networkd_generated,
+  dependencies: networkd_deps,
+  include_directories: networkd_includes,
+  link_with: networkd_lib)
+
+executable(
+  'phosphor-network-manager',
+  'network_manager_main.cpp',
+  implicit_include_directories: false,
+  dependencies: networkd_dep,
+  install: true,
+  install_dir: get_option('bindir'))
diff --git a/ncsi_netlink_main.cpp b/src/ncsi_netlink_main.cpp
similarity index 100%
rename from ncsi_netlink_main.cpp
rename to src/ncsi_netlink_main.cpp
diff --git a/ncsi_util.cpp b/src/ncsi_util.cpp
similarity index 100%
rename from ncsi_util.cpp
rename to src/ncsi_util.cpp
diff --git a/ncsi_util.hpp b/src/ncsi_util.hpp
similarity index 100%
rename from ncsi_util.hpp
rename to src/ncsi_util.hpp
diff --git a/neighbor.cpp b/src/neighbor.cpp
similarity index 100%
rename from neighbor.cpp
rename to src/neighbor.cpp
diff --git a/neighbor.hpp b/src/neighbor.hpp
similarity index 100%
rename from neighbor.hpp
rename to src/neighbor.hpp
diff --git a/netlink.cpp b/src/netlink.cpp
similarity index 100%
rename from netlink.cpp
rename to src/netlink.cpp
diff --git a/netlink.hpp b/src/netlink.hpp
similarity index 100%
rename from netlink.hpp
rename to src/netlink.hpp
diff --git a/network_config.cpp b/src/network_config.cpp
similarity index 100%
rename from network_config.cpp
rename to src/network_config.cpp
diff --git a/network_config.hpp b/src/network_config.hpp
similarity index 100%
rename from network_config.hpp
rename to src/network_config.hpp
diff --git a/network_manager.cpp b/src/network_manager.cpp
similarity index 100%
rename from network_manager.cpp
rename to src/network_manager.cpp
diff --git a/network_manager.hpp b/src/network_manager.hpp
similarity index 100%
rename from network_manager.hpp
rename to src/network_manager.hpp
diff --git a/network_manager_main.cpp b/src/network_manager_main.cpp
similarity index 100%
rename from network_manager_main.cpp
rename to src/network_manager_main.cpp
diff --git a/routing_table.cpp b/src/routing_table.cpp
similarity index 100%
rename from routing_table.cpp
rename to src/routing_table.cpp
diff --git a/routing_table.hpp b/src/routing_table.hpp
similarity index 100%
rename from routing_table.hpp
rename to src/routing_table.hpp
diff --git a/rtnetlink_server.cpp b/src/rtnetlink_server.cpp
similarity index 100%
rename from rtnetlink_server.cpp
rename to src/rtnetlink_server.cpp
diff --git a/rtnetlink_server.hpp b/src/rtnetlink_server.hpp
similarity index 100%
rename from rtnetlink_server.hpp
rename to src/rtnetlink_server.hpp
diff --git a/system_configuration.cpp b/src/system_configuration.cpp
similarity index 100%
rename from system_configuration.cpp
rename to src/system_configuration.cpp
diff --git a/system_configuration.hpp b/src/system_configuration.hpp
similarity index 100%
rename from system_configuration.hpp
rename to src/system_configuration.hpp
diff --git a/types.hpp b/src/types.hpp
similarity index 100%
rename from types.hpp
rename to src/types.hpp
diff --git a/util.cpp b/src/util.cpp
similarity index 100%
rename from util.cpp
rename to src/util.cpp
diff --git a/util.hpp b/src/util.hpp
similarity index 100%
rename from util.hpp
rename to src/util.hpp
diff --git a/vlan_interface.cpp b/src/vlan_interface.cpp
similarity index 100%
rename from vlan_interface.cpp
rename to src/vlan_interface.cpp
diff --git a/vlan_interface.hpp b/src/vlan_interface.hpp
similarity index 100%
rename from vlan_interface.hpp
rename to src/vlan_interface.hpp
diff --git a/watch.cpp b/src/watch.cpp
similarity index 100%
rename from watch.cpp
rename to src/watch.cpp
diff --git a/watch.hpp b/src/watch.hpp
similarity index 100%
rename from watch.hpp
rename to src/watch.hpp