Skip to content

Commit

Permalink
Detect if _FILE_OFFSET_BITS=64 is required at configuration time via …
Browse files Browse the repository at this point in the history
…try_compile
  • Loading branch information
ptheywood committed Nov 21, 2023
1 parent 58232b0 commit b80c87d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
19 changes: 19 additions & 0 deletions cmake/CheckCompilerFunctionality.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ function(flamegpu_check_compiler_functionality)
endif()
endif()

if (NOT MSVC)
# Jitify2 on linux requires uses F_OFD_SETLKW or -D_FILE_OFFSET_BITS=64.
# Cannot detect the presence of this from CMAKE_SYSTEM_VERSION when in a container, so try to compile with it and if an error occurs then we must define this option.
# If required, sets a cmake cahce internal variable FLAMEGPU__FILE_OFFSET_BITS_64_REQUIRED to true
try_compile(
LINUX_F_OFD_SETLKW
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
"${CMAKE_CURRENT_LIST_DIR}/CheckCompilerFunctionality/F_OFD_SETLKW.cpp"
CXX_STANDARD 17
CUDA_STANDARD 17
CXX_STANDARD_REQUIRED "ON"
)
if(NOT LINUX_F_OFD_SETLKW)
set(FLAMEGPU__FILE_OFFSET_BITS_64_REQUIRED "true" CACHE INTERNAL "if _FILE_OFFSET_BITS=64 required for jitify2")
else()
set(FLAMEGPU__FILE_OFFSET_BITS_64_REQUIRED "false" CACHE INTERNAL "if _FILE_OFFSET_BITS=64 required for jitify2")
endif()
endif()

# If we made it this far, set the result variable to be truthy
set(FLAMEGPU_CheckCompilerFunctionality_RESULT "YES" PARENT_SCOPE)
endfunction()
Expand Down
10 changes: 10 additions & 0 deletions cmake/CheckCompilerFunctionality/F_OFD_SETLKW.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifdef __linux__
#include <fcntl.h>
#endif // __linux__

int main (int argc, char * argv[]) {
#ifndef F_OFD_SETLKW
#error F_OFD_SETLKW is not defined; try building with -D_FILE_OFFSET_BITS=64
#endif // F_OFD_SETLKW
return 0;
}
7 changes: 4 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,11 @@ if(FLAMEGPU_ENABLE_NVTX AND TARGET NVTX::nvtx)
unset(nvtxversion)
endif()

# Jitify2 requires separate compilation options for older linux kernels (i.e. manylinux2014), so detect and set an additional compile definition in this case
# if(CMAKE_SYSTEM_VERSION VERSION_LESS 3.15)
# Jitify2 requires separate compilation options for older linux kernels (i.e. manylinux2014).
# This is detected in cmake/CheckCompilerFunctionality.cmake and a boolean internal cache variable is stores if this is required or not.
if(FLAMEGPU__FILE_OFFSET_BITS_64_REQUIRED)
target_compile_definitions(${PROJECT_NAME} PUBLIC "_FILE_OFFSET_BITS=64")
# endif()
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC Jitify::jitify)
# jitify is included in public headers, so this definiition must be public too.
target_compile_definitions(${PROJECT_NAME} PUBLIC "JITIFY_PRINT_LOG")
Expand Down

0 comments on commit b80c87d

Please sign in to comment.