Skip to content

Commit

Permalink
build: Use target_compile_options (fixes a LibRaw build issue) (Acade…
Browse files Browse the repository at this point in the history
…mySoftwareFoundation#4556)

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.

Issue found while updating Little-CMS in
microsoft/vcpkg#42187 and the change fixes the
build issue found there. This is an attempt to upstream it so the issue
is fixed.

Signed-off-by: Don Olmstead <don.j.olmstead@gmail.com>
  • Loading branch information
donny-dont authored and lgritz committed Dec 9, 2024
1 parent 4b56b81 commit d59b5dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/cmake/add_oiio_plugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# [ SRC source1 ... ]
# [ INCLUDE_DIRS include_dir1 ... ]
# [ LINK_LIBRARIES external_lib1 ... ]
# [ DEFINITIONS -DFOO=bar ... ])
# [ COMPILE_OPTIONS -Wflag ... ]
# [ DEFINITIONS FOO=bar ... ])
#
# The plugin name can be specified with NAME, otherwise is inferred from the
# subdirectory name. The source files of the binary can be specified with
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,7 +72,8 @@ macro (add_oiio_plugin)
target_compile_definitions (${_plugin_NAME} PRIVATE
${_plugin_DEFINITIONS}
OpenImageIO_EXPORTS)
target_include_directories (${_plugin_NAME} PRIVATE ${_plugin_INCLUDE_DIRS})
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})
set_target_properties (${_plugin_NAME} PROPERTIES PREFIX "" FOLDER "Plugins")
Expand Down
4 changes: 3 additions & 1 deletion src/libOpenImageIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ if (EMBEDPLUGINS)
PRIVATE
EMBED_PLUGINS=1
${format_plugin_definitions})
target_include_directories (OpenImageIO
target_compile_options (OpenImageIO
PRIVATE ${format_plugin_compile_options})
target_include_directories (OpenImageIO BEFORE
PRIVATE ${format_plugin_include_dirs})

# Organize the embedded plugins into source folders
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 "-DUSE_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 d59b5dc

Please sign in to comment.