Skip to content

Commit

Permalink
[lcm] Fix build error on Linux (#14147)
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyWangL authored Oct 27, 2020
1 parent b6b734c commit 134fe60
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 14 deletions.
1 change: 1 addition & 0 deletions ports/lcm/CONTROL
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Source: lcm
Version: 1.4.0
Port-Version: 1
Build-Depends: glib
Homepage: https://github.com/lcm-proj/lcm
Description: Lightweight Communications and Marshalling (LCM)
Expand Down
127 changes: 127 additions & 0 deletions ports/lcm/fix-linux-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6d3a4c2..da3bfc5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ if(CMAKE_VERSION VERSION_LESS 3.7)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/3.7")
endif()

-find_package(GLib2 REQUIRED)
+find_package(unofficial-glib CONFIG REQUIRED)

# Configuration and utility functions
include(lcm-cmake/config.cmake NO_POLICY_SCOPE)
@@ -22,6 +22,11 @@ if (WIN32)
include_directories(${lcm_SOURCE_DIR})
add_subdirectory(WinSpecific)
set(lcm-winport lcm-winport)
+ if(CMAKE_BUILD_TYPE STREQUAL Debug)
+ get_target_property(GLIB2_GLIB_RUNTIME unofficial::glib::glib IMPORTED_LOCATION_DEBUG)
+ elseif(CMAKE_BUILD_TYPE STREQUAL Release)
+ get_target_property(GLIB2_GLIB_RUNTIME unofficial::glib::glib IMPORTED_LOCATION_RELEASE)
+ endif()
get_filename_component(LCM_LCMGEN_PATH ${GLIB2_GLIB_RUNTIME} DIRECTORY)
set(LCM_USE_GLIB_RUNTIME "set(LCM_LCMGEN_PATH \"${LCM_LCMGEN_PATH}\")")
else()
diff --git a/lcm-logger/CMakeLists.txt b/lcm-logger/CMakeLists.txt
index 9aee9df..253af08 100644
--- a/lcm-logger/CMakeLists.txt
+++ b/lcm-logger/CMakeLists.txt
@@ -1,9 +1,9 @@
add_executable(lcm-logger lcm_logger.c glib_util.c)
-target_link_libraries(lcm-logger
- lcm
- ${lcm-winport}
- GLib2::glib
-)
+if(WIN32)
+ target_link_libraries(lcm-logger lcm ${lcm-winport} unofficial::glib::glib ws2_32)
+else()
+ target_link_libraries(lcm-logger lcm ${lcm-winport} unofficial::glib::glib)
+endif()

add_executable(lcm-logplayer lcm_logplayer.c)
target_link_libraries(lcm-logplayer lcm ${lcm-winport})
diff --git a/lcm/CMakeLists.txt b/lcm/CMakeLists.txt
index 639ec12..9da0c00 100644
--- a/lcm/CMakeLists.txt
+++ b/lcm/CMakeLists.txt
@@ -60,10 +60,11 @@ foreach(lcm_lib lcm lcm-static)
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)

- target_link_libraries(${lcm_lib} PRIVATE
- GLib2::glib
- ${CMAKE_THREAD_LIBS_INIT}
- )
+ if(WIN32)
+ target_link_libraries(${lcm_lib} PRIVATE unofficial::glib::glib ${CMAKE_THREAD_LIBS_INIT} ws2_32)
+ else()
+ target_link_libraries(${lcm_lib} PRIVATE unofficial::glib::glib ${CMAKE_THREAD_LIBS_INIT})
+ endif()
endforeach()

generate_export_header(lcm STATIC_DEFINE LCM_STATIC)
diff --git a/lcmgen/CMakeLists.txt b/lcmgen/CMakeLists.txt
index 29354bb..d848b16 100644
--- a/lcmgen/CMakeLists.txt
+++ b/lcmgen/CMakeLists.txt
@@ -43,7 +43,11 @@ if(_uses_sanitizers AND NOT LCM_SANITIZE_LCMGEN)
endif()

add_executable(lcm-gen ${lcm-gen_sources})
-target_link_libraries(lcm-gen PRIVATE GLib2::glib)
+if(WIN32)
+ target_link_libraries(lcm-gen PRIVATE unofficial::glib::glib ws2_32)
+else()
+ target_link_libraries(lcm-gen PRIVATE unofficial::glib::glib)
+endif()

install(TARGETS lcm-gen
EXPORT lcmTargets
diff --git a/liblcm-test/CMakeLists.txt b/liblcm-test/CMakeLists.txt
index bb24675..da041d9 100644
--- a/liblcm-test/CMakeLists.txt
+++ b/liblcm-test/CMakeLists.txt
@@ -5,7 +5,11 @@ add_executable(lcm-source lcm-source.c)
target_link_libraries(lcm-source lcm ${lcm-winport})

add_executable(lcm-tester lcm-tester.c)
-target_link_libraries(lcm-tester lcm GLib2::glib)
+if(WIN32)
+ target_link_libraries(lcm-tester lcm unofficial::glib::glib ws2_32)
+else()
+ target_link_libraries(lcm-tester lcm unofficial::glib::glib)
+endif()

add_executable(lcm-example lcm-example.c)
target_link_libraries(lcm-example lcm)
@@ -14,13 +18,25 @@ if(WIN32)
endif()

add_executable(lcm-logfilter lcm-logfilter.c)
-target_link_libraries(lcm-logfilter lcm ${lcm-winport} GLib2::glib)
+if(WIN32)
+ target_link_libraries(lcm-logfilter lcm ${lcm-winport} unofficial::glib::glib ws2_32)
+else()
+ target_link_libraries(lcm-logfilter lcm ${lcm-winport} unofficial::glib::glib)
+endif()

add_executable(lcm-buftest-receiver buftest-receiver.c)
-target_link_libraries(lcm-buftest-receiver lcm GLib2::glib)
+if(WIN32)
+ target_link_libraries(lcm-buftest-receiver lcm unofficial::glib::glib ws2_32)
+else()
+ target_link_libraries(lcm-buftest-receiver lcm unofficial::glib::glib)
+endif()

add_executable(lcm-buftest-sender buftest-sender.c)
-target_link_libraries(lcm-buftest-sender lcm GLib2::glib)
+if(WIN32)
+ target_link_libraries(lcm-buftest-sender lcm unofficial::glib::glib ws2_32)
+else()
+ target_link_libraries(lcm-buftest-sender lcm unofficial::glib::glib)
+endif()

install(TARGETS
lcm-sink
30 changes: 18 additions & 12 deletions ports/lcm/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
include(vcpkg_common_functions)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO lcm-proj/lcm
REF v1.4.0
SHA512 ca036aa2c31911e0bfaeab9665188c97726201267314693a1c333c4efe13ea598b39a55a19bc1d48e65462ac9d1716adfda5af86c645d59c3247192631247cc6
HEAD_REF master
PATCHES only-install-one-flavor.patch
fix-build-error.patch
PATCHES
only-install-one-flavor.patch
fix-build-error.patch
fix-linux-build.patch
)

vcpkg_configure_cmake(
Expand All @@ -23,13 +23,19 @@ vcpkg_configure_cmake(
)

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH cmake)
if (VCPKG_TARGET_IS_WINDOWS)
vcpkg_fixup_cmake_targets(CONFIG_PATH cmake)
else()
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/lcm/cmake)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/lib/lcm" "${CURRENT_PACKAGES_DIR}/lib/lcm")
endif()


file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/share/aclocal)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/share/java)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/share/man)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/aclocal")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/java")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/man")

file(GLOB EXES ${CURRENT_PACKAGES_DIR}/bin/*.exe)
if(EXES)
Expand All @@ -42,11 +48,11 @@ if(DEBUG_EXES)
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
endif()

vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/lcm)

file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/lcm RENAME copyright)
file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

vcpkg_copy_pdbs()
2 changes: 0 additions & 2 deletions scripts/ci.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,6 @@ lastools:arm-uwp=fail
lastools:x64-uwp=fail
laszip:arm-uwp=fail
laszip:x64-uwp=fail
lcm:x64-linux=fail
lcm:x64-osx=fail
leptonica:x64-uwp=fail
leptonica:arm-uwp=fail
leveldb:arm-uwp=fail
Expand Down

0 comments on commit 134fe60

Please sign in to comment.