Skip to content

Commit

Permalink
Merge pull request #2100 from SergioRAgostinho/compile-options
Browse files Browse the repository at this point in the history
Move sse compiler options to PCL_COMPILE_OPTIONS
  • Loading branch information
taketwo authored Sep 8, 2018
2 parents 5cb9070 + a5ad749 commit 711ce28
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 25 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ 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()

# ---[ 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
57 changes: 47 additions & 10 deletions PCLConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -529,32 +530,68 @@ 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})
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}"
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})
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)

Expand Down
21 changes: 11 additions & 10 deletions cmake/pcl_find_sse.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand All @@ -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)
4 changes: 3 additions & 1 deletion cmake/pcl_pclconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 711ce28

Please sign in to comment.