From 453fb234beb65872494435f1464e3935914bbdc2 Mon Sep 17 00:00:00 2001 From: Artemis Everfree Date: Sat, 22 Jul 2023 01:16:05 -0700 Subject: [PATCH 1/3] support switching between dynamic/static kdlpp lib --- bindings/cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/cpp/CMakeLists.txt b/bindings/cpp/CMakeLists.txt index d2ea9cd..02dae5d 100644 --- a/bindings/cpp/CMakeLists.txt +++ b/bindings/cpp/CMakeLists.txt @@ -40,7 +40,7 @@ if(BUILD_KDLPP) src/kdlpp.cpp ) - add_library(kdlpp STATIC ${KDLPP_CXX_SOURCES}) + add_library(kdlpp ${KDLPP_CXX_SOURCES}) target_compile_options(kdlpp PRIVATE ${KDL_COMPILE_OPTIONS}) target_include_directories(kdlpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(kdlpp PUBLIC kdl) From 9d5a1bbd885474db638cfc47de52e853733b7316 Mon Sep 17 00:00:00 2001 From: Thomas Jollans Date: Fri, 1 Sep 2023 18:45:27 +0200 Subject: [PATCH 2/3] Allow kdlpp to be built as DLL --- bindings/cpp/CMakeLists.txt | 8 ++++++++ bindings/cpp/include/kdlpp.h | 24 +++++++++++++++++++----- bindings/cpp/tests/CMakeLists.txt | 4 ++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/bindings/cpp/CMakeLists.txt b/bindings/cpp/CMakeLists.txt index 02dae5d..be7d731 100644 --- a/bindings/cpp/CMakeLists.txt +++ b/bindings/cpp/CMakeLists.txt @@ -41,10 +41,18 @@ if(BUILD_KDLPP) ) add_library(kdlpp ${KDLPP_CXX_SOURCES}) + target_compile_options(kdlpp PRIVATE ${KDL_COMPILE_OPTIONS}) + target_compile_definitions(kdlpp PRIVATE BUILDING_KDLPP=1) + target_include_directories(kdlpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(kdlpp PUBLIC kdl) target_compile_features(kdlpp PUBLIC cxx_std_20) + + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(kdlpp PUBLIC KDLPP_STATIC_LIB=1) + endif() + install(TARGETS kdlpp COMPONENT libkdlpp) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/kdlpp.h TYPE INCLUDE COMPONENT libkdlpp) diff --git a/bindings/cpp/include/kdlpp.h b/bindings/cpp/include/kdlpp.h index 6ea0c6c..29b795a 100644 --- a/bindings/cpp/include/kdlpp.h +++ b/bindings/cpp/include/kdlpp.h @@ -1,6 +1,20 @@ #ifndef KDLPP_H_ #define KDLPP_H_ +#if defined(_WIN32) +# if defined(KDLPP_STATIC_LIB) +# define KDLPP_EXPORT +# elif defined(BUILDING_KDLPP) +# define KDLPP_EXPORT __declspec(dllexport) +# else +# define KDLPP_EXPORT __declspec(dllimport) +# endif +#elif defined(__GNUC__) && __GNUC__ >= 4 +# define KDLPP_EXPORT __attribute__((visibility("default"))) +#else +# define KDLPP_EXPORT +#endif + #include #include #include @@ -30,7 +44,7 @@ class TypeError : public std::exception { }; // Exception thrown on regular KDL parsing errors -class ParseError : public std::exception { +class KDLPP_EXPORT ParseError : public std::exception { std::string m_msg; public: ParseError(kdl_str const& msg); @@ -57,7 +71,7 @@ enum NumberRepresentation { // A KDL number: could be a long long, a double, or a string // Analogous to kdl_number -class Number { +class KDLPP_EXPORT Number { std::variant m_value; public: @@ -138,7 +152,7 @@ enum class Type { // A KDL value, possibly including a type annotation // Analogous to kdl_value -class Value : public HasTypeAnnotation { +class KDLPP_EXPORT Value : public HasTypeAnnotation { std::variant m_value; public: @@ -311,7 +325,7 @@ class Node : public HasTypeAnnotation { }; // A KDL document - consisting of several nodes. -class Document { +class KDLPP_EXPORT Document { std::vector m_nodes; public: @@ -338,7 +352,7 @@ class Document { }; // Load a KDL document from string -Document parse(std::u8string_view kdl_text); +KDLPP_EXPORT Document parse(std::u8string_view kdl_text); } // namespace kdl diff --git a/bindings/cpp/tests/CMakeLists.txt b/bindings/cpp/tests/CMakeLists.txt index 024de66..2986ee3 100644 --- a/bindings/cpp/tests/CMakeLists.txt +++ b/bindings/cpp/tests/CMakeLists.txt @@ -6,7 +6,7 @@ target_link_libraries(kdlpp_test kdlpp test_util) add_test(kdlpp_test kdlpp_test) if (WIN32 AND BUILD_SHARED_LIBS) - # Copy kdl.dll to the test folder so that the tests work + # Copy kdl.dll and kdlpp.dll to the test folder so that the tests work add_custom_command(TARGET kdlpp_test POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $) + COMMAND ${CMAKE_COMMAND} -E copy $ $ $) endif() From bbd8d7fe9fd5f97c868e89bdcd7d677070089f58 Mon Sep 17 00:00:00 2001 From: Thomas Jollans Date: Fri, 1 Sep 2023 18:53:14 +0200 Subject: [PATCH 3/3] Update docs --- doc/index.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index 918746e..8a4c672 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -89,16 +89,17 @@ of the ``DESTDIR`` environment variable). Dynamic vs static library ^^^^^^^^^^^^^^^^^^^^^^^^^ -The ckdl C library ``libkdl`` supports both dynamic linking and static linking. Which option -you want to choose depends on your situation: When using C, C++, or a similar language, static -libraries can be easier to work with, while when using a dynamic runtime a dynamic library -may be your best bet (Python's ctypes and .NET's P/Invoke are examples of technologies that -as good as require the use of a dynamic library). +The ckdl C library ``libkdl`` and the C++ bindings ``libkdlpp`` support both dynamic linking +and static linking. Which option you want to choose depends on your situation: When using C, +C++, or a similar language, static libraries can be easier to work with, while when using a +dynamic runtime a dynamic library may be your best bet (Python's ctypes and .NET's P/Invoke +are examples of technologies that as good as require the use of a dynamic library). .. attention:: On **Windows**, if you're using the static library, and not the DLL, you must define the - macro ``KDL_STATIC_LIB`` before including the ckdl headers, or you'll get linking errors. + macro ``KDL_STATIC_LIB`` before including the ckdl headers, and ``KDLPP_STATIC_LIB`` + before including the kdlpp header, or you'll get linking errors. On UNIX, this is not required, but it can't hurt in portable applications and libraries.