feat: update test_package cmake install process

This commit is contained in:
insleker 2026-05-20 21:30:35 +08:00
parent c25f13adb4
commit eb5c8024d5
7 changed files with 56 additions and 39 deletions

4
.gitignore vendored
View File

@ -69,5 +69,5 @@ Testing/
.cache/
# user
/CMakeUserPresets.json
**/CMakeUserPresets.json
/test_package/bin

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.21)
project(webots_controller VERSION 0.1.0 LANGUAGES C CXX)
project(webots_controller LANGUAGES C CXX)
option(WEBOTS_CONTROLLER_NO_PLUGINS "Disable runtime plugin loading (dlopen/LoadLibrary paths)." ON)

View File

@ -5,7 +5,7 @@ from conan.tools.files import copy
class WebotsControllerConan(ConanFile):
name = "webots-controller"
version = "0.1.0"
version = "r2025a"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
@ -20,7 +20,7 @@ class WebotsControllerConan(ConanFile):
"no_plugins": True,
}
exports_sources = "CMakeLists.txt", "src/*", "LICENSE", "README.md"
exports_sources = "CMakeLists.txt", "src/*", "include/*", "LICENSE", "README.md"
def config_options(self):
if self.settings.os == "Windows":
@ -50,3 +50,4 @@ class WebotsControllerConan(ConanFile):
def package_info(self):
self.cpp_info.libs = ["webots_cpp_controller", "webots_controller"]
self.cpp_info.includedirs = ["include/controller/cpp", "include/controller/c"]

View File

@ -91,14 +91,15 @@ if(WIN32)
endif()
target_include_directories(webots_controller
PUBLIC
$<BUILD_INTERFACE:${WEBOTS_HEADERS_ROOT}>
$<INSTALL_INTERFACE:include/controller/c>
PRIVATE
${WEBOTS_HEADERS_ROOT}
${WEBOTS_INCLUDE_ROOT}
${WEBOTS_STB_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(webots_controller PRIVATE LIBCONTROLLER_VERSION="custom")
target_compile_definitions(webots_controller PRIVATE LIBCONTROLLER_VERSION="R2025a")
if(WEBOTS_CONTROLLER_NO_PLUGINS)
target_compile_definitions(webots_controller PUBLIC WEBOTS_CONTROLLER_NO_PLUGINS=1)
endif()
@ -114,3 +115,4 @@ if(UNIX)
endif()
install(TARGETS webots_controller)
install(DIRECTORY "${WEBOTS_HEADERS_ROOT}/webots" DESTINATION "include/controller/c")

View File

@ -44,9 +44,9 @@ if(WIN32)
endif()
target_include_directories(webots_cpp_controller
PRIVATE
${CMAKE_SOURCE_DIR}/include/controller/c
${CMAKE_SOURCE_DIR}/include/controller/cpp
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/controller/cpp>
$<INSTALL_INTERFACE:include/controller/cpp>
)
target_link_libraries(webots_cpp_controller
@ -55,3 +55,4 @@ target_link_libraries(webots_cpp_controller
)
install(TARGETS webots_cpp_controller)
install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/controller/cpp/webots" DESTINATION "include/controller/cpp")

View File

@ -1,15 +1,25 @@
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.21)
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)
target_link_libraries(test_package PRIVATE webots-controller::webots-controller)
if(POLICY CMP0207)
cmake_policy(SET CMP0207 NEW)
endif()
set(_extra_runtime_dirs)
if(CMAKE_PREFIX_PATH)
foreach(prefix IN LISTS CMAKE_PREFIX_PATH)
list(APPEND _extra_runtime_dirs "${prefix}/lib")
endforeach()
endif()
if(WIN32 AND DEFINED ENV{MINGW_HOME})
list(APPEND _extra_runtime_dirs "$ENV{MINGW_HOME}/bin")
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
@ -18,29 +28,30 @@ install(TARGETS test_package
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
set(_runtime_dep_pre_excludes
"^api-ms-win-.*"
"^ext-ms-.*"
POST_EXCLUDE_REGEXES
"^ext-ms-.*")
set(_runtime_dep_post_excludes
".*/system32/.*"
".*/Windows/.*"
".*/SysWOW64/.*"
DESTINATION bin)
".*/SysWOW64/.*")
else()
set(_runtime_dep_pre_excludes
[[libc\.so\..*]]
[[libgcc_s\.so\..*]]
[[libm\.so\..*]]
[[libstdc\+\+\.so\..*]]
[[ld-linux-x86-64\.so\..*]])
set(_runtime_dep_post_excludes
[[^/lib.*]]
[[^/usr/lib.*]])
endif()
install(
RUNTIME_DEPENDENCY_SET test_package_runtime_deps
DESTINATION bin)
endif()
PRE_EXCLUDE_REGEXES ${_runtime_dep_pre_excludes}
POST_EXCLUDE_REGEXES ${_runtime_dep_post_excludes}
DIRECTORIES
${CONAN_RUNTIME_LIB_DIRS}
${CMAKE_SYSROOT}/lib
${_extra_runtime_dirs})

View File

@ -21,8 +21,10 @@ class TestPackageConan(ConanFile):
cmake.build()
def test(self):
# check if RUNTIME_DEPENDENCY_SET work
cmake = CMake(self)
cmake.install()
if can_run(self):
exe = os.path.join(self.source_folder, "bin", "test_package")
self.run(exe, env="conanrun")