feat: add cpp controller build support
This commit is contained in:
parent
535f4271a5
commit
c25f13adb4
|
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.21)
|
||||
project(webots_controller VERSION 0.1.0 LANGUAGES C)
|
||||
project(webots_controller VERSION 0.1.0 LANGUAGES C CXX)
|
||||
|
||||
option(WEBOTS_CONTROLLER_NO_PLUGINS "Disable runtime plugin loading (dlopen/LoadLibrary paths)." ON)
|
||||
|
||||
|
|
|
|||
|
|
@ -49,4 +49,4 @@ 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_controller"]
|
||||
self.cpp_info.libs = ["webots_cpp_controller", "webots_controller"]
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
add_subdirectory(c)
|
||||
add_subdirectory(cpp)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
set(WEBOTS_CONTROLLER_CPP_SOURCES
|
||||
Accelerometer.cpp
|
||||
Altimeter.cpp
|
||||
Brake.cpp
|
||||
Camera.cpp
|
||||
Compass.cpp
|
||||
Connector.cpp
|
||||
Device.cpp
|
||||
Display.cpp
|
||||
DistanceSensor.cpp
|
||||
Emitter.cpp
|
||||
Field.cpp
|
||||
GPS.cpp
|
||||
Gyro.cpp
|
||||
InertialUnit.cpp
|
||||
Joystick.cpp
|
||||
Keyboard.cpp
|
||||
LED.cpp
|
||||
Lidar.cpp
|
||||
LightSensor.cpp
|
||||
Motion.cpp
|
||||
Motor.cpp
|
||||
Mouse.cpp
|
||||
Node.cpp
|
||||
Pen.cpp
|
||||
PositionSensor.cpp
|
||||
Proto.cpp
|
||||
Radar.cpp
|
||||
RangeFinder.cpp
|
||||
Receiver.cpp
|
||||
Robot.cpp
|
||||
Skin.cpp
|
||||
Speaker.cpp
|
||||
Supervisor.cpp
|
||||
TouchSensor.cpp
|
||||
VacuumGripper.cpp
|
||||
)
|
||||
|
||||
add_library(webots_cpp_controller ${WEBOTS_CONTROLLER_CPP_SOURCES})
|
||||
add_library(webots-controller::webots_cpp_controller ALIAS webots_cpp_controller)
|
||||
|
||||
if(WIN32)
|
||||
set_target_properties(webots_cpp_controller PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
endif()
|
||||
|
||||
target_include_directories(webots_cpp_controller
|
||||
PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/include/controller/c
|
||||
${CMAKE_SOURCE_DIR}/include/controller/cpp
|
||||
)
|
||||
|
||||
target_link_libraries(webots_cpp_controller
|
||||
PUBLIC
|
||||
webots_controller
|
||||
)
|
||||
|
||||
install(TARGETS webots_cpp_controller)
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
project(test_package CXX)
|
||||
|
||||
find_package(webots-controller REQUIRED CONFIG)
|
||||
|
||||
add_executable(test_package test_package.cpp)
|
||||
target_link_libraries(test_package PRIVATE Webots::CppController Webots::Controller)
|
||||
|
||||
if(POLICY CMP0207)
|
||||
cmake_policy(SET CMP0207 NEW)
|
||||
endif()
|
||||
|
||||
# Webots controllers rely on seeing shared deps in the same directory as the executable.
|
||||
install(TARGETS test_package
|
||||
RUNTIME_DEPENDENCY_SET test_package_runtime_deps
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
if(WIN32)
|
||||
# for single-config generators.
|
||||
set(_runtime_dependency_directories)
|
||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" _conan_build_type)
|
||||
set(_webots_bin_dirs_var "webots-controller_BIN_DIRS_${_conan_build_type}")
|
||||
if(DEFINED ${_webots_bin_dirs_var})
|
||||
list(APPEND _runtime_dependency_directories ${${_webots_bin_dirs_var}})
|
||||
endif()
|
||||
if(DEFINED ENV{MINGW_HOME})
|
||||
list(APPEND _runtime_dependency_directories "$ENV{MINGW_HOME}/bin")
|
||||
endif()
|
||||
install(
|
||||
RUNTIME_DEPENDENCY_SET test_package_runtime_deps
|
||||
DIRECTORIES ${_runtime_dependency_directories}
|
||||
PRE_EXCLUDE_REGEXES
|
||||
"^api-ms-win-.*"
|
||||
"^ext-ms-.*"
|
||||
POST_EXCLUDE_REGEXES
|
||||
".*/system32/.*"
|
||||
".*/Windows/.*"
|
||||
".*/SysWOW64/.*"
|
||||
DESTINATION bin)
|
||||
else()
|
||||
install(
|
||||
RUNTIME_DEPENDENCY_SET test_package_runtime_deps
|
||||
DESTINATION bin)
|
||||
endif()
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
from conan import ConanFile
|
||||
from conan.tools.build import can_run
|
||||
from conan.tools.cmake import CMake, cmake_layout
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
test_type = "explicit"
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "CMakeDeps", "CMakeToolchain"
|
||||
|
||||
def requirements(self):
|
||||
self.requires(self.tested_reference_str)
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
cmake = CMake(self)
|
||||
cmake.install()
|
||||
if can_run(self):
|
||||
exe = os.path.join(self.source_folder, "bin", "test_package")
|
||||
self.run(exe, env="conanrun")
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#include <webots/Robot.hpp>
|
||||
#include <webots/robot.h>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
auto cpp_symbol = &webots::Robot::getBasicTimeStep;
|
||||
auto c_symbol = &wb_robot_get_time;
|
||||
(void)cpp_symbol;
|
||||
(void)c_symbol;
|
||||
std::cout << "Success!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue