Skip to content

Commit

Permalink
update docs and try to supports MT/MD
Browse files Browse the repository at this point in the history
  • Loading branch information
alexchicn committed Oct 16, 2020
1 parent 5d777b5 commit dc57f7e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 82 deletions.
51 changes: 7 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.11)
cmake_minimum_required(VERSION 3.15)

project(libgltf)

Expand All @@ -14,48 +14,14 @@ set(LIBGLTF_PLATFORM_WINDOWS FALSE)
set(LIBGLTF_PLATFORM_LINUX FALSE)
set(LIBGLTF_PLATFORM_MACOS FALSE)
set(LIBGLTF_PLATFORM_ANDROID FALSE)
set(LIBGLTF_PLATFORM_IOS FALSE CACHE BOOL "Build for iOS?")
set(LIBGLTF_PLATFORM_IOS FALSE CACHE BOOL "Build for iOS? Just for macOS")

if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND MSVC)
set(LIBGLTF_BUILD_MSVC_WITH_MT OFF CACHE BOOL "Build MSVC with 'MultiThreading?")
set(LIBGLTF_BUILD_MSVC_WITH_MT OFF CACHE BOOL "Build MSVC with 'MultiThreading(MT)' or 'MultiThreadingDLL(MD)'?")
if(${LIBGLTF_BUILD_MSVC_WITH_MT})
foreach(flags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${flags} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flags} "${${flags}}")
endif()
if(${flags} MATCHES "/MDd")
string(REGEX REPLACE "/MDd" "/MTd" ${flags} "${${flags}}")
endif()
endforeach()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
foreach(flags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${flags} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${flags} "${${flags}}")
endif()
if(${flags} MATCHES "/MTd")
string(REGEX REPLACE "/MTd" "/MDd" ${flags} "${${flags}}")
endif()
endforeach()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
set(LIBGLTF_PLATFORM_WINDOWS TRUE)
add_definitions(-DLIBGLTF_PLATFORM_WINDOWS)
Expand All @@ -78,11 +44,12 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wno-long-long -pedantic")
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(LIBGLTF_COVERAGE_GCOV OFF CACHE BOOL "Coverage gcov (debug, Linux builds only)")
if(LIBGLTF_COVERAGE_GCOV)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fPIC")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -lgcov")
add_definitions(-DBUILD_COVERALLS)
add_definitions(-DLIBGLTF_BUILD_COVERAGE_GCOV)
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(LIBGLTF_PLATFORM_ANDROID TRUE)
Expand Down Expand Up @@ -188,10 +155,6 @@ if(LIBGLTF_USE_GOOGLE_DRACO)
endif()
endif()

if(LIBGLTF_PLATFORM_LINUX)
set(LIBGLTF_COVERAGE_GCOV OFF CACHE BOOL "Coverage gcov (debug, Linux builds only)")
endif()

if((CMAKE_COMPILER_IS_GNUCC STREQUAL "1") OR (CMAKE_COMPILER_IS_GNUCXX STREQUAL "1"))
add_definitions(-DCOMPILER_IS_GCC)
endif()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(DOC_ROOT_FILE_LIST
${ROOT_PATH}/CONTRIBUTING.md
${ROOT_PATH}/CODE_OF_CONDUCT.md
${ROOT_PATH}/CHANGELOG.md
${ROOT_PATH}/LICENSE.md
${ROOT_PATH}/LICENSE
)

set(DOC_HELP_FILE_LIST
Expand Down
71 changes: 34 additions & 37 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,20 @@ Features
Getting Started
===============

1. Update the submodule
#. Update the submodule

..
Run :code:`git submodule update --init`

Run :code:`git submodule update --init`
#. Generate the project by [CMake]

2. Generate the project by [CMake]
Run :code:`cmake -G "[GENERATOR BY YOUR SYSTEM]" [LIBGLTF FOLDER]`

..
#. Build the project and generate the the static library `libgltf.lib` or `libgltf.a`
#. Include `libgltf/libgltf.h` in your project.
#. Link the static library `libgltf.lib` or `libgltf.a` in your project.

Run :code:`cmake -G "[GENERATOR BY YOUR SYSTEM]" [LIBGLTF FOLDER]`

3. Build the project and generate the the static library `libgltf.lib` or `libgltf.a`
4. Include `libgltf/libgltf.h` in your project.
5. Link the static library `libgltf.lib` or `libgltf.a` in your project.

..
You have to link the static library `draco.lib` or `draco.a` with your project, if you want support the `Google's Draco`_.
And you can find the draco in the external folder.
You have to link the static library `draco.lib` or `draco.a` with your project, if you want support the `Google's Draco`_.
And you can find the draco in the external folder.

Code example:

Expand All @@ -82,11 +76,10 @@ Code example:
printf("failed to load your gltf file");
}
Usage
==========

Generate the `makefile` or `ninja` or `visual c++ project` or `xcode project` by [CMake].
Generate the *makefile* or *ninja* or *visual c++ project* or *xcode project* by CMake_.

For now, just build to a static library - `libgltf.(lib/a)`.

Expand All @@ -96,7 +89,7 @@ How to use
Load the glTF file
------------------

You can load the glTF file by the function - `libgltf::IglTFLoader::Create`, like this:
You can load the glTF file by the function - :code:`libgltf::IglTFLoader::Create`, like this:

.. code-block:: cpp
Expand Down Expand Up @@ -142,57 +135,59 @@ Advance
Regenerate new code by the glTF schema
--------------------------------------

..
Generate the c++11 code:

You can update the c++11 source code by `jsonschematoc11`.
* You can update the c++11 source code by :code:`jsonschematoc11`.
* You need update the submodule :code:`external/glTF`
* It runs in **Python2**

Generate the c++11 code:
#. Run :code:`update_parser_by_scheme.bat`

* For Windows: :code:`cd tools\batch\ && update_parser_by_scheme.bat && cd ..\..\ `
* For Linux/MacOS :code:`cd tools/batch/ && ./update_parser_by_scheme.sh && cd ../../`

1. Run `tools/batch/update_parser_by_scheme.bat` (Windows) or `tools/batch/update_parser_by_scheme.sh` (Unix/Linux/MacOS)
2. Build your version by CMake_, Ninja_ or VisualStudio_.
#. Build your version by CMake_.

Character encoding
------------------

* default using UTF8, char and std::string
* set LIBGLTF_CHARACTOR_ENCODING in cmake command - UTF8, UTF16, UTF32 or UNICODE
* You can set :code:`LIBGLTF_CHARACTOR_ENCODING` in CMake_ to set the encoding.
* Supports :code:`UTF8`, :code:`UTF16`, :code:`UTF32` or :code:`UNICODE`.
* The default encoding is :code:`UTF8`.

Supports Google's draco
-----------------------

You can update the Google's draco submodule in external/draco or pull the draco repo by yourself.

Check the `LIBGLTF_USE_GOOGLE_DRACO` or set `LIBGLTF_USE_GOOGLE_DRACO` is `TRUE`.
Check the :code:`LIBGLTF_USE_GOOGLE_DRACO` or set :code:`LIBGLTF_USE_GOOGLE_DRACO` is `TRUE`.

* Set the `GOOGLE_DRACO_PATH_INCLUDE`, `GOOGLE_DRACO_PATH_BUILD`, `GOOGLE_DRACO_LIBRARY_DRACODEC_DEBUG`, `GOOGLE_DRACO_LIBRARY_DRACODEC_RELEASE`, `GOOGLE_DRACO_LIBRARY_DRACOENC_DEBUG` and `GOOGLE_DRACO_LIBRARY_DRACOENC_RELEASE`.
* Or enable the `LIBGLTF_USE_GOOGLE_DRACO_SUBMODULE` to compile with the submodule - `external/draco`.
* Set the :code:`GOOGLE_DRACO_PATH_INCLUDE`, :code:`GOOGLE_DRACO_PATH_BUILD`, :code:`GOOGLE_DRACO_LIBRARY_DRACODEC_DEBUG`, :code:`GOOGLE_DRACO_LIBRARY_DRACODEC_RELEASE`, :code:`GOOGLE_DRACO_LIBRARY_DRACOENC_DEBUG` and :code:`GOOGLE_DRACO_LIBRARY_DRACOENC_RELEASE`.
* Or enable the :code:`LIBGLTF_USE_GOOGLE_DRACO_SUBMODULE` to compile with the submodule - *external/draco*.

Download the compiled library
-----------------------------
Download libraries
------------------

This project is compiled by github action, and you can download the compiled library with `Google's Draco`_ from `the action page`_ or `the release page`_.

Note:
In `the action page`_ or `the release page`_, libraries was compiled with `MultiThreading` (/MT or /MTd) for **windows**.

Donation
==============================================================

..
*Please consider donating to sustain my activities*
**Please consider donating to sustain my activities**

|support-buy-a-cup-of-coffee| |donation-beome-a-patreon|

License
==========

The MIT license.

.. _glTFForUE4: https://github.com/code4game/glTFForUE4
`The MIT license`_.

.. _`glTF 2.0`: https://www.khronos.org/gltf/

.. _glTFForUE4: https://github.com/code4game/glTFForUE4

.. _`Google's Draco`: https://github.com/google/draco

.. _CMake: https://cmake.org/
Expand All @@ -205,6 +200,8 @@ The MIT license.

.. _`the release page`: https://github.com/code4game/libgltf/releases

.. _`The MIT license`: https://github.com/code4game/libgltf/LICENSE

.. |glTF 2.0| image:: https://img.shields.io/badge/glTF-2%2E0-green.svg?style=flat
:target: https://github.com/KhronosGroup/glTF

Expand Down
10 changes: 10 additions & 0 deletions source/runtest/runtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ int main(int _iArgc, char* _pcArgv[])
std::shared_ptr<libgltf::TAccessorStream<libgltf::TDimensionVector<2, float> > > texcoord_0_stream = std::make_shared<libgltf::TAccessorStream<libgltf::TDimensionVector<2, float> > >(texcoord_0_data);
gltf_loader->GetOrLoadMeshPrimitiveAttributeData(0, 0, GLTFTEXT("texcoord_0"), texcoord_0_stream);

#if defined(LIBGLTF_BUILD_COVERAGE_GCOV)
const std::string obj_file_path =
#if defined(LIBGLTF_CHARACTOR_ENCODING_IS_UNICODE) && defined(LIBGLTF_PLATFORM_WINDOWS)
libgltf::UNICODEToUTF8(input_file_path + GLTFTEXT(".obj"));
#else
input_file_path + GLTFTEXT(".obj");
#endif
SaveAsOBJ(obj_file_path, triangle_data, position_data, texcoord_0_data, normal_data);
#endif

//TODO: just convert to json, save the mesh or image data to file in future
libgltf::string_t output_content;
if (loaded_gltf >> output_content)
Expand Down

0 comments on commit dc57f7e

Please sign in to comment.