diff --git a/README.md b/README.md index fd98b5f..341e0e1 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/conanfile.py b/conanfile.py index a7a2cb7..30d2b1c 100644 --- a/conanfile.py +++ b/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") diff --git a/src/controller/c/CMakeLists.txt b/src/controller/c/CMakeLists.txt index 115a35a..23b647e 100644 --- a/src/controller/c/CMakeLists.txt +++ b/src/controller/c/CMakeLists.txt @@ -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 - DESTINATION "include/controller/c" - FILE_SET webots_plugin_headers - DESTINATION "include") + 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") diff --git a/src/controller/cpp/CMakeLists.txt b/src/controller/cpp/CMakeLists.txt index 0634c2e..8b2306a 100644 --- a/src/controller/cpp/CMakeLists.txt +++ b/src/controller/cpp/CMakeLists.txt @@ -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") diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 70ed1a3..8a05374 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -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 .) diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 469583d..6bbc624 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -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") diff --git a/test_package/test_package.c b/test_package/test_package.c new file mode 100644 index 0000000..29854f5 --- /dev/null +++ b/test_package/test_package.c @@ -0,0 +1,7 @@ +#include + +int main(void) { + double (*c_symbol)(void) = &wb_robot_get_time; + (void)c_symbol; + return 0; +}