diff --git a/CMakeLists.txt b/CMakeLists.txt index d7d8543111..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 #-------------------------------------------------------------------- @@ -571,19 +546,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 IF NOT (WIN32 OR MINGW)) + # 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..95f15d0d29 100644 --- a/cmake/AddExtraCompilationFlags.cmake +++ b/cmake/AddExtraCompilationFlags.cmake @@ -113,6 +113,12 @@ if(USE_OPENMP) add_extra_compiler_option("${OpenMP_CXX_FLAGS}") endif() +if(USE_PTHREAD) + if(THREADS_HAVE_PTHREAD_ARG) + add_extra_compiler_option("-pthread") + 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/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 3e44846b6f..eee1761ba1 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,11 +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} - LINK_PRIVATE + PRIVATE ${VISP_MODULE_${the_module}_PRIVATE_REQ_DEPS} ${VISP_MODULE_${the_module}_PRIVATE_OPT_DEPS} ${VISP_LINKER_LIBS}) @@ -1016,7 +1016,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 f50d78d76a..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. @@ -222,8 +227,9 @@ 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(CMAKE_THREAD_LIBS_INIT) + list(APPEND opt_libs "${CMAKE_THREAD_LIBS_INIT}") + endif() endif() if(USE_ZLIB) list(APPEND opt_incs ${ZLIB_INCLUDE_DIRS}) @@ -231,7 +237,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) 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 /** 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 diff --git a/modules/robot/CMakeLists.txt b/modules/robot/CMakeLists.txt index d01ec138c7..b20f96706e 100644 --- a/modules/robot/CMakeLists.txt +++ b/modules/robot/CMakeLists.txt @@ -50,8 +50,9 @@ 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}) + 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}) endif() @@ -123,8 +124,9 @@ 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(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}) elseif(USE_ARIA AND NOT UNIX)