From 34c693fe78affb103d41eed9c64acb8b3461e7b6 Mon Sep 17 00:00:00 2001 From: Tom Finegan Date: Thu, 3 Mar 2022 10:08:03 -0800 Subject: [PATCH] Add transcoder testing to Draco's Github CI tests. (#821) This enabled CI testing of transcoder configs and includes a few minor Windows-only bug fixes. Note that this adds flags to skip GltfDecoderTest.ThreeMeshesOneNoMaterialMesh for Windows MSVC CI builds. See https://github.com/google/draco/issues/826 for details. Windows specific updates (these do impact non-Windows builds, but are essentially a no-op there): - Use a local dupe of a constant to avoid DLL linkage issues on Windows in the GLTF encoder test.. - Define DRACO_PI to avoid M_PI and entertaining include ordering issues related to _USE_MATH_DEFINES and interactions between and on Windows (fun include guards and order related things). This is done in core/constants.h. --- .github/workflows/ci.yml | 131 +++++++++++++++++++++++++++ CMakeLists.txt | 5 +- src/draco/core/constants.h | 6 ++ src/draco/io/gltf_decoder_test.cc | 5 +- src/draco/io/gltf_encoder_test.cc | 7 +- src/draco/scene/light.cc | 5 +- src/draco/scene/light_test.cc | 12 +-- src/draco/tools/install_test/main.cc | 14 +++ src/draco/tools/install_test/test.py | 127 ++++++++++++++++++++++++-- 9 files changed, 292 insertions(+), 20 deletions(-) create mode 100644 src/draco/core/constants.h diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33af1f1..fcbfc43 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,16 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . -- -j2 draco_test_command: ./draco_tests + - test_name: macos-make-release-shared-with-transcoder + os: macos-latest + cmake_configure_command: |- + cmake .. -G "Unix Makefiles" \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . -- -j2 + draco_test_command: ./draco_tests - test_name: macos-make-release-static os: macos-latest @@ -38,6 +48,16 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . -- -j2 draco_test_command: ./draco_tests + - test_name: macos-make-release-static-with-transcoder + os: macos-latest + cmake_configure_command: |- + cmake .. -G "Unix Makefiles" \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . -- -j2 + draco_test_command: ./draco_tests - test_name: macos-xcode-release-shared os: macos-latest @@ -48,6 +68,16 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . --config Release draco_test_command: Release/draco_tests + - test_name: macos-xcode-release-shared-with-transcoder + os: macos-latest + cmake_configure_command: |- + cmake .. -G Xcode \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_CONFIGURATION_TYPES=Release \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . --config Release + draco_test_command: Release/draco_tests - test_name: macos-xcode-release-static os: macos-latest @@ -58,6 +88,16 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . --config Release draco_test_command: Release/draco_tests + - test_name: macos-xcode-release-static-with-transcoder + os: macos-latest + cmake_configure_command: |- + cmake .. -G Xcode \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_CONFIGURATION_TYPES=Release \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . --config Release + draco_test_command: Release/draco_tests - test_name: ubuntu-make-release-shared os: ubuntu-latest @@ -70,6 +110,18 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . -- -j2 draco_test_command: ./draco_tests + - test_name: ubuntu-make-release-shared-with-transcoder + os: ubuntu-latest + cmake_configure_command: |- + cmake .. -G "Unix Makefiles" \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER=gcc-10 \ + -DCMAKE_CXX_COMPILER=g++-10 \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . -- -j2 + draco_test_command: ./draco_tests - test_name: ubuntu-make-release-static os: ubuntu-latest @@ -82,6 +134,18 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . -- -j2 draco_test_command: ./draco_tests + - test_name: ubuntu-make-release-static-with-transcoder + os: ubuntu-latest + cmake_configure_command: |- + cmake .. -G "Unix Makefiles" \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER=gcc-10 \ + -DCMAKE_CXX_COMPILER=g++-10 \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . -- -j2 + draco_test_command: ./draco_tests - test_name: windows-msvc-release-shared os: windows-2019 @@ -92,6 +156,20 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . --config Release -- -m:2 draco_test_command: Release/draco_tests + - test_name: windows-msvc-release-shared-with-transcoder + os: windows-2019 + cmake_configure_command: |- + cmake .. -G "Visual Studio 16 2019" \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_CONFIGURATION_TYPES=Release \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . --config Release -- -m:2 + # TODO(https://github.com/google/draco/issues/826) + draco_test_command: |- + Release/draco_tests \ + --gtest_filter=-GltfDecoderTest.ThreeMeshesOneNoMaterialMesh + - test_name: windows-msvc-release-static os: windows-2019 @@ -102,6 +180,20 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . --config Release -- -m:2 draco_test_command: Release/draco_tests + - test_name: windows-msvc-release-static-with-transcoder + os: windows-2019 + cmake_configure_command: |- + cmake .. -G "Visual Studio 16 2019" \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_CONFIGURATION_TYPES=Release \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . --config Release -- -m:2 + # TODO(https://github.com/google/draco/issues/826) + draco_test_command: |- + Release/draco_tests \ + --gtest_filter=-GltfDecoderTest.ThreeMeshesOneNoMaterialMesh + - test_name: windows-make-release-shared os: windows-2019 @@ -114,6 +206,18 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . -- -j2 draco_test_command: ./draco_tests + - test_name: windows-make-release-shared-with-transcoder + os: windows-2019 + cmake_configure_command: |- + cmake .. -G "MinGW Makefiles" \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \ + -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . -- -j2 + draco_test_command: ./draco_tests - test_name: windows-make-release-static os: windows-2019 @@ -126,6 +230,18 @@ jobs: -DDRACO_TESTS=ON cmake_build_command: cmake --build . -- -j2 draco_test_command: ./draco_tests + - test_name: windows-make-release-static-with-transcoder + os: windows-2019 + cmake_configure_command: |- + cmake .. -G "MinGW Makefiles" \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \ + -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \ + -DDRACO_TESTS=ON \ + -DDRACO_TRANSCODER_SUPPORTED=ON + cmake_build_command: cmake --build . -- -j2 + draco_test_command: ./draco_tests name: test-${{ matrix.test_name }} runs-on: ${{ matrix.os }} @@ -163,22 +279,37 @@ jobs: - test_name: ubuntu-make os: ubuntu-latest test_command: python3 test.py -v -G "Unix Makefiles" + - test_name: ubuntu-make-with-transcoder + os: ubuntu-latest + test_command: python3 test.py -v -t -G "Unix Makefiles" - test_name: macos-make os: macos-latest test_command: python3 test.py -v -G "Unix Makefiles" + - test_name: macos-make-with-transcoder + os: macos-latest + test_command: python3 test.py -v -t -G "Unix Makefiles" - test_name: macos-xcode os: macos-latest test_command: python3 test.py -v -G Xcode + - test_name: macos-xcode-with-transcoder + os: macos-latest + test_command: python3 test.py -v -t -G Xcode - test_name: windows-make os: windows-2019 test_command: python3 test.py -v -G "MinGW Makefiles" + - test_name: windows-make-with-transcoder + os: windows-2019 + test_command: python3 test.py -v -t -G "MinGW Makefiles" - test_name: windows-msvc os: windows-2019 test_command: python3 test.py -v -G "Visual Studio 16 2019" + - test_name: windows-msvc-with-transcoder + os: windows-2019 + test_command: python3 test.py -v -t -G "Visual Studio 16 2019" name: install-test-${{ matrix.test_name }} runs-on: ${{ matrix.os }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 0362420..e551901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,9 +246,11 @@ list(APPEND draco_dec_config_sources list(APPEND draco_compression_decode_sources "${draco_src_root}/compression/decode.cc" - "${draco_src_root}/compression/decode.h") + "${draco_src_root}/compression/decode.h" + "${draco_src_root}/compression/draco_compression_options.h") list(APPEND draco_compression_encode_sources + "${draco_src_root}/compression/draco_compression_options.h" "${draco_src_root}/compression/encode.cc" "${draco_src_root}/compression/encode.h" "${draco_src_root}/compression/encode_base.h" @@ -337,6 +339,7 @@ list(APPEND draco_core_sources "${draco_src_root}/core/bit_utils.h" "${draco_src_root}/core/bounding_box.cc" "${draco_src_root}/core/bounding_box.h" + "${draco_src_root}/core/constants.h" "${draco_src_root}/core/cycle_timer.cc" "${draco_src_root}/core/cycle_timer.h" "${draco_src_root}/core/data_buffer.cc" diff --git a/src/draco/core/constants.h b/src/draco/core/constants.h new file mode 100644 index 0000000..3e81992 --- /dev/null +++ b/src/draco/core/constants.h @@ -0,0 +1,6 @@ +#ifndef DRACO_CORE_CONSTANTS_H_ +#define DRACO_CORE_CONSTANTS_H_ + +#define DRACO_PI 3.14159265358979323846 + +#endif // DRACO_CORE_CONSTANTS_H_ diff --git a/src/draco/io/gltf_decoder_test.cc b/src/draco/io/gltf_decoder_test.cc index 58e3303..0e5a074 100644 --- a/src/draco/io/gltf_decoder_test.cc +++ b/src/draco/io/gltf_decoder_test.cc @@ -22,6 +22,7 @@ #include #ifdef DRACO_TRANSCODER_SUPPORTED +#include "draco/core/constants.h" #include "draco/core/draco_test_base.h" #include "draco/core/draco_test_utils.h" #include "draco/core/draco_types.h" @@ -1156,7 +1157,7 @@ TEST(GltfDecoderTest, DecodeLightsIntoScene) { ASSERT_EQ(light.GetType(), draco::Light::POINT); ASSERT_EQ(light.GetRange(), 1000); ASSERT_EQ(light.GetInnerConeAngle(), 0.0); - ASSERT_NEAR(light.GetOuterConeAngle(), M_PI / 4.0f, 1e-8); + ASSERT_NEAR(light.GetOuterConeAngle(), DRACO_PI / 4.0f, 1e-8); // Check directional light with some properties specified. light = *scene->GetLight(LightIndex(2)); @@ -1174,7 +1175,7 @@ TEST(GltfDecoderTest, DecodeLightsIntoScene) { ASSERT_EQ(light.GetType(), draco::Light::SPOT); ASSERT_EQ(light.GetRange(), std::numeric_limits::max()); ASSERT_EQ(light.GetInnerConeAngle(), 0.0); - ASSERT_NEAR(light.GetOuterConeAngle(), M_PI / 4.0f, 1e-8); + ASSERT_NEAR(light.GetOuterConeAngle(), DRACO_PI / 4.0f, 1e-8); // Check that lights are referenced by the scene nodes. ASSERT_EQ(scene->GetNode(SceneNodeIndex(0))->GetLightIndex(), diff --git a/src/draco/io/gltf_encoder_test.cc b/src/draco/io/gltf_encoder_test.cc index cbdb286..99cd64d 100644 --- a/src/draco/io/gltf_encoder_test.cc +++ b/src/draco/io/gltf_encoder_test.cc @@ -16,7 +16,9 @@ #ifdef DRACO_TRANSCODER_SUPPORTED #include +#include #include +#include #include "draco/core/draco_test_base.h" #include "draco/core/draco_test_utils.h" @@ -411,8 +413,9 @@ TEST_F(GltfEncoderTest, EncodeNamedGenericAttribute) { // Set metadata for first attribute so it gets written out by glTF encoder. std::unique_ptr am(new draco::AttributeMetadata()); constexpr char kAttributeName[] = "MyAttributeName"; - am->AddEntryString(GltfEncoder::kDracoMetadataGltfAttributeName, - kAttributeName); + constexpr char kDracoMetadataGltfAttributeName[] = + "//GLTF/ApplicationSpecificAttributeName"; + am->AddEntryString(kDracoMetadataGltfAttributeName, kAttributeName); mesh->AddAttributeMetadata(new_att_id_0, std::move(am)); // Make sure the GLTF contains a reference to the named attribute. diff --git a/src/draco/scene/light.cc b/src/draco/scene/light.cc index a7094cf..1fef98c 100644 --- a/src/draco/scene/light.cc +++ b/src/draco/scene/light.cc @@ -16,9 +16,10 @@ #ifdef DRACO_TRANSCODER_SUPPORTED -#include #include +#include "draco/core/constants.h" + namespace draco { Light::Light() @@ -27,7 +28,7 @@ Light::Light() type_(POINT), range_(std::numeric_limits::max()), // Infinity. inner_cone_angle_(0.0), - outer_cone_angle_(M_PI / 4.0) {} + outer_cone_angle_(DRACO_PI / 4.0) {} void Light::Copy(const Light &light) { name_ = light.name_; diff --git a/src/draco/scene/light_test.cc b/src/draco/scene/light_test.cc index 12d51f6..bc24a14 100644 --- a/src/draco/scene/light_test.cc +++ b/src/draco/scene/light_test.cc @@ -14,9 +14,9 @@ // #include "draco/scene/light.h" -#include #include +#include "draco/core/constants.h" #include "draco/core/draco_test_base.h" #include "draco/core/draco_test_utils.h" @@ -33,7 +33,7 @@ TEST(LightTest, TestDefaults) { ASSERT_EQ(light.GetType(), draco::Light::POINT); ASSERT_EQ(light.GetRange(), std::numeric_limits::max()); ASSERT_EQ(light.GetInnerConeAngle(), 0.0); - ASSERT_EQ(light.GetOuterConeAngle(), M_PI / 4.0); + ASSERT_EQ(light.GetOuterConeAngle(), DRACO_PI / 4.0); } TEST(LightTest, TestCopy) { @@ -44,8 +44,8 @@ TEST(LightTest, TestCopy) { light.SetIntensity(5.0); light.SetType(draco::Light::SPOT); light.SetRange(1000.0); - light.SetInnerConeAngle(M_PI / 8.0); - light.SetOuterConeAngle(M_PI / 2.0); + light.SetInnerConeAngle(DRACO_PI / 8.0); + light.SetOuterConeAngle(DRACO_PI / 2.0); // Create a copy of the initialized light and check all properties. draco::Light copy; @@ -55,8 +55,8 @@ TEST(LightTest, TestCopy) { ASSERT_EQ(copy.GetIntensity(), 5.0); ASSERT_EQ(copy.GetType(), draco::Light::SPOT); ASSERT_EQ(copy.GetRange(), 1000.0); - ASSERT_EQ(copy.GetInnerConeAngle(), M_PI / 8.0); - ASSERT_EQ(copy.GetOuterConeAngle(), M_PI / 2.0); + ASSERT_EQ(copy.GetInnerConeAngle(), DRACO_PI / 8.0); + ASSERT_EQ(copy.GetOuterConeAngle(), DRACO_PI / 2.0); } #endif // DRACO_TRANSCODER_SUPPORTED diff --git a/src/draco/tools/install_test/main.cc b/src/draco/tools/install_test/main.cc index cddcdc1..e76793b 100644 --- a/src/draco/tools/install_test/main.cc +++ b/src/draco/tools/install_test/main.cc @@ -18,13 +18,27 @@ // against an installed version of Draco without errors. It does not perform // any sort of library tests. +#include #include #include "draco/core/decoder_buffer.h" +#if defined DRACO_TRANSCODER_SUPPORTED +#include "draco/scene/scene.h" +#include "draco/scene/scene_utils.h" +#endif + int main(int /*argc*/, char** /*argv*/) { std::vector empty_buffer; draco::DecoderBuffer buffer; buffer.Init(empty_buffer.data(), empty_buffer.size()); + +#if defined DRACO_TRANSCODER_SUPPORTED + draco::Scene empty_scene; + const int num_meshes = empty_scene.NumMeshes(); + (void)num_meshes; +#endif + + printf("Partial sanity test passed.\n"); return 0; } diff --git a/src/draco/tools/install_test/test.py b/src/draco/tools/install_test/test.py index ad66a1d..6b911af 100755 --- a/src/draco/tools/install_test/test.py +++ b/src/draco/tools/install_test/test.py @@ -35,9 +35,16 @@ CMAKE = shutil.which('cmake') # List of generators available in the current CMake executable. CMAKE_AVAILABLE_GENERATORS = [] +# List of variable defs to be passed through to CMake via its -D argument. +CMAKE_DEFINES = [] + # CMake builds use the specified generator. CMAKE_GENERATOR = None +# Enable the transcoder before running tests (sets DRACO_TRANSCODER_SUPPORTED +# and builds transcoder support dependencies). +ENABLE_TRANSCODER = False + # The Draco tree that this script uses. DRACO_SOURCES_PATH = os.path.abspath(os.path.join('..', '..', '..', '..')) @@ -136,6 +143,9 @@ def run_process_and_capture_output(cmd, env=None): proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) + if VERBOSE: + print('COMMAND output:') + stdout = '' for line in iter(proc.stdout.readline, b''): decoded_line = line.decode('utf-8') @@ -183,6 +193,10 @@ def cmake_configure(source_path, cmake_args=None): for arg in cmake_args: command += f' {arg}' + if CMAKE_DEFINES: + for arg in CMAKE_DEFINES: + command += f' -D{arg}' + if VERBOSE: print(f'CONFIGURE command:\n{command}') @@ -191,9 +205,6 @@ def cmake_configure(source_path, cmake_args=None): if result[0] != 0: raise Exception(f'CONFIGURE failed!\nexit_code: {result[0]}\n{result[1]}') - if VERBOSE: - print(f'CONFIGURE result:\nexit_code: {result[0]}\n{result[1]}') - def cmake_build(cmake_args=None, build_args=None): """Runs a CMake build.""" @@ -225,30 +236,116 @@ def cmake_build(cmake_args=None, build_args=None): if result[0] != 0: raise Exception(f'BUILD failed!\nexit_code: {result[0]}\n{result[1]}') - if VERBOSE: - print(f'BUILD result:\nexit_code: {result[0]}\n{result[1]}') - def run_install_check(install_path): """Runs the install_check program.""" cmd = os.path.join(install_path, 'bin', 'install_check') - result = run_process_and_capture_output(cmd) + if VERBOSE: + print(f'RUN command: {cmd}') + result = run_process_and_capture_output(cmd) if result[0] != 0: raise Exception( f'install_check run failed!\nexit_code: {result[0]}\n{result[1]}') +def build_and_install_transcoder_dependencies(): + """Builds and installs Draco dependencies for transcoder enabled builds.""" + orig_dir = os.getcwd() + + # The Eigen CMake build in the release Draco has pinned is, to put it mildly, + # user unfriendly. Instead of wasting time trying to integrate it here, just + # shutil.copytree() everything in $eigen_submodule_path to + # $CMAKE_INSTALL_PREFIX/include/Eigen. + # Eigen claims to be header-only, so this should be adequate for Draco's + # needs here. + eigen_submodule_path = os.path.join( + DRACO_SOURCES_PATH, 'third_party', 'eigen', 'Eigen') + + # "Install" Eigen for the shared install root. + eigen_install_path = os.path.join( + DRACO_SHARED_INSTALL_PATH, 'include', 'Eigen') + shutil.copytree(src=eigen_submodule_path, dst=eigen_install_path) + + # "Install" Eigen for the static install root. + eigen_install_path = os.path.join( + DRACO_STATIC_INSTALL_PATH, 'include', 'Eigen') + shutil.copytree(src=eigen_submodule_path, dst=eigen_install_path) + + # Build and install gulrak/filesystem for shared and static configurations. + # Note that this is basically running gulrak/filesystem's CMake build as an + # install script. + fs_submodule_path = os.path.join( + DRACO_SOURCES_PATH, 'third_party', 'filesystem') + + # Install gulrak/filesystem in the shared draco install root. + fs_shared_build = os.path.join(DRACO_SHARED_BUILD_PATH, '_fs') + pathlib.Path(fs_shared_build).mkdir(parents=True, exist_ok=True) + os.chdir(fs_shared_build) + cmake_args = [] + cmake_args.append(f'-DCMAKE_INSTALL_PREFIX={DRACO_SHARED_INSTALL_PATH}') + cmake_args.append('-DBUILD_SHARED_LIBS=ON') + cmake_args.append('-DGHC_FILESYSTEM_BUILD_TESTING=OFF') + cmake_args.append('-DGHC_FILESYSTEM_BUILD_EXAMPLES=OFF') + cmake_configure(source_path=fs_submodule_path, cmake_args=cmake_args) + cmake_build(cmake_args=['--target install']) + + # Install gulrak/filesystem in the shared draco install root. + fs_static_build = os.path.join(DRACO_STATIC_BUILD_PATH, '_fs') + pathlib.Path(fs_static_build).mkdir(parents=True, exist_ok=True) + os.chdir(fs_static_build) + cmake_args = [] + cmake_args.append(f'-DCMAKE_INSTALL_PREFIX={DRACO_SHARED_INSTALL_PATH}') + cmake_args.append('-DBUILD_SHARED_LIBS=OFF') + cmake_args.append('-DGHC_FILESYSTEM_BUILD_TESTING=OFF') + cmake_args.append('-DGHC_FILESYSTEM_BUILD_EXAMPLES=OFF') + cmake_configure(source_path=fs_submodule_path, cmake_args=cmake_args) + cmake_build(cmake_args=['--target install']) + + # Build and install TinyGLTF for shared and static configurations. + # Note, as above, that this is basically running TinyGLTF's CMake build as an + # install script. + tinygltf_submodule_path = os.path.join( + DRACO_SOURCES_PATH, 'third_party', 'tinygltf') + + # Install TinyGLTF in the shared draco install root. + tinygltf_shared_build = os.path.join(DRACO_SHARED_BUILD_PATH, '_TinyGLTF') + pathlib.Path(tinygltf_shared_build).mkdir(parents=True, exist_ok=True) + os.chdir(tinygltf_shared_build) + cmake_args = [] + cmake_args.append(f'-DCMAKE_INSTALL_PREFIX={DRACO_SHARED_INSTALL_PATH}') + cmake_args.append('-DTINYGLTF_BUILD_EXAMPLES=OFF') + cmake_configure(source_path=tinygltf_submodule_path, cmake_args=cmake_args) + cmake_build(cmake_args=['--target install']) + + # Install TinyGLTF in the static draco install root. + tinygltf_static_build = os.path.join(DRACO_STATIC_BUILD_PATH, '_TinyGLTF') + pathlib.Path(tinygltf_static_build).mkdir(parents=True, exist_ok=True) + os.chdir(tinygltf_static_build) + cmake_args = [] + cmake_args.append(f'-DCMAKE_INSTALL_PREFIX={DRACO_STATIC_INSTALL_PATH}') + cmake_args.append('-DTINYGLTF_BUILD_EXAMPLES=OFF') + cmake_configure(source_path=tinygltf_submodule_path, cmake_args=cmake_args) + cmake_build(cmake_args=['--target install']) + + os.chdir(orig_dir) + + def build_and_install_draco(): """Builds Draco in shared and static configurations.""" orig_dir = os.getcwd() + if ENABLE_TRANSCODER: + build_and_install_transcoder_dependencies() + # Build and install Draco in shared library config for the current host # machine. os.chdir(DRACO_SHARED_BUILD_PATH) cmake_args = [] cmake_args.append(f'-DCMAKE_INSTALL_PREFIX={DRACO_SHARED_INSTALL_PATH}') cmake_args.append('-DBUILD_SHARED_LIBS=ON') + if ENABLE_TRANSCODER: + cmake_args.append('-DDRACO_TRANSCODER_SUPPORTED=ON') cmake_configure(source_path=DRACO_SOURCES_PATH, cmake_args=cmake_args) cmake_build(cmake_args=['--target install']) @@ -257,6 +354,8 @@ def build_and_install_draco(): cmake_args = [] cmake_args.append(f'-DCMAKE_INSTALL_PREFIX={DRACO_STATIC_INSTALL_PATH}') cmake_args.append('-DBUILD_SHARED_LIBS=OFF') + if ENABLE_TRANSCODER: + cmake_args.append('-DDRACO_TRANSCODER_SUPPORTED=ON') cmake_configure(source_path=DRACO_SOURCES_PATH, cmake_args=cmake_args) cmake_build(cmake_args=['--target install']) @@ -301,6 +400,14 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument( '-G', '--generator', help='CMake builds use the specified generator.') + parser.add_argument( + '-D', '--cmake_define', + action='append', + help='Passes argument through to CMake as a CMake variable via cmake -D.') + parser.add_argument( + '-t', '--with_transcoder', + action='store_true', + help='Run tests with Draco transcoder support enabled.') parser.add_argument( '-v', '--verbose', @@ -308,15 +415,21 @@ if __name__ == '__main__': help='Show configuration and build output.') args = parser.parse_args() + if args.cmake_define: + CMAKE_DEFINES = args.cmake_define if args.generator: CMAKE_GENERATOR = args.generator if args.verbose: VERBOSE = True + if args.with_transcoder: + ENABLE_TRANSCODER = True if VERBOSE: print(f'CMAKE={CMAKE}') + print(f'CMAKE_DEFINES={CMAKE_DEFINES}') print(f'CMAKE_GENERATOR={CMAKE_GENERATOR}') print(f'CMAKE_AVAILABLE_GENERATORS={CMAKE_AVAILABLE_GENERATORS}') + print(f'ENABLE_TRANSCODER={ENABLE_TRANSCODER}') print(f'DRACO_SOURCES_PATH={DRACO_SOURCES_PATH}') print(f'DRACO_SHARED_BUILD_PATH={DRACO_SHARED_BUILD_PATH}') print(f'DRACO_STATIC_BUILD_PATH={DRACO_STATIC_BUILD_PATH}')