generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from ydcpp/conan
Conan support is added
- Loading branch information
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Installing using conan | ||
## Prerequisites | ||
1- Python 3 | ||
https://www.python.org/downloads/ | ||
|
||
2- Conan package manager | ||
https://docs.conan.io/2/installation.html | ||
|
||
## Build and Install the repo to local system by using conan | ||
1- Navigate to `kubernetes` directory, then use `conan create` command. This will build the repo from source as static library. | ||
``` | ||
cd kubernetes | ||
conan create . --build=missing | ||
``` | ||
|
||
Validate `kubernetes_client_c` package exists by using following command to list all installed packages in local conan cache: | ||
``` | ||
conan list "*" | ||
``` | ||
|
||
## Using kubernetes_client_c library in your project | ||
1- Create `conanfile.py` or `conanfile.txt` file in the root of your project. | ||
|
||
**conanfile.txt** | ||
``` | ||
[requires] | ||
kubernetes_client_c/0.9.0 | ||
[generators] | ||
CMakeDeps | ||
CMakeToolchain | ||
[layout] | ||
cmake_layout | ||
``` | ||
|
||
**conanfile.py** | ||
```python | ||
from conan import ConanFile | ||
from conan.tools.cmake import cmake_layout | ||
|
||
class ExampleRecipe(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "CMakeDeps", "CMakeToolchain" | ||
|
||
def requirements(self): | ||
self.requires("kubernetes_client_c/0.9.0") | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
``` | ||
|
||
2- Use following command (in the root directory of project) to install all dependencies that are specified in the `conanfile`: | ||
``` | ||
conan install . --build=missing | ||
``` | ||
|
||
3- Finally, edit `CMakeLists.txt` of your project to link against libraries. In this case, we link to `kubernetes_client_c` library. | ||
|
||
Add these lines after declaring the target in CMakeLists. | ||
|
||
**CMakeLists.txt** | ||
``` | ||
find_package(kubernetes_client_c) | ||
target_link_libraries(<your_target> kubernetes_client_c::kubernetes_client_c) | ||
``` | ||
|
||
Make sure to edit `<your_target>` with the actual target name. | ||
|
||
4- Example `#include` headers: | ||
```c | ||
#include <kubernetes/api/CoreV1API.h> | ||
#include <kubernetes/model/v1_pod.h> | ||
#include <kubernetes/config/kube_config.h> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps | ||
from conan.tools.files import copy | ||
from os.path import join | ||
|
||
class kubernetes_client_cRecipe(ConanFile): | ||
name = "kubernetes_client_c" | ||
version = "0.9.0" | ||
package_type = "library" | ||
|
||
# Optional metadata | ||
license = "Apache-2.0" | ||
url = "https://github.com/kubernetes-client/c" | ||
description = "Official C client library for Kubernetes" | ||
topics = ("kubernetes", "k8s", "kubernetes-client", "k8s-client") | ||
|
||
# Binary configuration | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = {"shared": [True, False], "fPIC": [True, False], "openssl_shared":[True, False], "curl_version": ["7", "8"]} | ||
default_options = {"shared": False, "fPIC": True, "openssl_shared": True, "curl_version": "8"} | ||
|
||
# Sources are located in the same place as this recipe, copy them to the recipe | ||
exports_sources = "config.h.in", "ConfigureChecks.cmake", "PreTarget.cmake", "PostTarget.cmake", "CMakeLists.txt", "src/*", "external/*", "api/*", "model/*", "include/*", "config/*", "watch/*", "websocket/*" | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
self.options.rm_safe("fPIC") | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
self.options["openssl/*"].shared = self.options.openssl_shared | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def generate(self): | ||
deps = CMakeDeps(self) | ||
deps.generate() | ||
tc = CMakeToolchain(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
copy(self, "*.h", src=join(self.source_folder, "api"), dst=join(self.package_folder, "include/kubernetes/api"), keep_path=False) | ||
copy(self, "*.h", src=join(self.source_folder, "model"), dst=join(self.package_folder, "include/kubernetes/model"), keep_path=False) | ||
copy(self, "*.h", src=join(self.source_folder, "config"), dst=join(self.package_folder, "include/kubernetes/config"), keep_path=False) | ||
copy(self, "*.h", src=join(self.source_folder, "include"), dst=join(self.package_folder, "include/kubernetes/include"), keep_path=False) | ||
copy(self, "*.h", src=join(self.source_folder, "websocket"), dst=join(self.package_folder, "include/kubernetes/websocket"), keep_path=False) | ||
copy(self, "*.h", src=join(self.source_folder, "external"), dst=join(self.package_folder, "include/kubernetes/external"), keep_path=False) | ||
copy(self, "*.h", src=join(self.source_folder, "watch"), dst=join(self.package_folder, "include/kubernetes/watch"), keep_path=False) | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["kubernetes"] | ||
|
||
def requirements(self): | ||
self.requires("libcurl/[~{}]".format(self.options.curl_version), transitive_headers=True) | ||
self.requires("openssl/[^3]", force=True) | ||
self.requires("libwebsockets/[^4.2]", transitive_headers=True) | ||
self.requires("libyaml/[^0.2.5]") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters