Skip to content

Commit

Permalink
Change: Remove fastgltf_simdjson target, update to 3.3.6
Browse files Browse the repository at this point in the history
Fixes #35, closes #44.
  • Loading branch information
spnda committed Jan 17, 2024
1 parent 0f87a1f commit 3dd326e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 75 deletions.
107 changes: 43 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ endif()

project(fastgltf VERSION 0.6.1 LANGUAGES C CXX)

option(FASTGLTF_DOWNLOAD_SIMDJSON "Downloads a copy of simdjson itself to satisfy the dependency" ON)
option(FASTGLTF_USE_CUSTOM_SMALLVECTOR "Uses a custom SmallVector type optimised for small arrays" OFF)
option(FASTGLTF_ENABLE_TESTS "Enables test targets for fastlgtf" OFF)
option(FASTGLTF_ENABLE_EXAMPLES "Enables example targets for fastgltf" OFF)
Expand All @@ -22,66 +21,6 @@ option(FASTGLTF_USE_64BIT_FLOAT "Default to 64-bit double precision floats for e
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/add_source_directory.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler_flags.cmake)

if (FASTGLTF_DOWNLOAD_SIMDJSON)
# Download and configure simdjson
set(SIMDJSON_TARGET_VERSION "3.3.0")
set(SIMDJSON_DL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/deps/simdjson")
file(MAKE_DIRECTORY ${SIMDJSON_DL_DIR})

set(SIMDJSON_HEADER_FILE "${SIMDJSON_DL_DIR}/simdjson.h")
set(SIMDJSON_SOURCE_FILE "${SIMDJSON_DL_DIR}/simdjson.cpp")

macro(download_simdjson)
file(DOWNLOAD "https://raw.githubusercontent.com/simdjson/simdjson/v${SIMDJSON_TARGET_VERSION}/singleheader/simdjson.h" ${SIMDJSON_HEADER_FILE})
file(DOWNLOAD "https://raw.githubusercontent.com/simdjson/simdjson/v${SIMDJSON_TARGET_VERSION}/singleheader/simdjson.cpp" ${SIMDJSON_SOURCE_FILE})
endmacro()

if (EXISTS ${SIMDJSON_HEADER_FILE})
# Look for the SIMDJSON_VERSION define in the header to check the version.
file(STRINGS ${SIMDJSON_HEADER_FILE} SIMDJSON_HEADER_VERSION_LINE REGEX "^#define SIMDJSON_VERSION ")
string(REGEX MATCHALL "[0-9.]+" SIMDJSON_HEADER_VERSION "${SIMDJSON_HEADER_VERSION_LINE}")
message(STATUS "fastgltf: Found simdjson (Version ${SIMDJSON_HEADER_VERSION})")
if (SIMDJSON_HEADER_VERSION VERSION_LESS SIMDJSON_TARGET_VERSION)
message(STATUS "fastgltf: simdjson outdated, downloading...")
download_simdjson()
endif()
else()
message(STATUS "fastgltf: Did not find simdjson, downloading...")
download_simdjson()

if (NOT EXISTS "${SIMDJSON_HEADER_FILE}")
message(FATAL_ERROR "fastgltf: Failed to download simdjson.")
endif()
endif()

add_library(fastgltf_simdjson ${SIMDJSON_HEADER_FILE} ${SIMDJSON_SOURCE_FILE})
target_compile_features(fastgltf_simdjson PRIVATE cxx_std_17)
target_include_directories(fastgltf_simdjson PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/deps/simdjson> $<INSTALL_INTERFACE:include>)
fastgltf_compiler_flags(fastgltf_simdjson)
fastgltf_enable_debug_inlining(fastgltf_simdjson)

install(
FILES deps/simdjson/simdjson.h
DESTINATION include
)

install(
TARGETS fastgltf_simdjson
EXPORT fastgltf_simdjson-targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

install(
EXPORT fastgltf_simdjson-targets
FILE fastgltf_simdjsonTargets.cmake
NAMESPACE fastgltf::
DESTINATION lib/cmake/fastgltf
)
endif()

# Create the library target
add_library(fastgltf
"src/fastgltf.cpp" "src/base64.cpp"
Expand All @@ -96,10 +35,50 @@ target_include_directories(fastgltf PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIS
set_target_properties(fastgltf PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)
set_target_properties(fastgltf PROPERTIES VERSION ${PROJECT_VERSION})

if (TARGET fastgltf_simdjson)
target_link_libraries(fastgltf PRIVATE fastgltf_simdjson)
elseif(TARGET simdjson::simdjson)
# If the target already exists due to the parent script already including it as a dependency, just directly link it.
if (TARGET simdjson::simdjson)
target_link_libraries(fastgltf PRIVATE simdjson::simdjson)
else()
# Try to find simdjson through a find_package call.
find_package(simdjson CONFIG)
if (simdjson_FOUND)
message(STATUS "fastgltf: Found simdjson config")
target_link_libraries(fastgltf PRIVATE simdjson::simdjson)
else()
# Download and configure simdjson
set(SIMDJSON_TARGET_VERSION "3.3.6")
set(SIMDJSON_DL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/deps/simdjson")
file(MAKE_DIRECTORY ${SIMDJSON_DL_DIR})

set(SIMDJSON_HEADER_FILE "${SIMDJSON_DL_DIR}/simdjson.h")
set(SIMDJSON_SOURCE_FILE "${SIMDJSON_DL_DIR}/simdjson.cpp")

macro(download_simdjson)
file(DOWNLOAD "https://raw.githubusercontent.com/simdjson/simdjson/v${SIMDJSON_TARGET_VERSION}/singleheader/simdjson.h" ${SIMDJSON_HEADER_FILE})
file(DOWNLOAD "https://raw.githubusercontent.com/simdjson/simdjson/v${SIMDJSON_TARGET_VERSION}/singleheader/simdjson.cpp" ${SIMDJSON_SOURCE_FILE})
endmacro()

if (EXISTS ${SIMDJSON_HEADER_FILE})
# Look for the SIMDJSON_VERSION define in the header to check the version.
file(STRINGS ${SIMDJSON_HEADER_FILE} SIMDJSON_HEADER_VERSION_LINE REGEX "^#define SIMDJSON_VERSION ")
string(REGEX MATCHALL "[0-9.]+" SIMDJSON_HEADER_VERSION "${SIMDJSON_HEADER_VERSION_LINE}")
message(STATUS "fastgltf: Found simdjson (Version ${SIMDJSON_HEADER_VERSION})")
if (SIMDJSON_HEADER_VERSION VERSION_LESS SIMDJSON_TARGET_VERSION)
message(STATUS "fastgltf: simdjson outdated, downloading...")
download_simdjson()
endif()
else()
message(STATUS "fastgltf: Did not find simdjson, downloading...")
download_simdjson()

if (NOT EXISTS "${SIMDJSON_HEADER_FILE}")
message(FATAL_ERROR "fastgltf: Failed to download simdjson.")
endif()
endif()

fastgltf_add_source_directory(TARGET fastgltf FOLDER ${SIMDJSON_DL_DIR})
target_include_directories(fastgltf PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/deps/simdjson> $<INSTALL_INTERFACE:include>)
endif()
endif()

if (SIMDJSON_TARGET_VERSION)
Expand Down
10 changes: 0 additions & 10 deletions docs/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ Options
CMake options
=============

``FASTGLTF_DOWNLOAD_SIMDJSON``
------------------------------

A ``BOOL`` option that tells fastgltf's CMake script whether it should download the simdjson sources itself.

* If set to ``YES`` the script will automatically download the amalgamated simdjson header and source files and link them into fastgltf.
* If set to ``NO`` the CMake script expects a ``simdjson::simdjson`` target to exist against which it tries to link.
This target needs to also use the amalgamated simdjson.h header.


``FASTGLTF_USE_64BIT_FLOAT``
----------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_executable(fastgltf_tests EXCLUDE_FROM_ALL
"base64_tests.cpp" "basic_test.cpp" "benchmarks.cpp" "glb_tests.cpp" "gltf_path.hpp"
"vector_tests.cpp" "uri_tests.cpp" "extension_tests.cpp" "accessor_tests.cpp")
target_compile_features(fastgltf_tests PRIVATE cxx_std_17)
target_link_libraries(fastgltf_tests PRIVATE fastgltf fastgltf_simdjson)
target_link_libraries(fastgltf_tests PRIVATE fastgltf)
target_link_libraries(fastgltf_tests PRIVATE glm::glm Catch2::Catch2WithMain)
fastgltf_compiler_flags(fastgltf_tests)

Expand Down

0 comments on commit 3dd326e

Please sign in to comment.