Skip to content

Commit d59b5dc

Browse files
donny-dontlgritz
authored andcommitted
build: Use target_compile_options (fixes a LibRaw build issue) (AcademySoftwareFoundation#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 <[email protected]>
1 parent 4b56b81 commit d59b5dc

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/cmake/add_oiio_plugin.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# [ SRC source1 ... ]
1313
# [ INCLUDE_DIRS include_dir1 ... ]
1414
# [ LINK_LIBRARIES external_lib1 ... ]
15-
# [ DEFINITIONS -DFOO=bar ... ])
15+
# [ COMPILE_OPTIONS -Wflag ... ]
16+
# [ DEFINITIONS FOO=bar ... ])
1617
#
1718
# The plugin name can be specified with NAME, otherwise is inferred from the
1819
# subdirectory name. The source files of the binary can be specified with
@@ -34,7 +35,7 @@
3435
# be handed off too the setup of the later OpenImageIO target.
3536
#
3637
macro (add_oiio_plugin)
37-
cmake_parse_arguments (_plugin "" "NAME" "SRC;INCLUDE_DIRS;LINK_LIBRARIES;DEFINITIONS" ${ARGN})
38+
cmake_parse_arguments (_plugin "" "NAME" "SRC;INCLUDE_DIRS;LINK_LIBRARIES;COMPILE_OPTIONS;DEFINITIONS" ${ARGN})
3839
# Arguments: <prefix> <options> <one_value_keywords> <multi_value_keywords> args...
3940
get_filename_component (_plugin_name ${CMAKE_CURRENT_SOURCE_DIR} NAME_WE)
4041
if (NOT _plugin_NAME)
@@ -61,6 +62,7 @@ macro (add_oiio_plugin)
6162
endforeach ()
6263
set (libOpenImageIO_srcs "${_plugin_all_source}" PARENT_SCOPE)
6364
set (format_plugin_definitions ${format_plugin_definitions} ${_plugin_DEFINITIONS} PARENT_SCOPE)
65+
set (format_plugin_compile_options ${format_plugin_compile_options} ${_plugin_COMPILE_OPTIONS} PARENT_SCOPE)
6466
set (format_plugin_include_dirs ${format_plugin_include_dirs} ${_plugin_INCLUDE_DIRS} PARENT_SCOPE)
6567
set (format_plugin_libs ${format_plugin_libs} ${_plugin_LINK_LIBRARIES} PARENT_SCOPE)
6668
else ()
@@ -70,7 +72,8 @@ macro (add_oiio_plugin)
7072
target_compile_definitions (${_plugin_NAME} PRIVATE
7173
${_plugin_DEFINITIONS}
7274
OpenImageIO_EXPORTS)
73-
target_include_directories (${_plugin_NAME} PRIVATE ${_plugin_INCLUDE_DIRS})
75+
target_compile_options (${_plugin_NAME} PRIVATE ${_plugin_COMPILE_OPTIONS})
76+
target_include_directories (${_plugin_NAME} BEFORE PRIVATE ${_plugin_INCLUDE_DIRS})
7477
target_link_libraries (${_plugin_NAME} PUBLIC OpenImageIO
7578
PRIVATE ${_plugin_LINK_LIBRARIES})
7679
set_target_properties (${_plugin_NAME} PROPERTIES PREFIX "" FOLDER "Plugins")

src/libOpenImageIO/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ if (EMBEDPLUGINS)
8585
PRIVATE
8686
EMBED_PLUGINS=1
8787
${format_plugin_definitions})
88-
target_include_directories (OpenImageIO
88+
target_compile_options (OpenImageIO
89+
PRIVATE ${format_plugin_compile_options})
90+
target_include_directories (OpenImageIO BEFORE
8991
PRIVATE ${format_plugin_include_dirs})
9092

9193
# Organize the embedded plugins into source folders

src/raw.imageio/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ if (LIBRAW_FOUND)
66
add_oiio_plugin (rawinput.cpp
77
INCLUDE_DIRS ${LibRaw_INCLUDE_DIR}
88
LINK_LIBRARIES ${LibRaw_r_LIBRARIES}
9-
DEFINITIONS "-DUSE_LIBRAW=1" ${LibRaw_r_DEFINITIONS})
9+
COMPILE_OPTIONS ${LibRaw_r_DEFINITIONS}
10+
DEFINITIONS "USE_LIBRAW=1")
1011
else ()
1112
message (WARNING "Raw plugin will not be built")
1213
endif ()

0 commit comments

Comments
 (0)