]> git.feebdaed.xyz Git - 0xmirror/SOEM.git/commitdiff
CMakeLists.txt: Add possibility to build library as shared
authorMatthias Schoepfer <msc@fp-robotics.com>
Wed, 31 Jul 2024 15:36:30 +0000 (17:36 +0200)
committerHans-Erik Floryd <hans-erik.floryd@rt-labs.com>
Tue, 11 Mar 2025 18:44:21 +0000 (19:44 +0100)
This adds the option to build the soem library also as shared object.
Note that the default is untouched, so by default, it will still build
a static library.

The [BUILD_SHARED_LIBS](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html)
is the standard way of doing it, many tools use this semantics to influence
the output to be the desired type (whichever you want).

Signed-off-by: Matthias Schoepfer <matthias.schoepfer@googlemail.com>
CMakeLists.txt

index f9f67ab65b2ae125859c4ac0e630ac74627f0b56..bf30105eddb26d38ac6655aa78917ea2e63e7299 100644 (file)
@@ -10,6 +10,8 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
   set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/install)
 endif()
 
+option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
+
 set(SOEM_INCLUDE_INSTALL_DIR include/soem)
 set(SOEM_LIB_INSTALL_DIR lib)
 
@@ -75,11 +77,16 @@ file(GLOB SOEM_HEADERS soem/*.h)
 file(GLOB OSAL_HEADERS osal/osal.h osal/${OS}/*.h)
 file(GLOB OSHW_HEADERS oshw/${OS}/*.h)
 
-add_library(soem STATIC
+add_library(soem
   ${SOEM_SOURCES}
   ${OSAL_SOURCES}
   ${OSHW_SOURCES}
   ${OSHW_EXTRA_SOURCES})
+
+if (BUILD_SHARED_LIBS)
+  set_target_properties(soem PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})
+endif(BUILD_SHARED_LIBS)
+
 target_link_libraries(soem ${OS_LIBS})
 
 target_include_directories(soem PUBLIC