libcr51sign: build: Refactor for subproject use
This refactors the build to make it more suitable for use as a
subproject in other OpenBMC codebases.
Change-Id: I546c993d3f53c1cbe2161e5d8959373d5b12e57f
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/subprojects/libcr51sign/cr51_image_descriptor.h b/subprojects/libcr51sign/include/libcr51sign/cr51_image_descriptor.h
similarity index 100%
rename from subprojects/libcr51sign/cr51_image_descriptor.h
rename to subprojects/libcr51sign/include/libcr51sign/cr51_image_descriptor.h
diff --git a/subprojects/libcr51sign/libcr51sign.h b/subprojects/libcr51sign/include/libcr51sign/libcr51sign.h
similarity index 100%
rename from subprojects/libcr51sign/libcr51sign.h
rename to subprojects/libcr51sign/include/libcr51sign/libcr51sign.h
diff --git a/subprojects/libcr51sign/libcr51sign_support.h b/subprojects/libcr51sign/include/libcr51sign/libcr51sign_support.h
similarity index 100%
rename from subprojects/libcr51sign/libcr51sign_support.h
rename to subprojects/libcr51sign/include/libcr51sign/libcr51sign_support.h
diff --git a/subprojects/libcr51sign/include/meson.build b/subprojects/libcr51sign/include/meson.build
new file mode 100644
index 0000000..fc9ec3a
--- /dev/null
+++ b/subprojects/libcr51sign/include/meson.build
@@ -0,0 +1,20 @@
+# Copyright 2021 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+libcr51sign_includes = include_directories('.')
+
+install_subdir(
+ 'libcr51sign',
+ install_dir: get_option('includedir'),
+ strip_directory: false)
diff --git a/subprojects/libcr51sign/meson.build b/subprojects/libcr51sign/meson.build
index a96a204..66f77f0 100644
--- a/subprojects/libcr51sign/meson.build
+++ b/subprojects/libcr51sign/meson.build
@@ -12,39 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-project('libcr51sign', 'c',
- version: '0.1', meson_version: '>=0.57.0',
- default_options: [
- 'warning_level=2',
- 'werror=false',
- 'cpp_std=c++20'
- ])
-
-# libssl part of openssl isn't used.
-openssl = dependency('libcrypto')
-
-libcr51sign_headers = include_directories('.')
-
-libcr51sign_lib = library(
+project(
'libcr51sign',
- 'libcr51sign.c',
- 'libcr51sign_support.c',
- include_directories: libcr51sign_headers,
- dependencies: openssl,
- implicit_include_directories: false,
- version: meson.project_version(),
- install: true)
+ 'c',
+ version: '0.1',
+ meson_version: '>=0.57.0',
+ default_options: [
+ 'warning_level=3',
+ 'werror=false',
+ 'c_std=c18',
+ ])
-pkg = import('pkgconfig')
-pkg.generate(
- libcr51sign_lib,
- name: 'libcr51sign',
- description: 'CR51 signing verification utilities',
- requires: openssl,
- version: meson.project_version())
-
-install_headers(
- 'cr51_image_descriptor.h',
- 'libcr51sign.h',
- 'libcr51sign_support.h',
- subdir: 'libcr51sign')
+subdir('include')
+subdir('src')
diff --git a/subprojects/libcr51sign/libcr51sign.c b/subprojects/libcr51sign/src/libcr51sign.c
similarity index 99%
rename from subprojects/libcr51sign/libcr51sign.c
rename to subprojects/libcr51sign/src/libcr51sign.c
index 7d2e1bb..9bd86b9 100644
--- a/subprojects/libcr51sign/libcr51sign.c
+++ b/subprojects/libcr51sign/src/libcr51sign.c
@@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "libcr51sign.h"
-
#include <assert.h>
+#include <libcr51sign/libcr51sign.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/subprojects/libcr51sign/libcr51sign_support.c b/subprojects/libcr51sign/src/libcr51sign_support.c
similarity index 99%
rename from subprojects/libcr51sign/libcr51sign_support.c
rename to subprojects/libcr51sign/src/libcr51sign_support.c
index 3c968d3..81f05c5 100644
--- a/subprojects/libcr51sign/libcr51sign_support.c
+++ b/subprojects/libcr51sign/src/libcr51sign_support.c
@@ -13,8 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "libcr51sign_support.h"
-
+#include <libcr51sign/libcr51sign_support.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
diff --git a/subprojects/libcr51sign/src/meson.build b/subprojects/libcr51sign/src/meson.build
new file mode 100644
index 0000000..e85e65c
--- /dev/null
+++ b/subprojects/libcr51sign/src/meson.build
@@ -0,0 +1,48 @@
+# Copyright 2021 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+libcr51sign_deps = [
+ dependency('libcrypto'),
+]
+
+libcr51sign_pre = declare_dependency(
+ include_directories: libcr51sign_includes,
+ dependencies: libcr51sign_deps)
+
+libcr51sign_lib = library(
+ 'cr51sign',
+ 'libcr51sign.c',
+ 'libcr51sign_support.c',
+ dependencies: libcr51sign_pre,
+ implicit_include_directories: false,
+ version: meson.project_version(),
+ install: true)
+
+libcr51sign_dep = declare_dependency(
+ link_with: libcr51sign_lib,
+ dependencies: libcr51sign_pre)
+
+libcr51sign_reqs = []
+foreach dep : libcr51sign_deps
+ if dep.type_name() == 'pkgconfig'
+ libcr51sign_reqs += dep
+ endif
+endforeach
+
+import('pkgconfig').generate(
+ libcr51sign_lib,
+ name: 'libcr51sign',
+ description: 'CR51 signing verification utilities',
+ requires: libcr51sign_reqs,
+ version: meson.project_version())