feat: separate pure C lib to a standalone cmake target
This commit is contained in:
parent
0ec592a2be
commit
dbd6f6c6b8
|
|
@ -11,6 +11,7 @@ By default, headers are read from `./include/controller/c` and stb from `./src/s
|
|||
## Example
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
conan create . \
|
||||
-o webots-controller/*:no_plugins=True
|
||||
```
|
||||
|
|
|
|||
16
conanfile.py
16
conanfile.py
|
|
@ -61,5 +61,17 @@ class WebotsControllerConan(ConanFile):
|
|||
copy(self, "LICENSE", src=self.source_folder, dst=f"{self.package_folder}/licenses")
|
||||
|
||||
def package_info(self):
|
||||
self.cpp_info.libs = ["webots_cpp_controller", "webots_controller"]
|
||||
self.cpp_info.includedirs = ["include", "include/controller/cpp", "include/controller/c"]
|
||||
self.cpp_info.set_property("cmake_file_name", "webots-controller")
|
||||
self.cpp_info.set_property("cmake_target_name", "webots-controller::webots-controller")
|
||||
self.cpp_info.requires = ["CppController"]
|
||||
|
||||
controller = self.cpp_info.components["Controller"]
|
||||
controller.libs = ["webots_controller"]
|
||||
controller.includedirs = ["include", "include/controller/c"]
|
||||
controller.set_property("cmake_target_name", "webots-controller::Controller")
|
||||
|
||||
cpp_controller = self.cpp_info.components["CppController"]
|
||||
cpp_controller.libs = ["webots_cpp_controller"]
|
||||
cpp_controller.includedirs = ["include", "include/controller/cpp", "include/controller/c"]
|
||||
cpp_controller.requires = ["Controller"]
|
||||
cpp_controller.set_property("cmake_target_name", "webots-controller::CppController")
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ endif()
|
|||
# cmake.
|
||||
add_library(webots_controller ${WEBOTS_CONTROLLER_C_SOURCES})
|
||||
add_library(webots-controller::webots_controller ALIAS webots_controller)
|
||||
add_library(webots-controller::Controller ALIAS webots_controller)
|
||||
|
||||
target_sources(
|
||||
webots_controller
|
||||
|
|
@ -136,7 +137,11 @@ if(UNIX)
|
|||
endif()
|
||||
|
||||
install(
|
||||
TARGETS webots_controller FILE_SET webots_c_headers
|
||||
TARGETS webots_controller
|
||||
RUNTIME DESTINATION "bin"
|
||||
LIBRARY DESTINATION "lib"
|
||||
ARCHIVE DESTINATION "lib"
|
||||
FILE_SET webots_c_headers
|
||||
DESTINATION "include/controller/c"
|
||||
FILE_SET webots_plugin_headers
|
||||
DESTINATION "include")
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ file(GLOB_RECURSE WEBOTS_CONTROLLER_CPP_PUBLIC_HEADERS CONFIGURE_DEPENDS
|
|||
add_library(webots_cpp_controller ${WEBOTS_CONTROLLER_CPP_SOURCES})
|
||||
add_library(webots-controller::webots_cpp_controller ALIAS
|
||||
webots_cpp_controller)
|
||||
add_library(webots-controller::CppController ALIAS webots_cpp_controller)
|
||||
add_library(webots-controller::webots-controller ALIAS webots_cpp_controller)
|
||||
|
||||
target_sources(
|
||||
webots_cpp_controller
|
||||
|
|
@ -67,5 +69,9 @@ target_link_libraries(webots_cpp_controller PUBLIC webots_controller)
|
|||
|
||||
install(
|
||||
TARGETS webots_cpp_controller
|
||||
RUNTIME DESTINATION "bin"
|
||||
LIBRARY DESTINATION "lib"
|
||||
ARCHIVE DESTINATION "lib"
|
||||
# `include "../../c/webots/types.h"` in `Robot.hpp`
|
||||
FILE_SET webots_cpp_headers DESTINATION "include/controller/cpp")
|
||||
FILE_SET webots_cpp_headers
|
||||
DESTINATION "include/controller/cpp")
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
cmake_minimum_required(VERSION 3.21)
|
||||
project(test_package CXX)
|
||||
project(test_package C CXX)
|
||||
|
||||
find_package(webots-controller REQUIRED CONFIG)
|
||||
|
||||
add_executable(test_package test_package.cpp)
|
||||
target_link_libraries(test_package PRIVATE webots-controller::webots-controller)
|
||||
target_link_libraries(test_package PRIVATE webots-controller::CppController)
|
||||
|
||||
add_executable(test_package_c test_package.c)
|
||||
target_link_libraries(test_package_c PRIVATE webots-controller::Controller)
|
||||
|
||||
if(POLICY CMP0207)
|
||||
cmake_policy(SET CMP0207 NEW)
|
||||
|
|
@ -23,7 +26,8 @@ endif()
|
|||
# Webots controllers rely on seeing shared deps in the same directory as the
|
||||
# executable. Destination therefore change to "."
|
||||
install(
|
||||
TARGETS test_package RUNTIME_DEPENDENCY_SET test_package_runtime_deps
|
||||
TARGETS test_package test_package_c RUNTIME_DEPENDENCY_SET
|
||||
test_package_runtime_deps
|
||||
RUNTIME DESTINATION .
|
||||
LIBRARY DESTINATION .
|
||||
ARCHIVE DESTINATION .)
|
||||
|
|
|
|||
|
|
@ -27,4 +27,5 @@ class TestPackageConan(ConanFile):
|
|||
if can_run(self):
|
||||
exe = os.path.join(self.source_folder, "test_package")
|
||||
self.run(exe, env="conanrun")
|
||||
|
||||
exe = os.path.join(self.source_folder, "test_package_c")
|
||||
self.run(exe, env="conanrun")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
#include <webots/robot.h>
|
||||
|
||||
int main(void) {
|
||||
double (*c_symbol)(void) = &wb_robot_get_time;
|
||||
(void)c_symbol;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue