OpenUSD icon indicating copy to clipboard operation
OpenUSD copied to clipboard

Fails with PXR_BUILD_IMAGING=ON: Cannot find source file: /usr/ports/misc/usd/work/USD-21.11/pxr/imaging/garch/.h

Open yurivict opened this issue 4 years ago • 14 comments

Description of Issue

cmake is called with these arguments:

-DPXR_BUILD_IMAGING:BOOL=true -DPTEX_INCLUDE_DIR=/usr/local/include -DPXR_BUILD_USD_TOOLS:BOOL=true -DCMAKE_C_COMPILER:STRING="cc"  -DCMAKE_CXX_COMPILER:STRING="c++"  -DCMAKE_C_FLAGS:STRING="-O2 -pipe -fno-omit-frame-pointer  -fstack-protector-strong -fno-strict-aliasing "  -DCMAKE_C_FLAGS_DEBUG:STRING="-O2 -pipe -fno-omit-frame-pointer  -fstack-protector-strong -fno-strict-aliasing "  -DCMAKE_C_FLAGS_RELEASE:STRING="-O2 -pipe -fno-omit-frame-pointer  -fstack-protector-strong -fno-strict-aliasing "  -DCMAKE_CXX_FLAGS:STRING="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer  "  -DCMAKE_CXX_FLAGS_DEBUG:STRING="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer  "  -DCMAKE_CXX_FLAGS_RELEASE:STRING="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer  "  -DCMAKE_EXE_LINKER_FLAGS:STRING=" -fstack-protector-strong "  -DCMAKE_MODULE_LINKER_FLAGS:STRING=" -fstack-protector-strong "  -DCMAKE_SHARED_LINKER_FLAGS:STRING=" -fstack-protector-strong "  -DCMAKE_INSTALL_PREFIX:PATH="/usr/local"  -DCMAKE_BUILD_TYPE:STRING="Release"  -DTHREADS_HAVE_PTHREAD_ARG:BOOL=YES  -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=YES  -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DPXR_BUILD_TESTS:BOOL=OFF -DPXR_BUILD_EXAMPLES:BOOL=OFF -DPXR_BUILD_TUTORIALS:BOOL=OFF -DPXR_ENABLE_PYTHON_SUPPORT:BOOL=OFF -GNinja

Failure:

-- Configuring done
CMake Error at cmake/macros/Private.cmake:1177 (add_library):
  Cannot find source file:

    /disk-samsung/freebsd-ports/misc/usd/work/USD-21.11/pxr/imaging/garch/.h

yurivict avatar Dec 05 '21 21:12 yurivict

Filed as internal issue #USD-7058

jilliene avatar Dec 08 '21 23:12 jilliene

I think this is caused by X11_FOUND is false.

ivwumupy avatar Jun 07 '23 13:06 ivwumupy

This bug is still here on 24.08.

VVD avatar Aug 19 '24 19:08 VVD

@VVD If you can repro, could you try adding a final else() clause in this conditional in garch/CMakelists.txt?

if(APPLE)
    set(GARCH_GLPLATFORMCONTEXT       glPlatformContextDarwin)
    set(GARCH_GLPLATFORMDEBUGWINDOW   glPlatformDebugWindowDarwin)
    set(GARCH_SOURCE_EXTENSION        mm)
    set(GARCH_PLATFORM_LIBRARIES      "-framework AppKit")
elseif(X11_FOUND)
    set(GARCH_GLPLATFORMCONTEXT       glPlatformContextGLX)
    set(GARCH_GLPLATFORMDEBUGWINDOW   glPlatformDebugWindowGLX)
    set(GARCH_SOURCE_EXTENSION        cpp)
elseif(WIN32)
    set(GARCH_GLPLATFORMCONTEXT       glPlatformContextWindows)
    set(GARCH_GLPLATFORMDEBUGWINDOW   glPlatformDebugWindowWindows)
    set(GARCH_SOURCE_EXTENSION        cpp)
endif()

something like

        if(UNIX AND NOT APPLE)
           message(STATUS
               "Skipping ${PXR_PACKAGE} because X11 is not available.")
        else()
            message(STATUS
               "Skipping ${PXR_PACKAGE} because OpenGL is not available.")
       endif()

and let us know if that resolves it for you?

meshula avatar Aug 19 '24 19:08 meshula

-- Skipping Python program usdstitch, Python modules required
-- Skipping Python program usdstitchclips, Python modules required
-- Skipping Python program usdzip, Python modules required
-- Skipping garch because X11 is not available.
-- Skipping hgiMetal because PXR_BUILD_GPU_SUPPORT or PXR_ENABLE_METAL_SUPPORT is OFF
-- Skipping hgiVulkan because PXR_BUILD_GPU_SUPPORT or PXR_ENABLE_VULKAN_SUPPORT is OFF
-- Skipping building hdGenSchema, Python modules required.
-- Skipping Python program usdrecord, Python modules required
-- Configuring done (1.6s)
CMake Error at cmake/macros/Private.cmake:1239 (add_library):
  Cannot find source file:

    /tmp/work/usr/ports/misc/openusd/work/OpenUSD-24.08/pxr/imaging/garch/.h

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
  .ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
  .f95 .f03 .hip .ispc
Call Stack (most recent call first):
  cmake/macros/Public.cmake:321 (_pxr_library)
  pxr/imaging/garch/CMakeLists.txt:33 (pxr_library)


CMake Error at cmake/macros/Private.cmake:1239 (add_library):
  No SOURCES given to target: garch
Call Stack (most recent call first):
  cmake/macros/Public.cmake:321 (_pxr_library)
  pxr/imaging/garch/CMakeLists.txt:33 (pxr_library)

Added this line: -- Skipping garch because X11 is not available.

VVD avatar Aug 19 '24 20:08 VVD

Maybe that's enough to help people debug the problem if they encounter it?

I don't know if people have suggestions for better reporting, but at least there's some diagnostic output to explain the failure in trying to build garch. Maybe there could be an earlier test, that if imaging is requested, and you are on linux, and X11 is not found, it could error out at that point.

meshula avatar Aug 19 '24 21:08 meshula

We are on FreeBSD and X11 is installed. (I am writing this message now on FreeBSD+KDE5+xorg+Firefox.)

VVD avatar Aug 19 '24 21:08 VVD

got it. We test for X11_FOUND, which should have been set by

    if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
        find_package(X11)
    endif()

around line 276 in Packages.cmake.

Does this fix it? I suspect the SYSTEM_NAME might be the problem.

if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
   find_package(X11)
endif()

meshula avatar Aug 19 '24 22:08 meshula

Thanks. This work! Maybe better something like this:

if (NOT (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "Windows"))
   find_package(X11)
endif()

For support other BSDs.

VVD avatar Aug 20 '24 00:08 VVD

My current set of patches (hacks!) for support FreeBSD (Updated 2024-08-20):
--- cmake/defaults/Packages.cmake.orig  2024-07-24 22:34:34 UTC
+++ cmake/defaults/Packages.cmake
@@ -273,7 +273,8 @@ if (PXR_BUILD_IMAGING)
         add_definitions(-DPXR_OPENVDB_SUPPORT_ENABLED)
     endif()
     # --X11
-    if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+    #if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+    if (NOT (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "Windows"))
         find_package(X11)
     endif()
     # --Embree
--- pxr/base/arch/assumptions.cpp.orig  2024-07-24 22:34:34 UTC
+++ pxr/base/arch/assumptions.cpp
@@ -33,8 +33,10 @@ Arch_ObtainCacheLineSize()
 static size_t
 Arch_ObtainCacheLineSize()
 {
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) && !defined(ARCH_OS_FREEBSD)
     return sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+#elif defined(ARCH_OS_FREEBSD)
+    return 64;
 #elif defined(ARCH_OS_DARWIN)
     size_t cacheLineSize = 0;
     size_t cacheLineSizeSize = sizeof(cacheLineSize);
--- pxr/base/arch/debugger.cpp.orig     2024-07-24 22:34:34 UTC
+++ pxr/base/arch/debugger.cpp
@@ -325,7 +325,7 @@ Arch_DebuggerAttachExecPosix(void* data)

 #endif // defined(ARCH_OS_LINUX) || defined(ARCH_OS_DARWIN)

-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) && !defined(ARCH_OS_FREEBSD)

 static
 bool
@@ -371,6 +371,15 @@ Arch_DebuggerIsAttachedPosix()
     }
     return false;

+}
+
+#elif defined(ARCH_OS_FREEBSD)
+
+static
+bool
+Arch_DebuggerIsAttachedPosix()
+{
+    return false;
 }

 #elif defined(ARCH_OS_DARWIN)
--- pxr/base/arch/defines.h.orig        2024-07-24 22:34:34 UTC
+++ pxr/base/arch/defines.h
@@ -13,6 +13,9 @@

 #if defined(__linux__)
 #define ARCH_OS_LINUX
+#elif defined(__FreeBSD__)
+#define ARCH_OS_FREEBSD
+#define ARCH_OS_LINUX
 #elif defined(__APPLE__)
 #include "TargetConditionals.h"
 #define ARCH_OS_DARWIN
--- pxr/base/arch/fileSystem.cpp.orig   2024-07-24 22:34:34 UTC
+++ pxr/base/arch/fileSystem.cpp
@@ -34,7 +34,11 @@
 #include <Windows.h>
 #include <WinIoCtl.h>
 #else
+#if defined(ARCH_OS_FREEBSD)
+#include <stdlib.h>
+#else
 #include <alloca.h>
+#endif
 #include <sys/mman.h>
 #include <sys/file.h>
 #include <unistd.h>
@@ -904,8 +908,11 @@ ArchQueryMappedMemoryResidency(
 ArchQueryMappedMemoryResidency(
     void const *addr, size_t len, unsigned char *pageMap)
 {
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) && !defined(ARCH_OS_FREEBSD)
     int ret = mincore(const_cast<void *>(addr), len, pageMap);
+    return ret == 0;
+#elif defined(ARCH_OS_FREEBSD)
+    int ret = mincore(const_cast<void *>(addr), len, reinterpret_cast<char *>(pageMap));
     return ret == 0;
 #elif defined (ARCH_OS_DARWIN)
     // On darwin the addr param is 'caddr_t' and the vec param is 'char *'.
--- pxr/base/arch/fileSystem.h.orig     2024-07-24 22:34:34 UTC
+++ pxr/base/arch/fileSystem.h
@@ -24,11 +24,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>

-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) && !defined(ARCH_OS_FREEBSD)
 #include <unistd.h>
 #include <sys/statfs.h>
 #include <glob.h>
-#elif defined(ARCH_OS_DARWIN)
+#elif defined(ARCH_OS_DARWIN) || defined(ARCH_OS_FREEBSD)
 #include <unistd.h>
 #include <sys/mount.h>
 #include <glob.h>
--- pxr/base/arch/stackTrace.cpp.orig   2024-07-24 22:34:34 UTC
+++ pxr/base/arch/stackTrace.cpp
@@ -570,7 +570,7 @@ nonLockingFork()
 }
 #endif

-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) && !defined(ARCH_OS_FREEBSD)
 static int
 nonLockingLinux__execve (const char *file,
                          char *const argv[],
@@ -647,7 +647,7 @@ nonLockingExecv(const char *path, char *const argv[])
 static int
 nonLockingExecv(const char *path, char *const argv[])
 {
-#if defined(ARCH_OS_LINUX)
+#if defined(ARCH_OS_LINUX) && !defined(ARCH_OS_FREEBSD)
      return nonLockingLinux__execve (path, argv, __environ);
 #else
      return execv(path, argv);

But I got this error (fixed in patches above):

FAILED: pxr/base/arch/CMakeFiles/arch.dir/assumptions.cpp.o
/usr/bin/c++ -DARCH_EXPORTS=1 -DBOOST_NO_CXX98_FUNCTION_BASE -DBOOST_PYTHON_NO_PY_SIGNATURES -DGLX_GLXEXT_PROTOTYPES -DGL_GLEXT_PROTOTYPES -DMFB_ALT_PACKAGE_NAME=arch -DMFB_PACKAGE_MODULE=Arch -DMFB_PACKAGE_NAME=arch -DPXR_BUILD_LOCATION=usd -DPXR_GL_SUPPORT_ENABLED -DPXR_PLUGIN_BUILD_LOCATION=../plugin/usd -Darch_EXPORTS -I/tmp/work/usr/ports/misc/openusd/work/.build/include -Wall -Wformat-security -pthread -Wno-deprecated -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-command-line-argument -O2 -pipe -march=core2 -fstack-protector-strong -fno-strict-aliasing -O2 -pipe -march=core2 -fstack-protector-strong -fno-strict-aliasing   -DNDEBUG -std=c++17 -fPIC -MD -MT pxr/base/arch/CMakeFiles/arch.dir/assumptions.cpp.o -MF pxr/base/arch/CMakeFiles/arch.dir/assumptions.cpp.o.d -o pxr/base/arch/CMakeFiles/arch.dir/assumptions.cpp.o -c /tmp/work/usr/ports/misc/openusd/work/OpenUSD-24.08/pxr/base/arch/assumptions.cpp
/tmp/work/usr/ports/misc/openusd/work/OpenUSD-24.08/pxr/base/arch/assumptions.cpp:37:20: error: use of undeclared identifier '_SC_LEVEL1_DCACHE_LINESIZE'
   37 |     return sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
      |                    ^
1 error generated.
In function Arch_ObtainCacheLineSize:
static size_t
Arch_ObtainCacheLineSize()
{
#if defined(ARCH_OS_LINUX)
    return sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
#elif defined(ARCH_OS_DARWIN)
    size_t cacheLineSize = 0;
    size_t cacheLineSizeSize = sizeof(cacheLineSize);
    sysctlbyname("hw.cachelinesize", &cacheLineSize, &cacheLineSizeSize, 0, 0);
    return cacheLineSize;
#elif defined(ARCH_OS_WINDOWS)
    DWORD bufferSize = 0;
    using INFO = SYSTEM_LOGICAL_PROCESSOR_INFORMATION;

    // Get the number of bytes required.
    ::GetLogicalProcessorInformation(nullptr, &bufferSize);

    // Get the count of structures
    size_t total = bufferSize / sizeof(INFO);

    // Allocate the array of processor INFOs.
    std::unique_ptr<INFO[]> buffer(new INFO[total]);

    size_t lineSize = 0;
    if (::GetLogicalProcessorInformation(&buffer[0], &bufferSize))
    {
        for (size_t current = 0; current != total; ++current)
        {
            if (buffer[current].Relationship == RelationCache &&
                1 == buffer[current].Cache.Level)
            {
                lineSize = buffer[current].Cache.LineSize;
                break;
            }
        }
    }

    return lineSize;
#else
#error Arch_ObtainCacheLineSize not implemented for OS.
#endif
}

One more "hack" is coming:

#if defined(ARCH_OS_LINUX) && !defined(ARCH_OS_FREEBSD)
    return sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
#elif defined(ARCH_OS_FREEBSD)
    return 64;
#elif defined(ARCH_OS_DARWIN)

VVD avatar Aug 20 '24 01:08 VVD

That's cool :) Are you interested in submitting that as a PR? Those patches represent investigation and bug fixed worth tracking together.

meshula avatar Aug 20 '24 02:08 meshula

@meshula, you can submitting if you can and want, but for now it's set of "hacks". Correct way is define ARCH_OS_POSIX (or ARCH_OS_UNIX or ARCH_OS_UNIX_NOT_DARWIN) for both Linux and FreeBSD (may be for Darwin too?), replace all #if defined(ARCH_OS_LINUX) with #if defined(ARCH_OS_POSIX) and all #if defined(ARCH_OS_LINUX) && !defined(ARCH_OS_FREEBSD) with just #if defined(ARCH_OS_LINUX). But it's a lot of work:

$ grep -R ARCH_OS_LINUX OpenUSD-24.08 | wc -l
     164

P.S. Post with patches (hacks) for FreeBSD support updated.

VVD avatar Aug 20 '24 13:08 VVD

Thanks for putting together this set of hacks and patches, it should unblock others experiencing this issue for now!

meshula avatar Aug 20 '24 15:08 meshula

Thanks for putting together this set of hacks and patches, it should unblock others experiencing this issue for now!

https://github.com/PixarAnimationStudios/OpenUSD/pull/1961 but for old version…

VVD avatar Aug 21 '24 00:08 VVD