Skip to content

Commit

Permalink
CMakeLists.txt: Add possibility to build library as shared
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Matthias Schoepfer committed Feb 13, 2025
1 parent 2752dc2 commit 41202bf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -75,11 +77,17 @@ 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})
set_target_properties(soem PROPERTIES SOVERSION ${PROJECT_VERSION})
endif(BUILD_SHARED_LIBS)

target_link_libraries(soem ${OS_LIBS})

target_include_directories(soem PUBLIC
Expand Down

0 comments on commit 41202bf

Please sign in to comment.