Skip to content

Commit

Permalink
Fix side effect detected on windows whith commit e2ed222 where changes
Browse files Browse the repository at this point in the history
VISP_LINKER_LIBS are used as private
- there is the need to make ws2_32.lib as a 3rd party public library
- Consider now ws2_32.lib as a public  3rd party that is linked to core
  module
- Rename deprecated LINK_PUBLIC and LINK_PRIVATE to PUBLIC and PRIVATE respectively
  • Loading branch information
fspindle committed Sep 6, 2023
1 parent 9209898 commit 2c074db
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 45 deletions.
37 changes: 6 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,40 +382,15 @@ if(WIN32)
endif()
endif()

# Add library ws2_32.a or ws2_32.lib for vpNetwork class
if(WIN32 AND NOT CYGWIN)
if(MINGW)
set(WS2_32_LIBRARY "ws2_32.a")
check_library_exists(${WS2_32_LIBRARY} getch "" HAVE_LIBWS2_32) # for inet_ntoa() and socket functionalities
if(HAVE_LIBWS2_32)
list(APPEND VISP_LINKER_LIBS ${WS2_32_LIBRARY})
else()
find_library(HAVE_LIBWS2_32 ${WS2_32_LIBRARY}
"$ENV{MINGW_DIR}/lib"
"$ENV{MINGW_DIR}/mingw/lib"
C:/mingw/mingw/lib)
if(HAVE_LIBWS2_32)
list(APPEND VISP_LINKER_LIBS "${WS2_32_LIBRARY}")
endif()
endif()
elseif(WINRT)
# Since check_library_exists() and find_library() does't work to detect ws2_32.lib we add the lib that is part of Windows SDK
set(WS2_32_LIBRARY "ws2_32.lib")
list(APPEND VISP_LINKER_LIBS ${WS2_32_LIBRARY})
else() # pure WIN32
set(WS2_32_LIBRARY "ws2_32.lib")
#check_library_exists("ws2_32.lib" getch "" HAVE_LIBWS2_32) # for inet_ntoa() and socket functionalities
check_library_exists(${WS2_32_LIBRARY} getch "" HAVE_LIBWS2_32) # for inet_ntoa() and socket functionalities
if(HAVE_LIBWS2_32)
list(APPEND VISP_LINKER_LIBS ${WS2_32_LIBRARY})
endif()
endif()
mark_as_advanced(HAVE_LIBWS2_32)
VP_CHECK_PACKAGE(WS2_32)
# Should be before include(cmake/VISPDetectCXXStandard.cmake)
VP_CHECK_FUNCTION_EXISTS(inet_ntop "${WS2_32_LIBRARY}")
else()
# Should be before include(cmake/VISPDetectCXXStandard.cmake)
VP_CHECK_FUNCTION_EXISTS(inet_ntop "")
endif()

# Should be before include(cmake/VISPDetectCXXStandard.cmake)
VP_CHECK_FUNCTION_EXISTS(inet_ntop "${VISP_LINKER_LIBS}")

#--------------------------------------------------------------------
# Option management
#--------------------------------------------------------------------
Expand Down
76 changes: 76 additions & 0 deletions cmake/FindWS2_32.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#############################################################################
#
# ViSP, open source Visual Servoing Platform software.
# Copyright (C) 2005 - 2023 by Inria. All rights reserved.
#
# This software is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# See the file LICENSE.txt at the root directory of this source
# distribution for additional information about the GNU GPL.
#
# For using ViSP with software that can not be combined with the GNU
# GPL, please contact Inria about acquiring a ViSP Professional
# Edition License.
#
# See https://visp.inria.fr for more information.
#
# This software was developed at:
# Inria Rennes - Bretagne Atlantique
# Campus Universitaire de Beaulieu
# 35042 Rennes Cedex
# France
#
# If you have questions regarding the use of this file, please contact
# Inria at [email protected]
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# Description:
# Try to find ws2_32 library.
#
# WS2_32_FOUND - true if ws2_32 library is detected
# WS2_32_LIBRARY - Library name
#
#############################################################################

if(WIN32 AND NOT CYGWIN)
if(MINGW)
set(WS2_32_LIBNAME "ws2_32.a")
check_library_exists(${WS2_32_LIBNAME} getch "" HAVE_LIBWS2_32) # for inet_ntoa() and socket functionalities
if(HAVE_LIBWS2_32)
set(WS2_32_LIBRARY ${WS2_32_LIBNAME})
set(WS2_32_FOUND TRUE)
else()
find_library(HAVE_LIBWS2_32 ${WS2_32_LIBNAME}
"$ENV{MINGW_DIR}/lib"
"$ENV{MINGW_DIR}/mingw/lib"
C:/mingw/mingw/lib)
if(HAVE_LIBWS2_32)
set(WS2_32_LIBRARY ${WS2_32_LIBNAME})
set(WS2_32_FOUND TRUE)
else()
set(WS2_32_FOUND FALSE)
endif()
endif()
elseif(WINRT)
# Since check_library_exists() and find_library() does't work to detect ws2_32.lib we add the lib that is part of Windows SDK
set(WS2_32_LIBNAME "ws2_32.lib")
set(WS2_32_LIBRARY ${WS2_32_LIBNAME})
set(WS2_32_FOUND TRUE)
else() # pure WIN32
set(WS2_32_LIBNAME "ws2_32.lib")
check_library_exists(${WS2_32_LIBNAME} getch "" HAVE_LIBWS2_32) # for inet_ntoa() and socket functionalities
if(HAVE_LIBWS2_32)
message("-----------> ${WS2_32_LIBNAME} is found")
set(WS2_32_LIBRARY ${WS2_32_LIBNAME})
set(WS2_32_FOUND TRUE)
else()
set(WS2_32_FOUND FALSE)
endif()
endif()
mark_as_advanced(WS2_32_LIBNAME)
mark_as_advanced(HAVE_LIBWS2_32)
endif()
9 changes: 4 additions & 5 deletions cmake/VISPModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ endmacro()
# creates ViSP module in current folder
# creates new target, configures standard dependencies, compilers flags, install rules
# Usage:
# vp_create_module(<extra link dependencies> LINK_PRIVATE <private link dependencies>)
# vp_create_module(<extra link dependencies>)
# vp_create_module()
macro(vp_create_module)
vp_debug_message("vp_create_module(" ${ARGN} ")")
Expand All @@ -801,12 +801,11 @@ macro(_vp_create_module)
vp_add_library(${the_module} ${VISP_MODULE_TYPE} ${VISP_MODULE_${the_module}_HEADERS} ${VISP_MODULE_${the_module}_SOURCES})

vp_target_link_libraries(${the_module}
LINK_PUBLIC
PUBLIC
${VISP_MODULE_${the_module}_DEPS_TO_LINK}
${VISP_MODULE_${the_module}_DEPS_EXT}
${VISP_MODULE_${the_module}_LINK_DEPS}
${VISP_LINKER_LIBS}
LINK_PRIVATE
PRIVATE
${VISP_MODULE_${the_module}_PRIVATE_REQ_DEPS}
${VISP_MODULE_${the_module}_PRIVATE_OPT_DEPS})
add_dependencies(visp_modules ${the_module})
Expand Down Expand Up @@ -1016,7 +1015,7 @@ macro(vp_add_tests)
# From source compile the binary and add link rules
vp_add_executable(${the_target} ${t})
vp_target_include_modules(${the_target} ${test_deps})
vp_target_link_libraries(${the_target} ${test_deps} ${VISP_MODULE_${the_module}_DEPS} ${VISP_LINKER_LIBS})
vp_target_link_libraries(${the_target} ${test_deps} ${VISP_MODULE_${the_module}_DEPS}) # should be removed ? ${VISP_LINKER_LIBS})

# ctest only:
# - if required dataset available
Expand Down
3 changes: 2 additions & 1 deletion cmake/VISPUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ macro(VP_CHECK_FUNCTION_EXISTS function libraries)
string(TOUPPER "${ALIAS}" ALIAS_UPPER)
set(ALIAS_HAVE HAVE_FUNC_${ALIAS_UPPER})
set(CMAKE_REQUIRED_LIBRARIES "${libraries}")
message(" -------> CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
check_function_exists(${ALIAS} ${ALIAS_HAVE})
endmacro()

Expand Down Expand Up @@ -1645,7 +1646,7 @@ macro(vp_get_all_libs _modules _extra_opt _extra_dbg _3rdparty)
endif()
endforeach()

foreach (dep ${deps} ${VISP_LINKER_LIBS})
foreach (dep ${deps}) # Should be remove ? ${VISP_LINKER_LIBS})
if (NOT DEFINED VISP_MODULE_${dep}_LOCATION)
if(dep MATCHES "^\\$<LINK_ONLY:([^>]+)>$")
set(dep_dbg "${CMAKE_MATCH_1}")
Expand Down
5 changes: 5 additions & 0 deletions modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
set(opt_incs "")
set(opt_libs "")

# Add library ws2_32.a or ws2_32.lib for vpNetwork class
if(WS2_32_FOUND)
list(APPEND opt_libs ${WS2_32_LIBRARY})
endif()

# OpenCV
if(USE_OPENCV)
# On win32 since OpenCV 2.4.7 and on OSX with OpenCV 2.4.10 we cannot use OpenCV_LIBS to set ViSP 3rd party libraries.
Expand Down
16 changes: 8 additions & 8 deletions modules/java/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ vp_add_library(${the_module} ${__type}
${copied_files}
)
add_dependencies(${the_module} gen_visp_java_source)

vp_target_include_directories(${the_module} "${CMAKE_CURRENT_SOURCE_DIR}/../generator/src/cpp")
vp_target_include_directories(${the_module} "${VISP_JAVA_BINDINGS_DIR}/gen/cpp")
vp_target_include_modules(${the_module} ${VISP_MODULE_${the_module}_DEPS})
Expand All @@ -51,17 +51,17 @@ if(BUILD_FAT_JAVA_LIB)
endif()
if(APPLE)
foreach(_dep ${__deps})
vp_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-force_load "${_dep}")
vp_target_link_libraries(${the_module} PRIVATE -Wl,-force_load "${_dep}")
endforeach()
# TODO: Just check visp's file once, they had a condition I ignored
elseif(((UNIX) OR (VISP_FORCE_FAT_JAVA_LIB_LD_RULES)) AND (NOT VISP_SKIP_FAT_JAVA_LIB_LD_RULES))
vp_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive)
vp_target_link_libraries(${the_module} PRIVATE -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive)
else()
vp_target_link_libraries(${the_module} LINK_PRIVATE ${__deps})
vp_target_link_libraries(${the_module} PRIVATE ${__deps})
endif()
vp_target_link_libraries(${the_module} LINK_PRIVATE ${__extradeps} ${VISP_LINKER_LIBS})
vp_target_link_libraries(${the_module} PRIVATE ${__extradeps} ${VISP_LINKER_LIBS})
else()
vp_target_link_libraries(${the_module} LINK_PRIVATE ${__deps} ${VISP_LINKER_LIBS})
vp_target_link_libraries(${the_module} PRIVATE ${__deps} ${VISP_LINKER_LIBS})
endif()

# Additional target properties
Expand All @@ -74,8 +74,8 @@ set_target_properties(${the_module} PROPERTIES
)

if(ANDROID)
vp_target_link_libraries(${the_module} LINK_PUBLIC jnigraphics)
vp_target_link_libraries(${the_module} LINK_PUBLIC log dl z)
vp_target_link_libraries(${the_module} PUBLIC jnigraphics)
vp_target_link_libraries(${the_module} PUBLIC log dl z)

# force strip library after the build command
# because samples and tests will make a copy of the library before install
Expand Down

0 comments on commit 2c074db

Please sign in to comment.