Skip to content

Commit 380d8ca

Browse files
authored
add build option to control shared/static build (ompl#1331)
* add build option to control shared/static build
1 parent 6c12590 commit 380d8ca

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ endif()
153153
# R is needed for running Planner Arena locally
154154
find_program(R_EXEC R)
155155

156+
# default to building shared libs except Windows
157+
if (MSVC)
158+
option(OMPL_BUILD_SHARED "Build OMPL as a shared library" OFF)
159+
else()
160+
option(OMPL_BUILD_SHARED "Build OMPL as a shared library" ON)
161+
endif()
156162
add_subdirectory(src)
157163
add_subdirectory(py-bindings)
158164

doc/markdown/buildOptions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ If you are building OMPL from source, there are several options that you can use
77
| OMPL_BUILD_DEMOS | ON | Compile the OMPL demo programs. (The binaries are never installed.) |
88
| OMPL_BUILD_PYBINDINGS | ON | Whether to compile the Python bindings (requires Py++). |
99
| OMPL_BUILD_PYTESTS | ON | Whether the Python tests should be added to the `test` target. |
10+
| OMPL_BUILD_SHARED | ON | Whether the OMPL library should be a static or dynamic library (the default on Windows is to build a static library)
1011
| OMPL_BUILD_TESTS | ON | Wether to compile the C++ unit tests |
1112
| OMPL_BUILD_VAMP | ON | Build VAMP (Vector-Accelerated Motion Planning) submodule for enhanced collision checking performance. |
1213
| OMPL_REGISTRATION | ON | Whether the registration page is shown. (Disabling it might be useful for build bots.) |

src/ompl/CMakeLists.txt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ source_group("OMPL Source" FILES "${OMPL_SOURCE_CODE}")
3434
source_group("OMPL Headers" FILES "${OMPL_HEADERS}")
3535

3636
# build the library
37-
if(MSVC)
38-
add_library(ompl STATIC ${OMPL_SOURCE_CODE})
39-
else()
37+
if(OMPL_BUILD_SHARED)
4038
add_library(ompl SHARED ${OMPL_SOURCE_CODE})
39+
else()
40+
add_library(ompl STATIC ${OMPL_SOURCE_CODE})
4141
endif()
4242
add_library(ompl::ompl ALIAS ompl)
4343
target_link_libraries(ompl
@@ -50,18 +50,24 @@ target_link_libraries(ompl
5050
PRIVATE
5151
"$<$<BOOL:${OMPL_HAVE_SPOT}>:Spot::Spot>")
5252

53-
if (MSVC)
54-
set_target_properties(ompl PROPERTIES VERSION "${PROJECT_VERSION}" STATIC_LIBRARY_FLAGS "psapi.lib ws2_32.lib")
55-
else (MSVC)
53+
set_target_properties(ompl PROPERTIES VERSION "${PROJECT_VERSION}")
54+
55+
if (OMPL_BUILD_SHARED)
56+
set_target_properties(ompl PROPERTIES SOVERSION "${OMPL_ABI_VERSION}")
5657
if (MINGW)
5758
target_link_libraries(ompl psapi ws2_32)
5859
set_target_properties(ompl PROPERTIES LINK_FLAGS "-Wl,--export-all-symbols")
59-
endif (MINGW)
60-
set_target_properties(ompl PROPERTIES VERSION "${PROJECT_VERSION}" SOVERSION "${OMPL_ABI_VERSION}")
61-
endif (MSVC)
60+
endif()
61+
else()
62+
if (MSVC)
63+
set_target_properties(ompl PROPERTIES STATIC_LIBRARY_FLAGS "psapi.lib ws2_32.lib")
64+
elseif (MINGW)
65+
target_link_libraries(ompl psapi ws2_32)
66+
endif()
67+
endif()
6268

63-
if (NOT MSVC)
69+
if (OMPL_BUILD_SHARED)
6470
add_custom_command(TARGET ompl POST_BUILD
6571
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:ompl>"
6672
"${CMAKE_CURRENT_SOURCE_DIR}/../../py-bindings/ompl/util/libompl${CMAKE_SHARED_LIBRARY_SUFFIX}")
67-
endif (NOT MSVC)
73+
endif (OMPL_BUILD_SHARED)

0 commit comments

Comments
 (0)