From e0a62b32439516398330e1cacead27e366b81e32 Mon Sep 17 00:00:00 2001 From: seanyen Date: Thu, 12 Dec 2019 21:22:15 -0800 Subject: [PATCH 1/2] Enable Windows build. --- CMakeLists.txt | 24 +++++++++++++++++++++--- SOEM/CMakeLists.txt | 4 ++-- SOEM/osal/win32/osal.c | 4 ++++ SOEM/oshw/win32/oshw.c | 1 + 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03f889b..ae90a6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,22 +30,40 @@ catkin_destinations() # create directory during CMake build system creation step file(MAKE_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION}) +if(WIN32) + set(OS "win32") +else() + set(OS "linux") +endif() + +file(GLOB SOEM_COMMON_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/SOEM/soem/*.h") +file(GLOB SOEM_OSAL_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/SOEM/osal/${OS}/*.h") +file(GLOB SOEM_OSHW_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/SOEM/oshw/${OS}/*.h") + # Copy header to ROS-standard location in devel space to satisfy catkin_package add_custom_target(CopyHeaders ALL COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_CURRENT_SOURCE_DIR}/SOEM/soem/*.h + ${SOEM_COMMON_HEADERS} ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/SOEM/osal/osal.h ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION} COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_CURRENT_SOURCE_DIR}/SOEM/osal/linux/*.h + ${SOEM_OSAL_HEADERS} ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION} COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_CURRENT_SOURCE_DIR}/SOEM/oshw/linux/*.h + ${SOEM_OSHW_HEADERS} ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION} COMMENT "Copying SOEM headers to ROS-standard in devel space location.") +if(WIN32) + add_custom_target(CopyWpcapHeaders ALL + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/SOEM/oshw/${OS}/wpcap/Include/ + ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION} + COMMENT "Copying Wpcap headers to ROS-standard in devel space location.") +endif() + # explicitely find pthread to be able to explicitely export the pthread dependency via catkin_package # see https://github.com/ros/ros_comm/issues/135 set(PTHREAD_LIB "") diff --git a/SOEM/CMakeLists.txt b/SOEM/CMakeLists.txt index a72b9ec..1df229b 100644 --- a/SOEM/CMakeLists.txt +++ b/SOEM/CMakeLists.txt @@ -15,9 +15,9 @@ if(WIN32) set(OS "win32") include_directories(oshw/win32/wpcap/Include) if(CMAKE_SIZEOF_VOID_P EQUAL 8) - link_directories(${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Lib/x64) + link_directories(oshw/win32/wpcap/Lib/x64) elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) - link_directories(${CMAKE_SOURCE_DIR}/oshw/win32/wpcap/Lib) + link_directories(oshw/win32/wpcap/Lib) endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_NO_WARNINGS") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") diff --git a/SOEM/osal/win32/osal.c b/SOEM/osal/win32/osal.c index d744fea..04f9c01 100644 --- a/SOEM/osal/win32/osal.c +++ b/SOEM/osal/win32/osal.c @@ -3,7 +3,11 @@ * LICENSE file in the project root for full license information */ +#ifdef WIN32_LEAN_AND_MEAN +#undef WIN32_LEAN_AND_MEAN +#endif #include +#include #include #include "osal_win32.h" diff --git a/SOEM/oshw/win32/oshw.c b/SOEM/oshw/win32/oshw.c index e58f5fa..7c5dbd7 100644 --- a/SOEM/oshw/win32/oshw.c +++ b/SOEM/oshw/win32/oshw.c @@ -3,6 +3,7 @@ * LICENSE file in the project root for full license information */ +#include #include "oshw.h" /** From 4dc8bdd63f77c828b8c6087dd01e83d8dc4cf52f Mon Sep 17 00:00:00 2001 From: seanyen Date: Thu, 12 Dec 2019 21:55:16 -0800 Subject: [PATCH 2/2] undef WIN32_LEAN_AND_MEAN instead of touching SOEM code. --- CMakeLists.txt | 3 +++ SOEM/osal/win32/osal.c | 4 ---- SOEM/oshw/win32/oshw.c | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae90a6f..2ec7423 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,9 @@ catkin_package( # Thus, we add -fPIC here. # This allows us to still include this in any shared libraries we create. add_compile_options(-fPIC) +# removed any pre-defined `WIN32_LEAN_AND_MEAN`. +# Otherwise, many symbols will be reported as missing. +remove_definitions(-DWIN32_LEAN_AND_MEAN) #catkin_lint: ignore duplicate_cmd #catkin_lint: ignore subproject add_subdirectory(SOEM) diff --git a/SOEM/osal/win32/osal.c b/SOEM/osal/win32/osal.c index 04f9c01..d744fea 100644 --- a/SOEM/osal/win32/osal.c +++ b/SOEM/osal/win32/osal.c @@ -3,11 +3,7 @@ * LICENSE file in the project root for full license information */ -#ifdef WIN32_LEAN_AND_MEAN -#undef WIN32_LEAN_AND_MEAN -#endif #include -#include #include #include "osal_win32.h" diff --git a/SOEM/oshw/win32/oshw.c b/SOEM/oshw/win32/oshw.c index 7c5dbd7..e58f5fa 100644 --- a/SOEM/oshw/win32/oshw.c +++ b/SOEM/oshw/win32/oshw.c @@ -3,7 +3,6 @@ * LICENSE file in the project root for full license information */ -#include #include "oshw.h" /**