From 9de4530c6b951107b99593ca32e7bbff4066bba7 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 4 Sep 2023 18:27:13 +0200 Subject: [PATCH 1/7] Introduce modern way to link with pthread library --- CMakeLists.txt | 11 ++-- cmake/AddExtraCompilationFlags.cmake | 9 +++ cmake/FindPTHREAD.cmake | 99 ---------------------------- modules/core/CMakeLists.txt | 8 ++- modules/robot/CMakeLists.txt | 11 ++-- 5 files changed, 27 insertions(+), 111 deletions(-) delete mode 100644 cmake/FindPTHREAD.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d7d8543111..c8a1bd2d3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -571,19 +571,18 @@ if(SOQT_FOUND) # SoQt < 1.6.0 that depends on Qt4 was found. We need an explicit VP_OPTION(USE_QT Qt "" "Include Coin/SoQt/Qt support" "" ON IF USE_SOQT AND NOT WINRT AND NOT IOS) endif() VP_OPTION(USE_SOXT SOXT "" "Include Coin/SoXt support" "" OFF IF USE_COIN3D AND NOT WINRT AND NOT IOS) -if (ANDROID) - VP_OPTION(USE_PTHREAD Threads "" "Include pthread support" "" ON) -else() - VP_OPTION(USE_PTHREAD PTHREAD "" "Include pthread support" "" ON) -endif() +set(THREADS_PREFER_PTHREAD_FLAG ON) +VP_OPTION(USE_PTHREAD Threads "" "Include pthread support" "" ON) + # We need threads with c++11 if((VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98) AND NOT USE_PTHREAD) - if(Threads_FOUND OR PTHREAD_FOUND) + if(Threads_FOUND) message(WARNING "We need threads. Turn USE_PTHREAD=ON.") unset(USE_PTHREAD) set(USE_PTHREAD ON CACHE BOOL "Include pthread support" FORCE) endif() endif() + VP_OPTION(USE_XML2 XML2 "" "Include xml support" "" ON IF NOT WINRT) if(CMAKE_TOOLCHAIN_FILE) # Find opencv2.framework for ios and naoqi diff --git a/cmake/AddExtraCompilationFlags.cmake b/cmake/AddExtraCompilationFlags.cmake index 7f761ede09..3f9ad7245b 100644 --- a/cmake/AddExtraCompilationFlags.cmake +++ b/cmake/AddExtraCompilationFlags.cmake @@ -113,6 +113,15 @@ if(USE_OPENMP) add_extra_compiler_option("${OpenMP_CXX_FLAGS}") endif() +if(USE_PTHREAD) + if(TARGET Threads::Threads) + get_target_property(prop_threads_compile_option Threads::Threads INTERFACE_COMPILE_OPTIONS) + if (prop_threads_compile_option) + add_extra_compiler_option(${prop_threads_compile_option}) + endif() + endif() +endif() + if((VISP_CXX_STANDARD EQUAL VISP_CXX_STANDARD_11) AND CXX11_CXX_FLAGS) add_extra_compiler_option("${CXX11_CXX_FLAGS}") elseif((VISP_CXX_STANDARD EQUAL VISP_CXX_STANDARD_14) AND CXX14_CXX_FLAGS) diff --git a/cmake/FindPTHREAD.cmake b/cmake/FindPTHREAD.cmake deleted file mode 100644 index 00b366dacc..0000000000 --- a/cmake/FindPTHREAD.cmake +++ /dev/null @@ -1,99 +0,0 @@ -############################################################################# -# -# 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 visp@inria.fr -# -# 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 pthread library. -# Once run this will define: -# -# PTHREAD_FOUND -# PTHREAD_INCLUDE_DIRS -# PTHREAD_LIBRARIES -# -############################################################################# - -if(MINGW) - find_path(PTHREAD_INCLUDE_DIR pthread.h - "$ENV{MINGW_DIR}/include" - "$ENV{MINGW_DIR}/mingw/include" - C:/mingw/mingw/include - ) - - # pthreadVSE pthreadGCE pthreadGC pthreadVC1 pthreadVC2 are comming from web - find_library(PTHREAD_LIBRARY - NAMES pthread pthreadGC2 pthreadVSE pthreadGCE pthreadGC pthreadVC1 pthreadVC2 - PATHS - "$ENV{MINGW_DIR}/lib" - "$ENV{MINGW_DIR}/mingw/lib" - C:/mingw/mingw/lib - ) -else() - find_path(PTHREAD_INCLUDE_DIR pthread.h - "$ENV{PTHREAD_HOME}/include" - "$ENV{PTHREAD_DIR}/include" - /usr/include - ) - # pthreadVSE pthreadGCE pthreadGC pthreadVC1 pthreadVC2 are comming from web - find_library(PTHREAD_LIBRARY - NAMES pthread pthreadGC2 pthreadVSE pthreadGCE pthreadGC pthreadVC1 pthreadVC2 - PATHS - "$ENV{PTHREAD_HOME}/lib" - "$ENV{PTHREAD_DIR}/lib" - /usr/lib - /usr/local/lib - /lib - ) -endif() - #MESSAGE("DBG PTHREAD_INCLUDE_DIR=${PTHREAD_INCLUDE_DIR}") - #MESSAGE(STATUS "DBG PTHREAD_LIBRARY=${PTHREAD_LIBRARY}") - - ## -------------------------------- - - IF(PTHREAD_LIBRARY) - SET(PTHREAD_LIBRARIES ${PTHREAD_LIBRARY}) - ELSE(PTHREAD_LIBRARY) - #MESSAGE(SEND_ERROR "pthread library not found.") - ENDIF(PTHREAD_LIBRARY) - - IF(NOT PTHREAD_INCLUDE_DIR) - #MESSAGE(SEND_ERROR "pthread include dir not found.") - ENDIF(NOT PTHREAD_INCLUDE_DIR) - - IF(PTHREAD_LIBRARIES AND PTHREAD_INCLUDE_DIR) - SET(PTHREAD_INCLUDE_DIRS ${PTHREAD_INCLUDE_DIR}) - SET(PTHREAD_FOUND TRUE) - ELSE(PTHREAD_LIBRARIES AND PTHREAD_INCLUDE_DIR) - SET(PTHREAD_FOUND FALSE) - ENDIF(PTHREAD_LIBRARIES AND PTHREAD_INCLUDE_DIR) - - MARK_AS_ADVANCED( - PTHREAD_INCLUDE_DIR - PTHREAD_LIBRARY - ) - #MESSAGE(STATUS "PTHREAD_FOUND : ${PTHREAD_FOUND}") diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index f50d78d76a..6eb10469bc 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -222,8 +222,12 @@ if(USE_XML2) list(APPEND opt_libs ${XML2_LIBRARIES}) endif() if(USE_PTHREAD) - list(APPEND opt_incs ${PTHREAD_INCLUDE_DIRS}) - list(APPEND opt_libs ${PTHREAD_LIBRARIES}) + if(TARGET Threads::Threads) + get_target_property(prop_threads_link_libs Threads::Threads INTERFACE_LINK_LIBRARIES) + if(prop_threads_link_libs) + list(APPEND opt_libs ${prop_threads_link_libs}) + endif() + endif() endif() if(USE_ZLIB) list(APPEND opt_incs ${ZLIB_INCLUDE_DIRS}) diff --git a/modules/robot/CMakeLists.txt b/modules/robot/CMakeLists.txt index d01ec138c7..a5befad6f7 100644 --- a/modules/robot/CMakeLists.txt +++ b/modules/robot/CMakeLists.txt @@ -50,8 +50,7 @@ if(USE_VIRTUOSE) list(APPEND opt_libs ${VIRTUOSE_LIBRARIES}) if(USE_PTHREAD AND RT_FOUND AND DL_FOUND) - list(APPEND opt_incs ${PTHREAD_INCLUDE_DIRS}) - list(APPEND opt_libs ${PTHREAD_LIBRARIES}) + list(APPEND opt_libs "Threads::Threads") list(APPEND opt_libs ${RT_LIBRARIES}) list(APPEND opt_libs ${DL_LIBRARIES}) endif() @@ -123,8 +122,12 @@ if(USE_ARIA AND UNIX AND USE_PTHREAD AND RT_FOUND AND DL_FOUND) # Under Unix we need Aria, pthread, dl and rt libraries list(APPEND opt_incs ${ARIA_INCLUDE_DIRS}) list(APPEND opt_libs ${ARIA_LIBRARIES}) - list(APPEND opt_incs ${PTHREAD_INCLUDE_DIRS}) - list(APPEND opt_libs ${PTHREAD_LIBRARIES}) + if(TARGET Threads::Threads) + get_target_property(prop_threads_link_libs Threads::Threads INTERFACE_LINK_LIBRARIES) + if(prop_threads_link_libs) + list(APPEND opt_libs ${prop_threads_link_libs}) + endif() + endif() list(APPEND opt_libs ${RT_LIBRARIES}) list(APPEND opt_libs ${DL_LIBRARIES}) elseif(USE_ARIA AND NOT UNIX) From 22c748f6c730c5affeca1e0355c633f65fb8c9da Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Mon, 4 Sep 2023 18:31:25 +0200 Subject: [PATCH 2/7] Fix pthread usage with virtuose --- modules/robot/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/robot/CMakeLists.txt b/modules/robot/CMakeLists.txt index a5befad6f7..79bed3e9f3 100644 --- a/modules/robot/CMakeLists.txt +++ b/modules/robot/CMakeLists.txt @@ -50,7 +50,12 @@ if(USE_VIRTUOSE) list(APPEND opt_libs ${VIRTUOSE_LIBRARIES}) if(USE_PTHREAD AND RT_FOUND AND DL_FOUND) - list(APPEND opt_libs "Threads::Threads") + if(TARGET Threads::Threads) + get_target_property(prop_threads_link_libs Threads::Threads INTERFACE_LINK_LIBRARIES) + if(prop_threads_link_libs) + list(APPEND opt_libs ${prop_threads_link_libs}) + endif() + endif() list(APPEND opt_libs ${RT_LIBRARIES}) list(APPEND opt_libs ${DL_LIBRARIES}) endif() From d6e5a2fe74defc6ff68003f315218de13af31aab Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 5 Sep 2023 10:55:21 +0200 Subject: [PATCH 3/7] Change way to use pthread --- cmake/AddExtraCompilationFlags.cmake | 7 ++----- modules/core/CMakeLists.txt | 7 ++----- modules/robot/CMakeLists.txt | 14 ++++---------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/cmake/AddExtraCompilationFlags.cmake b/cmake/AddExtraCompilationFlags.cmake index 3f9ad7245b..95f15d0d29 100644 --- a/cmake/AddExtraCompilationFlags.cmake +++ b/cmake/AddExtraCompilationFlags.cmake @@ -114,11 +114,8 @@ if(USE_OPENMP) endif() if(USE_PTHREAD) - if(TARGET Threads::Threads) - get_target_property(prop_threads_compile_option Threads::Threads INTERFACE_COMPILE_OPTIONS) - if (prop_threads_compile_option) - add_extra_compiler_option(${prop_threads_compile_option}) - endif() + if(THREADS_HAVE_PTHREAD_ARG) + add_extra_compiler_option("-pthread") endif() endif() diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 6eb10469bc..824ea789b4 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -222,11 +222,8 @@ if(USE_XML2) list(APPEND opt_libs ${XML2_LIBRARIES}) endif() if(USE_PTHREAD) - if(TARGET Threads::Threads) - get_target_property(prop_threads_link_libs Threads::Threads INTERFACE_LINK_LIBRARIES) - if(prop_threads_link_libs) - list(APPEND opt_libs ${prop_threads_link_libs}) - endif() + if(CMAKE_THREAD_LIBS_INIT) + list(APPEND opt_libs "${CMAKE_THREAD_LIBS_INIT}") endif() endif() if(USE_ZLIB) diff --git a/modules/robot/CMakeLists.txt b/modules/robot/CMakeLists.txt index 79bed3e9f3..b20f96706e 100644 --- a/modules/robot/CMakeLists.txt +++ b/modules/robot/CMakeLists.txt @@ -50,11 +50,8 @@ if(USE_VIRTUOSE) list(APPEND opt_libs ${VIRTUOSE_LIBRARIES}) if(USE_PTHREAD AND RT_FOUND AND DL_FOUND) - if(TARGET Threads::Threads) - get_target_property(prop_threads_link_libs Threads::Threads INTERFACE_LINK_LIBRARIES) - if(prop_threads_link_libs) - list(APPEND opt_libs ${prop_threads_link_libs}) - endif() + if(CMAKE_THREAD_LIBS_INIT) + list(APPEND opt_libs "${CMAKE_THREAD_LIBS_INIT}") endif() list(APPEND opt_libs ${RT_LIBRARIES}) list(APPEND opt_libs ${DL_LIBRARIES}) @@ -127,11 +124,8 @@ if(USE_ARIA AND UNIX AND USE_PTHREAD AND RT_FOUND AND DL_FOUND) # Under Unix we need Aria, pthread, dl and rt libraries list(APPEND opt_incs ${ARIA_INCLUDE_DIRS}) list(APPEND opt_libs ${ARIA_LIBRARIES}) - if(TARGET Threads::Threads) - get_target_property(prop_threads_link_libs Threads::Threads INTERFACE_LINK_LIBRARIES) - if(prop_threads_link_libs) - list(APPEND opt_libs ${prop_threads_link_libs}) - endif() + if(CMAKE_THREAD_LIBS_INIT) + list(APPEND opt_libs "${CMAKE_THREAD_LIBS_INIT}") endif() list(APPEND opt_libs ${RT_LIBRARIES}) list(APPEND opt_libs ${DL_LIBRARIES}) From 831bf154322ef882b0d783148f53f232e882746c Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 5 Sep 2023 10:57:12 +0200 Subject: [PATCH 4/7] Fix compat with OpenCV < 2.4.0 (2.3.1 on ubuntu 12.04 ci) --- modules/core/include/visp3/core/vpImageCircle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/include/visp3/core/vpImageCircle.h b/modules/core/include/visp3/core/vpImageCircle.h index 6d591fba25..e3648b7259 100644 --- a/modules/core/include/visp3/core/vpImageCircle.h +++ b/modules/core/include/visp3/core/vpImageCircle.h @@ -48,7 +48,7 @@ #include #if defined(VISP_HAVE_OPENCV) -#include +#include #endif /** From cc0782b3246f04f3619014a904974a7c7caf3c29 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Tue, 5 Sep 2023 18:03:34 +0200 Subject: [PATCH 5/7] Disable USE_PTHREAD on windows to enable WITH_PTHREAD that allows to build the embedded pthread library on windows --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8a1bd2d3d..8e77dd4b94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -572,7 +572,7 @@ if(SOQT_FOUND) # SoQt < 1.6.0 that depends on Qt4 was found. We need an explicit endif() VP_OPTION(USE_SOXT SOXT "" "Include Coin/SoXt support" "" OFF IF USE_COIN3D AND NOT WINRT AND NOT IOS) set(THREADS_PREFER_PTHREAD_FLAG ON) -VP_OPTION(USE_PTHREAD Threads "" "Include pthread support" "" ON) +VP_OPTION(USE_PTHREAD Threads "" "Include pthread support" "" ON IF NOT (WIN32 OR MINGW)) # We need threads with c++11 if((VISP_CXX_STANDARD GREATER VISP_CXX_STANDARD_98) AND NOT USE_PTHREAD) From 9209898bd4223248cea3c56b5f6b1e351e3eddc2 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 6 Sep 2023 09:16:57 +0200 Subject: [PATCH 6/7] Fix OpenMP library usage that has a dependency to pthread that break conda package usage Because there is an explicit link to libpthread location that breaks visp conda package usage on linux we cannot use OpenMP_CXX_LIBRARIES that contains /usr/lib/gcc/x86_64-linux-gnu/11/libgomp.so;/usr/lib/x86_64-linux-gnu/libpthread.a by adding: list(APPEND opt_libs ${OpenMP_CXX_LIBRARIES}) That's why we need to use the modern way to consider pthread dependency --- modules/core/CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 824ea789b4..ed4ddec793 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -232,7 +232,19 @@ if(USE_ZLIB) endif() if(USE_OPENMP) list(APPEND opt_incs ${OpenMP_CXX_INCLUDE_DIRS}) - list(APPEND opt_libs ${OpenMP_CXX_LIBRARIES}) + # Because there is an explicit link to libpthread location that breaks visp conda package usage on linux + # we cannot use OpenMP_CXX_LIBRARIES that contains /usr/lib/gcc/x86_64-linux-gnu/11/libgomp.so;/usr/lib/x86_64-linux-gnu/libpthread.a + # by adding: + # list(APPEND opt_libs ${OpenMP_CXX_LIBRARIES}) + foreach(lib_ ${OpenMP_CXX_LIB_NAMES}) + if("x${lib_}" STREQUAL "xpthread") + if(CMAKE_THREAD_LIBS_INIT) + list(APPEND opt_libs "${CMAKE_THREAD_LIBS_INIT}") + endif() + else() + list(APPEND opt_libs ${OpenMP_${lib_}_LIBRARY}) + endif() + endforeach() endif() if(USE_NLOHMANN_JSON) get_target_property(_inc_dirs "nlohmann_json::nlohmann_json" INTERFACE_INCLUDE_DIRECTORIES) From 2c074dbdba519e439647e29706118c6d65c05bee Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 6 Sep 2023 18:22:35 +0200 Subject: [PATCH 7/7] Fix side effect detected on windows whith commit e2ed222 where changes 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 --- CMakeLists.txt | 37 +++------------- cmake/FindWS2_32.cmake | 76 +++++++++++++++++++++++++++++++++ cmake/VISPModule.cmake | 9 ++-- cmake/VISPUtils.cmake | 3 +- modules/core/CMakeLists.txt | 5 +++ modules/java/jni/CMakeLists.txt | 16 +++---- 6 files changed, 101 insertions(+), 45 deletions(-) create mode 100644 cmake/FindWS2_32.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e77dd4b94..52b6d125fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 #-------------------------------------------------------------------- diff --git a/cmake/FindWS2_32.cmake b/cmake/FindWS2_32.cmake new file mode 100644 index 0000000000..853caf9fc1 --- /dev/null +++ b/cmake/FindWS2_32.cmake @@ -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 visp@inria.fr +# +# 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() diff --git a/cmake/VISPModule.cmake b/cmake/VISPModule.cmake index a178dc79f3..8933d58c60 100644 --- a/cmake/VISPModule.cmake +++ b/cmake/VISPModule.cmake @@ -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( LINK_PRIVATE ) +# vp_create_module() # vp_create_module() macro(vp_create_module) vp_debug_message("vp_create_module(" ${ARGN} ")") @@ -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}) @@ -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 diff --git a/cmake/VISPUtils.cmake b/cmake/VISPUtils.cmake index d394a08fc5..3df61f4ac1 100644 --- a/cmake/VISPUtils.cmake +++ b/cmake/VISPUtils.cmake @@ -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() @@ -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 "^\\$]+)>$") set(dep_dbg "${CMAKE_MATCH_1}") diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index ed4ddec793..2734dad673 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -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. diff --git a/modules/java/jni/CMakeLists.txt b/modules/java/jni/CMakeLists.txt index 908fcf66e4..7d95d24266 100644 --- a/modules/java/jni/CMakeLists.txt +++ b/modules/java/jni/CMakeLists.txt @@ -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}) @@ -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 @@ -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