microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.63k stars 6.25k forks source link

[pcl] missing "/bigobj" under msvc due to comparing ${CMAKE_CXX_FLAGS} to ${CMAKE_CXX_FLAGS_DEFAULT} #23372

Closed yuanchen-zhu closed 8 months ago

yuanchen-zhu commented 2 years ago

The current head version of PCL's CMakeLists.txt has a problematic logic where it adds in required compilation flags only when the condition

${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}"

is true. Just grep the above string in CMakeLists.txt to see a list of them.

The existing fix-check-see.patch fixes one occurrence where comparing CMAKE_CXX_FLAGS against CMAKE_CXX_FLAGS_DEFAULT skips SSE detection.

Another occurrence is that for msvc, the "/bigobj" compilation flag is only added if the above condition holds. When building with vcpkg + MSVC, it seems CMAKE_CXX_FLAGS is often not equal to CMAKE_CXX_FLAGS_DEFAULT. This causes compilation eeor while building some of the larger source files.

Proposed solution

I have to use the following patch to make it work:

--- CMakeLists.txt.org  2022-03-03 21:28:02.780958900 -0800
+++ CMakeLists.txt  2022-03-03 21:28:20.408494400 -0800
@@ -142,7 +142,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 ${SSE_DEFINITIONS}")

-  if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
+  if(1)
     string(APPEND CMAKE_CXX_FLAGS " /fp:precise /wd4800 /wd4521 /wd4251 /wd4275 /wd4305 /wd4355 ${SSE_FLAGS} ${AVX_FLAGS} /bigobj")

     # Add extra code generation/link optimizations

Additional context

There are some additional occurrences of this comparison logic in CMakeList.txt: In particular, one is associated with checking for avx, and another for disabling a warning under clang. These are admittedly less urgent and won't trigger a compilation error.

Also to make the current port work the pcl head, I had to make a few more straightforward adjustments to the existing list of patches.

JackBoosY commented 2 years ago

Hmm... I don't remember why I set the condition to 1, but it must have some issues there. Can you please provide the failure logs?

Thanks.

yuanchen-zhu commented 2 years ago

Without the fix mentioned, I get the following error in install-x64-windows-dbg-out.log.

Note that in my port file, I'm pointing to a version of pcl that's close to master, so newer than the current vcpkg master port. I just want to raise this issue to save you folks some work when you invariably upgrade to 1.12.1+ for your pcl port.

[25/433] "C:\PROGRA~2\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe"   /TP -DPCLAPI_EXPORTS -D_ENABLE_EXTENDED_ALIGNED_STORAGE -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\x64-windows-dbg\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\common\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\sample_consensus\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\search\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\kdtree\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\octree\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\filters\include -IC:\Users\yzhu\proj\2015-face-change\mvp\vcpkg_installed\x64-windows\include\eigen3 -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\recognition\include\pcl\recognition\3rdparty -IC:\Users\yzhu\proj\2015-face-change\mvp\vcpkg_installed\x64-windows\include /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP  /FS -DBOOST_ALL_DYN_LINK -DBOOST_ALL_NO_LIB /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1    -DBOOST_ALL_NO_LIB -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DNOMINMAX -DPCL_ONLY_CORE_POINT_TYPES  -D__SSE4_2__ -D__SSE4_1__ -D__SSSE3__ -D__SSE3__ -D__SSE2__ -D__SSE__ -std:c++14 /showIncludes /Fofilters\CMakeFiles\pcl_filters.dir\src\voxel_grid_covariance.cpp.obj /Fdfilters\CMakeFiles\pcl_filters.dir\ /FS -c C:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\filters\src\voxel_grid_covariance.cpp

FAILED: filters/CMakeFiles/pcl_filters.dir/src/voxel_grid_covariance.cpp.obj 

"C:\PROGRA~2\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe"   /TP -DPCLAPI_EXPORTS -D_ENABLE_EXTENDED_ALIGNED_STORAGE -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\x64-windows-dbg\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\common\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\sample_consensus\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\search\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\kdtree\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\octree\include -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\filters\include -IC:\Users\yzhu\proj\2015-face-change\mvp\vcpkg_installed\x64-windows\include\eigen3 -IC:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\recognition\include\pcl\recognition\3rdparty -IC:\Users\yzhu\proj\2015-face-change\mvp\vcpkg_installed\x64-windows\include /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP  /FS -DBOOST_ALL_DYN_LINK -DBOOST_ALL_NO_LIB /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1    -DBOOST_ALL_NO_LIB -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DNOMINMAX -DPCL_ONLY_CORE_POINT_TYPES  -D__SSE4_2__ -D__SSE4_1__ -D__SSSE3__ -D__SSE3__ -D__SSE2__ -D__SSE__ -std:c++14 /showIncludes /Fofilters\CMakeFiles\pcl_filters.dir\src\voxel_grid_covariance.cpp.obj /Fdfilters\CMakeFiles\pcl_filters.dir\ /FS -c C:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\filters\src\voxel_grid_covariance.cpp

C:\Users\yzhu\share\vcpkg\buildtrees\pcl\src\dcb8d686c4-ef8ca80bcd.clean\filters\src\voxel_grid_covariance.cpp : fatal error C1128: number of sections exceeded object file format limit: compile with /bigobj
LilyWangLL commented 8 months ago

This issue has been fixed in PR https://github.com/microsoft/vcpkg/pull/28818, so I am closing this issue for now.