From 66a2cba3657d450e4fddab97b83d846079d0e9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Agostinho?= Date: Thu, 23 Nov 2017 17:30:47 +0000 Subject: [PATCH 1/5] Move sse compiler options to PCL_COMPILE_OPTIONS --- CMakeLists.txt | 6 +++--- PCLConfig.cmake.in | 3 ++- cmake/pcl_find_sse.cmake | 21 +++++++++++---------- cmake/pcl_pclconfig.cmake | 4 +++- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7a1d80a2e0..724cf1024c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,7 +114,7 @@ endif() # ---[ Unix/Darwin/Windows specific flags if(CMAKE_COMPILER_IS_GNUCXX) if("${CMAKE_CXX_FLAGS}" STREQUAL "") - SET(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -fno-strict-aliasing -Wno-format-extra-args -Wno-sign-compare -Wno-invalid-offsetof -Wno-conversion ${SSE_FLAGS}") + SET(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -fno-strict-aliasing -Wno-format-extra-args -Wno-sign-compare -Wno-invalid-offsetof -Wno-conversion ${SSE_FLAGS_STR}") # Enable -Wabi for GCC > 4.3, and -Wno-deprecated for GCC < 4.3 # to disable a lot of warnings which are not fixable @@ -153,7 +153,7 @@ if(CMAKE_COMPILER_IS_MSVC) add_definitions("-DBOOST_ALL_NO_LIB -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DNOMINMAX -DPCL_ONLY_CORE_POINT_TYPES /bigobj ${SSE_DEFINITIONS}") if("${CMAKE_CXX_FLAGS}" STREQUAL "/DWIN32 /D_WINDOWS /W3 /GR /EHsc") # Check against default flags - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /fp:precise /wd4800 /wd4521 /wd4251 /wd4275 /wd4305 /wd4355 ${SSE_FLAGS}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /fp:precise /wd4800 /wd4521 /wd4251 /wd4275 /wd4305 /wd4355 ${SSE_FLAGS_STR}") # Add extra code generation/link optimizations if(CMAKE_MSVC_CODE_LINK_OPTIMIZATION) @@ -193,7 +193,7 @@ if(CMAKE_COMPILER_IS_CLANG) SET(CMAKE_C_FLAGS "-Qunused-arguments") endif() if("${CMAKE_CXX_FLAGS}" STREQUAL "") - SET(CMAKE_CXX_FLAGS "-ftemplate-depth=1024 -Qunused-arguments -Wno-invalid-offsetof ${SSE_FLAGS}") # Unfortunately older Clang versions do not have this: -Wno-unnamed-type-template-args + SET(CMAKE_CXX_FLAGS "-ftemplate-depth=1024 -Qunused-arguments -Wno-invalid-offsetof ${SSE_FLAGS_STR}") # Unfortunately older Clang versions do not have this: -Wno-unnamed-type-template-args if(APPLE AND WITH_CUDA AND CUDA_FOUND) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") endif() diff --git a/PCLConfig.cmake.in b/PCLConfig.cmake.in index 9a9e5f817d8..ccfdec37dde 100644 --- a/PCLConfig.cmake.in +++ b/PCLConfig.cmake.in @@ -415,7 +415,8 @@ set(PCL_DEBUG_SUFFIX "@CMAKE_DEBUG_POSTFIX@") set(PCL_RELEASE_SUFFIX "@CMAKE_RELEASE_POSTFIX@") #set SSE flags used compiling PCL -list(APPEND PCL_DEFINITIONS "@PCLCONFIG_SSE_DEFINITIONS@") +list(APPEND PCL_DEFINITIONS @PCLCONFIG_SSE_DEFINITIONS@) +list(APPEND PCL_COMPILE_OPTIONS @PCLCONFIG_SSE_COMPILE_OPTIONS@) set(pcl_all_components @PCLCONFIG_AVAILABLE_COMPONENTS@ ) list(LENGTH pcl_all_components PCL_NB_COMPONENTS) diff --git a/cmake/pcl_find_sse.cmake b/cmake/pcl_find_sse.cmake index a1ebfe6ba44..a4c8d3a9a73 100644 --- a/cmake/pcl_find_sse.cmake +++ b/cmake/pcl_find_sse.cmake @@ -16,7 +16,7 @@ macro(PCL_CHECK_FOR_SSE) execute_process(COMMAND ${CMAKE_CXX_COMPILER} "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_STRING) if(GCC_VERSION_STRING VERSION_GREATER 4.2 AND NOT APPLE AND NOT CMAKE_CROSSCOMPILING) - SET(SSE_FLAGS "${SSE_FLAGS} -march=native") + list(APPEND SSE_FLAGS "-march=native") message(STATUS "Using CPU native flags for SSE optimization: ${SSE_FLAGS}") endif() endif() @@ -169,27 +169,27 @@ macro(PCL_CHECK_FOR_SSE) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG) if(HAVE_SSE4_2_EXTENSIONS) - SET(SSE_FLAGS "${SSE_FLAGS} -msse4.2 -mfpmath=sse") + list(APPEND SSE_FLAGS "-msse4.2" "-mfpmath=sse") elseif(HAVE_SSE4_1_EXTENSIONS) - SET(SSE_FLAGS "${SSE_FLAGS} -msse4.1 -mfpmath=sse") + list(APPEND SSE_FLAGS "-msse4.1" "-mfpmath=sse") elseif(HAVE_SSSE3_EXTENSIONS) - SET(SSE_FLAGS "${SSE_FLAGS} -mssse3 -mfpmath=sse") + list(APPEND SSE_FLAGS "-mssse3" "-mfpmath=sse") elseif(HAVE_SSE3_EXTENSIONS) - SET(SSE_FLAGS "${SSE_FLAGS} -msse3 -mfpmath=sse") + list(APPEND SSE_FLAGS "-msse3" "-mfpmath=sse") elseif(HAVE_SSE2_EXTENSIONS) - SET(SSE_FLAGS "${SSE_FLAGS} -msse2 -mfpmath=sse") + list(APPEND SSE_FLAGS "-msse2" "-mfpmath=sse") elseif(HAVE_SSE_EXTENSIONS) - SET(SSE_FLAGS "${SSE_FLAGS} -msse -mfpmath=sse") + list(APPEND SSE_FLAGS "-msse" "-mfpmath=sse") else() # Setting -ffloat-store to alleviate 32bit vs 64bit discrepancies on non-SSE # platforms. - set(SSE_FLAGS "-ffloat-store") + list(APPEND SSE_FLAGS "-ffloat-store") endif() elseif(MSVC AND NOT CMAKE_CL_64) if(HAVE_SSE2_EXTENSIONS) - SET(SSE_FLAGS "${SSE_FLAGS} /arch:SSE2") + list(APPEND SSE_FLAGS "/arch:SSE2") elseif(HAVE_SSE_EXTENSIONS) - SET(SSE_FLAGS "${SSE_FLAGS} /arch:SSE") + list(APPEND SSE_FLAGS "/arch:SSE") endif(HAVE_SSE2_EXTENSIONS) endif() @@ -204,4 +204,5 @@ macro(PCL_CHECK_FOR_SSE) SET(SSE_DEFINITIONS "${SSE_DEFINITIONS} -D__SSE__") endif() endif() + string(REPLACE ";" " " SSE_FLAGS_STR "${SSE_FLAGS}") endmacro(PCL_CHECK_FOR_SSE) diff --git a/cmake/pcl_pclconfig.cmake b/cmake/pcl_pclconfig.cmake index 777d049488b..152be7582db 100644 --- a/cmake/pcl_pclconfig.cmake +++ b/cmake/pcl_pclconfig.cmake @@ -11,7 +11,9 @@ set(PCLCONFIG_AVAILABLE_COMPONENTS_LIST) set(PCLCONFIG_INTERNAL_DEPENDENCIES) set(PCLCONFIG_EXTERNAL_DEPENDENCIES) set(PCLCONFIG_OPTIONAL_DEPENDENCIES) -set(PCLCONFIG_SSE_DEFINITIONS "${SSE_FLAGS} ${SSE_DEFINITIONS}") +set(PCLCONFIG_SSE_DEFINITIONS "${SSE_DEFINITIONS}") +set(PCLCONFIG_SSE_COMPILE_OPTIONS ${SSE_FLAGS}) + foreach(_ss ${PCL_SUBSYSTEMS_MODULES}) PCL_GET_SUBSYS_STATUS(_status ${_ss}) if(_status) From bacc76c3d16647e5442150ed11e068f2aed0e374 Mon Sep 17 00:00:00 2001 From: Sergey Alexandrov Date: Thu, 23 Nov 2017 21:31:51 +0000 Subject: [PATCH 2/5] Expose pcl target interface libraries, headers, definitions and compile options --- PCLConfig.cmake.in | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/PCLConfig.cmake.in b/PCLConfig.cmake.in index ccfdec37dde..90c46321a2f 100644 --- a/PCLConfig.cmake.in +++ b/PCLConfig.cmake.in @@ -538,24 +538,50 @@ foreach(component ${PCL_TO_FIND_COMPONENTS}) list(APPEND PCL_DEFINITIONS ${PCL_${COMPONENT}_DEFINITIONS}) list(APPEND PCL_LIBRARY_DIRS ${component_library_path}) if(PCL_${COMPONENT}_LIBRARY_DEBUG) - list(APPEND PCL_${COMPONENT}_LIBRARIES optimized ${PCL_${COMPONENT}_LIBRARY} debug ${PCL_${COMPONENT}_LIBRARY_DEBUG}) list(APPEND PCL_LIBRARY_DIRS ${component_library_path_debug}) - else(PCL_${COMPONENT}_LIBRARY_DEBUG) - list(APPEND PCL_${COMPONENT}_LIBRARIES ${PCL_${COMPONENT}_LIBRARY}) - endif(PCL_${COMPONENT}_LIBRARY_DEBUG) - list(APPEND PCL_LIBRARIES ${PCL_${COMPONENT}_LIBRARIES}) + endif() + list(APPEND PCL_LIBRARIES ${pcl_component}) mark_as_advanced(PCL_${COMPONENT}_LIBRARY PCL_${COMPONENT}_LIBRARY_DEBUG) - endif(_is_header_only EQUAL -1) + endif() # Append internal dependencies foreach(int_dep ${pcl_${component}_int_dep}) string(TOUPPER "${int_dep}" INT_DEP) if(PCL_${INT_DEP}_FOUND) list(APPEND PCL_${COMPONENT}_INCLUDE_DIRS ${PCL_${INT_DEP}_INCLUDE_DIRS}) if(PCL_${INT_DEP}_LIBRARIES) - list(APPEND PCL_${COMPONENT}_LIBRARIES "${PCL_${INT_DEP}_LIBRARIES}") + list(APPEND PCL_${COMPONENT}_LINK_LIBRARIES "${PCL_${INT_DEP}_LIBRARIES}") endif(PCL_${INT_DEP}_LIBRARIES) endif(PCL_${INT_DEP}_FOUND) endforeach(int_dep) + if(_is_header_only EQUAL -1) + add_library(${pcl_component} @PCL_LIB_TYPE@ IMPORTED GLOBAL) + if(PCL_${COMPONENT}_LIBRARY_DEBUG) + set_target_properties(${pcl_component} + PROPERTIES + IMPORTED_CONFIGURATIONS "RELEASE;DEBUG" + IMPORTED_LOCATION_RELEASE "${PCL_${COMPONENT}_LIBRARY}" + IMPORTED_LOCATION_DEBUG "${PCL_${COMPONENT}_LIBRARY_DEBUG}" + ) + else() + set_target_properties(${pcl_component} + PROPERTIES + IMPORTED_LOCATION "${PCL_${COMPONENT}_LIBRARY}" + ) + endif() + foreach(def ${PCL_DEFINITIONS}) + string(REPLACE " " ";" def2 ${def}) + string(REGEX REPLACE "^-D" "" def3 "${def2}") + list(APPEND definitions ${def3}) + endforeach() + set_target_properties(${pcl_component} + PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "${definitions}" + INTERFACE_COMPILE_OPTIONS "${PCL_COMPILE_OPTIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${PCL_${COMPONENT}_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${PCL_${COMPONENT}_LINK_LIBRARIES}" + ) + set(PCL_${COMPONENT}_LIBRARIES ${pcl_component}) + endif() endif(PCL_${COMPONENT}_FOUND) endforeach(component) From f91d6b94bd554e56a01f280184129f5b55fbde3d Mon Sep 17 00:00:00 2001 From: Sergey Alexandrov Date: Tue, 27 Feb 2018 11:13:57 +0100 Subject: [PATCH 3/5] Filter PCL component include directories (remove nonexistent) Some villain dependencies (e.g. VTK) may output nonexistent directories as a part of their include list. Filter such bogus entries out. --- PCLConfig.cmake.in | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PCLConfig.cmake.in b/PCLConfig.cmake.in index 90c46321a2f..c1b73efd9fe 100644 --- a/PCLConfig.cmake.in +++ b/PCLConfig.cmake.in @@ -530,9 +530,16 @@ foreach(component ${PCL_TO_FIND_COMPONENTS}) if(PCL_${COMPONENT}_FOUND) if(NOT "${PCL_${COMPONENT}_INCLUDE_DIRS}" STREQUAL "") - list(REMOVE_DUPLICATES PCL_${COMPONENT}_INCLUDE_DIRS) + set(_filtered "") + foreach(_inc ${PCL_${COMPONENT}_INCLUDE_DIRS}) + if(EXISTS ${_inc}) + list(APPEND _filtered "${_inc}") + endif() + endforeach() + list(REMOVE_DUPLICATES _filtered) + set(PCL_${COMPONENT}_INCLUDE_DIRS ${_filtered}) + list(APPEND PCL_INCLUDE_DIRS ${_filtered}) endif(NOT "${PCL_${COMPONENT}_INCLUDE_DIRS}" STREQUAL "") - list(APPEND PCL_INCLUDE_DIRS ${PCL_${COMPONENT}_INCLUDE_DIRS}) mark_as_advanced(PCL_${COMPONENT}_INCLUDE_DIRS) if(_is_header_only EQUAL -1) list(APPEND PCL_DEFINITIONS ${PCL_${COMPONENT}_DEFINITIONS}) From 267814746c26b3d699bda4c8f4d52f738b42bcbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Agostinho?= Date: Sun, 26 Aug 2018 23:20:30 +0100 Subject: [PATCH 4/5] Don't check and set SSE compile flags if other compile flags are provided. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 724cf1024c0..ffebbda3523 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,7 +107,7 @@ endif() # check for SSE flags include("${PCL_SOURCE_DIR}/cmake/pcl_find_sse.cmake") -if(PCL_ENABLE_SSE) +if(PCL_ENABLE_SSE AND "${CMAKE_CXX_FLAGS}" STREQUAL "") PCL_CHECK_FOR_SSE() endif() From a5ad7495162163c3a24b6cc36326f2600e145500 Mon Sep 17 00:00:00 2001 From: Sergio Agostinho Date: Wed, 5 Sep 2018 17:13:41 -0700 Subject: [PATCH 5/5] Set IMPORTED_IMPLIB for importing pcl on Windows --- PCLConfig.cmake.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PCLConfig.cmake.in b/PCLConfig.cmake.in index c1b73efd9fe..851f5f1377a 100644 --- a/PCLConfig.cmake.in +++ b/PCLConfig.cmake.in @@ -568,11 +568,14 @@ foreach(component ${PCL_TO_FIND_COMPONENTS}) IMPORTED_CONFIGURATIONS "RELEASE;DEBUG" IMPORTED_LOCATION_RELEASE "${PCL_${COMPONENT}_LIBRARY}" IMPORTED_LOCATION_DEBUG "${PCL_${COMPONENT}_LIBRARY_DEBUG}" + IMPORTED_IMPLIB_RELEASE "${PCL_${COMPONENT}_LIBRARY}" + IMPORTED_IMPLIB_DEBUG "${PCL_${COMPONENT}_LIBRARY_DEBUG}" ) else() set_target_properties(${pcl_component} PROPERTIES IMPORTED_LOCATION "${PCL_${COMPONENT}_LIBRARY}" + IMPORTED_IMPLIB "${PCL_${COMPONENT}_LIBRARY}" ) endif() foreach(def ${PCL_DEFINITIONS})