From 9e1290855634b5360f56012a9824c7aca2b8271d Mon Sep 17 00:00:00 2001 From: Sundaram Ramaswamy Date: Thu, 25 Mar 2021 17:47:43 +0530 Subject: [PATCH 1/3] Add CMake interface library target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Projects using cglm as a header-only library needn’t build files under src/. Provide a target which allows them to skip compiling them by add_subdirectory(external/cglm EXCLUDE_FROM_ALL) target_link_libraries(MyExe PRIVATE cglm_headers) --- CMakeLists.txt | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cd48ea..db582a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,81 @@ target_include_directories(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src ) +# Target for header-only usage +add_library(${PROJECT_NAME}_headers INTERFACE + include/cglm/affine-mat.h + include/cglm/affine.h + include/cglm/affine2d.h + include/cglm/applesimd.h + include/cglm/bezier.h + include/cglm/box.h + include/cglm/call.h + include/cglm/cam.h + include/cglm/cglm.h + include/cglm/color.h + include/cglm/common.h + include/cglm/curve.h + include/cglm/ease.h + include/cglm/euler.h + include/cglm/frustum.h + include/cglm/io.h + include/cglm/mat2.h + include/cglm/mat3.h + include/cglm/mat4.h + include/cglm/plane.h + include/cglm/project.h + include/cglm/quat.h + include/cglm/ray.h + include/cglm/sphere.h + include/cglm/struct.h + include/cglm/types-struct.h + include/cglm/types.h + include/cglm/util.h + include/cglm/vec2-ext.h + include/cglm/vec2.h + include/cglm/vec3-ext.h + include/cglm/vec3.h + include/cglm/vec4-ext.h + include/cglm/vec4.h + include/cglm/version.h + include/cglm/simd/arm.h + include/cglm/simd/avx/affine.h + include/cglm/simd/avx/mat4.h + include/cglm/simd/intrin.h + include/cglm/simd/neon/mat4.h + include/cglm/simd/sse2/affine.h + include/cglm/simd/sse2/mat2.h + include/cglm/simd/sse2/mat3.h + include/cglm/simd/sse2/mat4.h + include/cglm/simd/sse2/quat.h + include/cglm/simd/x86.h + include/cglm/struct/affine.h + include/cglm/struct/affine2d.h + include/cglm/struct/box.h + include/cglm/struct/cam.h + include/cglm/struct/color.h + include/cglm/struct/curve.h + include/cglm/struct/euler.h + include/cglm/struct/frustum.h + include/cglm/struct/io.h + include/cglm/struct/mat2.h + include/cglm/struct/mat3.h + include/cglm/struct/mat4.h + include/cglm/struct/plane.h + include/cglm/struct/project.h + include/cglm/struct/quat.h + include/cglm/struct/sphere.h + include/cglm/struct/vec2-ext.h + include/cglm/struct/vec2.h + include/cglm/struct/vec3-ext.h + include/cglm/struct/vec3.h + include/cglm/struct/vec4-ext.h + include/cglm/struct/vec4.h + ) + +target_include_directories(${PROJECT_NAME}_headers INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/include) + # Test Configuration if(CGLM_USE_TEST) include(CTest) From 616d38c13a2d79ea3f244251724a6c9e86218d51 Mon Sep 17 00:00:00 2001 From: Sundaram Ramaswamy Date: Fri, 26 Mar 2021 12:23:56 +0530 Subject: [PATCH 2/3] Remove redundant header listing --- CMakeLists.txt | 72 +------------------------------------------------- 1 file changed, 1 insertion(+), 71 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db582a1..6e825d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,77 +94,7 @@ target_include_directories(${PROJECT_NAME} ) # Target for header-only usage -add_library(${PROJECT_NAME}_headers INTERFACE - include/cglm/affine-mat.h - include/cglm/affine.h - include/cglm/affine2d.h - include/cglm/applesimd.h - include/cglm/bezier.h - include/cglm/box.h - include/cglm/call.h - include/cglm/cam.h - include/cglm/cglm.h - include/cglm/color.h - include/cglm/common.h - include/cglm/curve.h - include/cglm/ease.h - include/cglm/euler.h - include/cglm/frustum.h - include/cglm/io.h - include/cglm/mat2.h - include/cglm/mat3.h - include/cglm/mat4.h - include/cglm/plane.h - include/cglm/project.h - include/cglm/quat.h - include/cglm/ray.h - include/cglm/sphere.h - include/cglm/struct.h - include/cglm/types-struct.h - include/cglm/types.h - include/cglm/util.h - include/cglm/vec2-ext.h - include/cglm/vec2.h - include/cglm/vec3-ext.h - include/cglm/vec3.h - include/cglm/vec4-ext.h - include/cglm/vec4.h - include/cglm/version.h - include/cglm/simd/arm.h - include/cglm/simd/avx/affine.h - include/cglm/simd/avx/mat4.h - include/cglm/simd/intrin.h - include/cglm/simd/neon/mat4.h - include/cglm/simd/sse2/affine.h - include/cglm/simd/sse2/mat2.h - include/cglm/simd/sse2/mat3.h - include/cglm/simd/sse2/mat4.h - include/cglm/simd/sse2/quat.h - include/cglm/simd/x86.h - include/cglm/struct/affine.h - include/cglm/struct/affine2d.h - include/cglm/struct/box.h - include/cglm/struct/cam.h - include/cglm/struct/color.h - include/cglm/struct/curve.h - include/cglm/struct/euler.h - include/cglm/struct/frustum.h - include/cglm/struct/io.h - include/cglm/struct/mat2.h - include/cglm/struct/mat3.h - include/cglm/struct/mat4.h - include/cglm/struct/plane.h - include/cglm/struct/project.h - include/cglm/struct/quat.h - include/cglm/struct/sphere.h - include/cglm/struct/vec2-ext.h - include/cglm/struct/vec2.h - include/cglm/struct/vec3-ext.h - include/cglm/struct/vec3.h - include/cglm/struct/vec4-ext.h - include/cglm/struct/vec4.h - ) - +add_library(${PROJECT_NAME}_headers INTERFACE) target_include_directories(${PROJECT_NAME}_headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) From d6a0ac320b527cf299011a589edb65141a093dad Mon Sep 17 00:00:00 2001 From: Sundaram Ramaswamy Date: Fri, 26 Mar 2021 12:32:36 +0530 Subject: [PATCH 3/3] Update docs on CMake header-only usage --- README.md | 18 ++++++++++++++++++ docs/source/build.rst | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 595812e..c272051 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,24 @@ option(CGLM_USE_C99 "" OFF) # C11 option(CGLM_USE_TEST "Enable Tests" OFF) # for make check - make test ``` +#### Use as header-only library with your CMake project + +This requires no building or installation of cglm. + +* Example: + +``` cmake +cmake_minimum_required(VERSION 3.8.2) + +project() + +add_executable(${PROJECT_NAME} src/main.c) +target_link_libraries(${LIBRARY_NAME} PRIVATE + cglm_headers) + +add_subdirectory(external/cglm/ EXCLUDE_FROM_ALL) +``` + #### Use with your CMake project * Example: ```cmake diff --git a/docs/source/build.rst b/docs/source/build.rst index 84da24d..e2eb23d 100644 --- a/docs/source/build.rst +++ b/docs/source/build.rst @@ -32,6 +32,22 @@ If you don't want to install **cglm** to your system's folder you can get static option(CGLM_USE_C99 "" OFF) # C11 option(CGLM_USE_TEST "Enable Tests" OFF) # for make check - make test +**Use as header-only library with your CMake project example** +This requires no building or installation of cglm. + +.. code-block:: CMake + :linenos: + + cmake_minimum_required(VERSION 3.8.2) + + project() + + add_executable(${PROJECT_NAME} src/main.c) + target_link_libraries(${LIBRARY_NAME} PRIVATE + cglm_headers) + + add_subdirectory(external/cglm/ EXCLUDE_FROM_ALL) + **Use with your CMake project example** .. code-block:: CMake