Skip to content

Commit

Permalink
Upgrade installer to support cmake linking statically or dynamically …
Browse files Browse the repository at this point in the history
…to Fast-DDS (#107)

* [11561] Add a FASTDDS_STATIC CMake variable to link statically to the binary deployment

* [11561] Addressing reviewer's comments
  • Loading branch information
MiguelBarro authored May 18, 2021
1 parent e194e44 commit f773acf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
10 changes: 9 additions & 1 deletion cmake/packaging/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ endif()
set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(@PROJECT_NAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@")

include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake)
if(FASTDDS_STATIC)
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-static-targets.cmake)
else()
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-dynamic-targets.cmake OPTIONAL RESULT_VARIABLE DYNAMIC_TARGET_FILE)
# fallback to static linking if dynamic target is missing
if( NOT DYNAMIC_TARGET_FILE )
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-static-targets.cmake)
endif()
endif()
19 changes: 4 additions & 15 deletions cmake/packaging/windows/fastcdr-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if(MSVC_VERSION EQUAL 1900)
if(CMAKE_CL_64)
include("${CMAKE_CURRENT_LIST_DIR}/../share/fastcdr-x64Win64VS2015/cmake/fastcdr-config.cmake")
else()
include("${CMAKE_CURRENT_LIST_DIR}/../share/fastcdr-i86Win32VS2015/cmake/fastcdr-config.cmake")
endif()
elseif(MSVC_VERSION LESS 1920)
if(CMAKE_CL_64)
include("${CMAKE_CURRENT_LIST_DIR}/../share/fastcdr-x64Win64VS2017/cmake/fastcdr-config.cmake")
else()
include("${CMAKE_CURRENT_LIST_DIR}/../share/fastcdr-i86Win32VS2017/cmake/fastcdr-config.cmake")
endif()
elseif(MSVC_VERSION GREATER_EQUAL 1920)
if(MSVC_VERSION LESS_EQUAL 1900)
message(FATAL_ERROR "Visual Studio version ${MSVC_VERSION} is no longer supported")
else()
if(CMAKE_CL_64)
include("${CMAKE_CURRENT_LIST_DIR}/../share/fastcdr-x64Win64VS2019/cmake/fastcdr-config.cmake")
else()
include("${CMAKE_CURRENT_LIST_DIR}/../share/fastcdr-i86Win32VS2019/cmake/fastcdr-config.cmake")
endif()
else()
message(FATAL_ERROR "Not supported version of Visual Studio")
endif()

15 changes: 12 additions & 3 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ if(UNIX AND EPROSIMA_INSTALLER)
endif()

# Install libraries

# Generate different target names depending on linking
get_target_property(TARGET_TYPE ${PROJECT_NAME} TYPE)
if(TARGET_TYPE STREQUAL "SHARED_LIBRARY")
set(FASTDDS_LINKING dynamic)
else()
set(FASTDDS_LINKING static)
endif()

if(MSVC OR MSVC_IDE AND EPROSIMA_INSTALLER)
if(IS_TOP_LEVEL)
install_msvc_libraries(i86Win32VS2013)
Expand All @@ -150,22 +159,22 @@ if(MSVC OR MSVC_IDE AND EPROSIMA_INSTALLER)
)
elseif(NOT EPROSIMA_INSTALLER)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
EXPORT ${PROJECT_NAME}-${FASTDDS_LINKING}-targets
RUNTIME DESTINATION ${BIN_INSTALL_DIR}${MSVCARCH_DIR_EXTENSION}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}${MSVCARCH_DIR_EXTENSION}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}${MSVCARCH_DIR_EXTENSION}
COMPONENT libraries${MSVCARCH_EXTENSION}
)

export(TARGETS ${PROJECT_NAME} FILE ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}-targets.cmake)
export(TARGETS ${PROJECT_NAME} FILE ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}-${FASTDDS_LINKING}-targets.cmake)

if(INSTALLER_PLATFORM)
set(INSTALL_DESTINATION_PATH ${DATA_INSTALL_DIR}/${PROJECT_NAME}-${INSTALLER_PLATFORM}/cmake)
else()
set(INSTALL_DESTINATION_PATH ${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}${MSVCARCH_DIR_EXTENSION_EXT})
endif()

install(EXPORT ${PROJECT_NAME}-targets
install(EXPORT ${PROJECT_NAME}-${FASTDDS_LINKING}-targets
DESTINATION ${INSTALL_DESTINATION_PATH}
COMPONENT cmake
)
Expand Down

0 comments on commit f773acf

Please sign in to comment.