Add CMake STATIC library target avif_internal
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 205fc61..51b9bcf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@
## [Unreleased]
+### Added
+* Add STATIC library target avif_internal to allow tests to access functions
+ from internal.h when BUILD_SHARED_LIBS is ON.
+
## [0.11.1] - 2022-10-19
### Changed
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0e0cb1f..7648d3b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -456,6 +456,21 @@
endif()
endif()
+# Give access to functions defined in internal.h when BUILD_SHARED_LIBS is ON, to tests for example.
+# The avif_internal target should not be used by external code.
+if(BUILD_SHARED_LIBS)
+ add_library(avif_internal STATIC ${AVIF_SRCS})
+ # Copy most properties from the public avif library target.
+ target_compile_definitions(avif_internal PRIVATE "$<TARGET_PROPERTY:avif,COMPILE_DEFINITIONS>")
+ target_link_libraries(avif_internal PRIVATE "$<TARGET_PROPERTY:avif,LINK_LIBRARIES>")
+ target_include_directories(
+ avif_internal PUBLIC "$<TARGET_PROPERTY:avif,INTERFACE_INCLUDE_DIRECTORIES>"
+ PRIVATE "$<TARGET_PROPERTY:avif,INCLUDE_DIRECTORIES>"
+ )
+else()
+ add_library(avif_internal ALIAS avif)
+endif()
+
option(AVIF_BUILD_EXAMPLES "Build avif examples." OFF)
if(AVIF_BUILD_EXAMPLES)
set(AVIF_EXAMPLES avif_example_decode_memory avif_example_decode_file avif_example_decode_streaming avif_example_encode)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9625d73..e7c3635 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -103,14 +103,10 @@
target_include_directories(avifrgbtoyuvtest PRIVATE ${GTEST_INCLUDE_DIRS})
add_test(NAME avifrgbtoyuvtest COMMAND avifrgbtoyuvtest)
- if(NOT BUILD_SHARED_LIBS)
- # Test the internal function avifSetTileConfiguration(), which is not exported from the
- # shared library.
- add_executable(aviftilingtest gtest/aviftilingtest.cc)
- target_link_libraries(aviftilingtest avif ${GTEST_BOTH_LIBRARIES})
- target_include_directories(aviftilingtest PRIVATE ${GTEST_INCLUDE_DIRS})
- add_test(NAME aviftilingtest COMMAND aviftilingtest)
- endif()
+ add_executable(aviftilingtest gtest/aviftilingtest.cc)
+ target_link_libraries(aviftilingtest avif_internal ${GTEST_BOTH_LIBRARIES})
+ target_include_directories(aviftilingtest PRIVATE ${GTEST_INCLUDE_DIRS})
+ add_test(NAME aviftilingtest COMMAND aviftilingtest)
add_executable(avify4mtest gtest/avify4mtest.cc)
target_link_libraries(avify4mtest aviftest_helpers ${GTEST_BOTH_LIBRARIES})