Skip to content

Commit

Permalink
build: Use target_compile_options
Browse files Browse the repository at this point in the history
When using pkgconfig the value of `<NAME>_CFLAGS_OTHER` can contain compiler flags along with preprocessor definitions. If there is a compiler flag and its passed to `target_compile_definitions` then it will be treated as if it is a preprocessor definition.

Found a case where a statically compiled LibRaw with a statically compiled Little-CMS caused `LibRaw_DEFINITIONS` to have `-pthread` in its listing which was passed to the compiler as a definition, `-D-pthread`. This caused a build failure with `auto-moc`.

Add an additional parameter for the `add_oiio_plugin` macro to take `COMPILE_OPTIONS` and pass those to `target_compile_options` which can differentiate between compiler flags and preprocessor definitions. Pass `LibRaw_DEFINITIONS` to the CMake macro to prevent the above error.
  • Loading branch information
donny-dont committed Dec 3, 2024
1 parent 019cc0d commit 4369b8c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/cmake/add_oiio_plugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# [ SRC source1 ... ]
# [ INCLUDE_DIRS include_dir1 ... ]
# [ LINK_LIBRARIES external_lib1 ... ]
# [ COMPILE_OPTIONS -Wflag ... ]
# [ DEFINITIONS FOO=bar ... ])
#
# The plugin name can be specified with NAME, otherwise is inferred from the
Expand All @@ -34,7 +35,7 @@
# be handed off too the setup of the later OpenImageIO target.
#
macro (add_oiio_plugin)
cmake_parse_arguments (_plugin "" "NAME" "SRC;INCLUDE_DIRS;LINK_LIBRARIES;DEFINITIONS" ${ARGN})
cmake_parse_arguments (_plugin "" "NAME" "SRC;INCLUDE_DIRS;LINK_LIBRARIES;COMPILE_OPTIONS;DEFINITIONS" ${ARGN})
# Arguments: <prefix> <options> <one_value_keywords> <multi_value_keywords> args...
get_filename_component (_plugin_name ${CMAKE_CURRENT_SOURCE_DIR} NAME_WE)
if (NOT _plugin_NAME)
Expand All @@ -61,6 +62,7 @@ macro (add_oiio_plugin)
endforeach ()
set (libOpenImageIO_srcs "${_plugin_all_source}" PARENT_SCOPE)
set (format_plugin_definitions ${format_plugin_definitions} ${_plugin_DEFINITIONS} PARENT_SCOPE)
set (format_plugin_compile_options ${format_plugin_compile_options} ${_plugin_COMPILE_OPTIONS} PARENT_SCOPE)
set (format_plugin_include_dirs ${format_plugin_include_dirs} ${_plugin_INCLUDE_DIRS} PARENT_SCOPE)
set (format_plugin_libs ${format_plugin_libs} ${_plugin_LINK_LIBRARIES} PARENT_SCOPE)
else ()
Expand All @@ -70,6 +72,7 @@ macro (add_oiio_plugin)
target_compile_definitions (${_plugin_NAME} PRIVATE
${_plugin_DEFINITIONS}
OpenImageIO_EXPORTS)
target_compile_options (${_plugin_NAME} PRIVATE ${_plugin_COMPILE_OPTIONS})
target_include_directories (${_plugin_NAME} BEFORE PRIVATE ${_plugin_INCLUDE_DIRS})
target_link_libraries (${_plugin_NAME} PUBLIC OpenImageIO
PRIVATE ${_plugin_LINK_LIBRARIES})
Expand Down
2 changes: 2 additions & 0 deletions src/libOpenImageIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ if (EMBEDPLUGINS)
PRIVATE
EMBED_PLUGINS=1
${format_plugin_definitions})
target_compile_options (OpenImageIO
PRIVATE ${format_plugin_compile_options})
target_include_directories (OpenImageIO BEFORE
PRIVATE ${format_plugin_include_dirs})

Expand Down
3 changes: 2 additions & 1 deletion src/raw.imageio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ if (LIBRAW_FOUND)
add_oiio_plugin (rawinput.cpp
INCLUDE_DIRS ${LibRaw_INCLUDE_DIR}
LINK_LIBRARIES ${LibRaw_r_LIBRARIES}
DEFINITIONS "USE_LIBRAW=1" ${LibRaw_r_DEFINITIONS})
COMPILE_OPTIONS ${LibRaw_r_DEFINITIONS}
DEFINITIONS "USE_LIBRAW=1")
else ()
message (WARNING "Raw plugin will not be built")
endif ()

0 comments on commit 4369b8c

Please sign in to comment.