Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libpngconf.c is attached to multiple targets #394

Closed
mgood7123 opened this issue Aug 28, 2021 · 7 comments
Closed

libpngconf.c is attached to multiple targets #394

mgood7123 opened this issue Aug 28, 2021 · 7 comments

Comments

@mgood7123
Copy link

CMake Error in /Users/smallville7123/StudioProjects/Graphical-Tool-Kit/app/src/main/cpp/freetype-cmake/libpng/CMakeLists.txt:
The custom command generating

/Users/smallville7123/StudioProjects/Graphical-Tool-Kit/macOS/IMPORTED_CMAKE_PROJECTS/OpenGLApp_CMAKE_PROJECT/GRAPHICS/libpng/pnglibconf.c

is attached to multiple targets:

genfiles
gensym
genvers

but none of these is a common dependency of the other(s). This is not
allowed by the Xcode "new build system".

when generating cmake project for XCode

@mgood7123
Copy link
Author

mgood7123 commented Aug 28, 2021

this seems to be fixed with the following

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -263,11 +263,17 @@ if(UNIX)
   symbol_prefix()
 endif()
 
-find_program(AWK NAMES gawk awk)
+if(CMAKE_GENERATOR MATCHES "Xcode" AND CMAKE_XCODE_BUILD_SYSTEM MATCHES 12)
+  message(WARNING "libpng does not currently support generating files for multiple targets using the Xcode \"new build system\", libpng will use the prebuilt pnglibconf instead")
+  set(PNG_XCODE_NEW_BUILD_SYSTEM true)
+else()
+  set(PNG_XCODE_NEW_BUILD_SYSTEM false)
+  find_program(AWK NAMES gawk awk)
+endif()
 
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
-if(NOT AWK OR ANDROID OR IOS)
+if (PNG_XCODE_NEW_BUILD_SYSTEM OR NOT AWK OR ANDROID OR IOS)
   # No awk available to generate sources; use pre-built pnglibconf.h
   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
                  ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
@@ -449,7 +455,7 @@ else()
                             "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk"
                             "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
                             "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out")
-endif(NOT AWK OR ANDROID OR IOS)
+endif(PNG_XCODE_NEW_BUILD_SYSTEM OR NOT AWK OR ANDROID OR IOS)
 
 # List the source code files.
 set(libpng_public_hdrs
@@ -463,8 +469,10 @@ set(libpng_private_hdrs
     pnginfo.h
     pngstruct.h
 )
-if(AWK AND NOT ANDROID AND NOT IOS)
+if(NOT PNG_XCODE_NEW_BUILD_SYSTEM AND AWK AND NOT ANDROID AND NOT IOS)
  list(APPEND libpng_private_hdrs "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h")
 endif()
 set(libpng_sources
     ${libpng_public_hdrs}

@glebm
Copy link
Contributor

glebm commented Dec 5, 2021

There is a clean fix in #403

@code-affinity
Copy link

I am facing the same error while building libpng 1.6.37 (because that is the version that is currently snapshotted in the latest version of the ImageMagick source distribution) with Xcode 12.4. Although #403 was applied to 1.6.38, I locally applied the changes from #403 to CMakeLists.txt for version 1.6.37, but I still get "attached to multiple targets" errors, although now it identifies different problem targets than before:

[08:31:15] : [Step 2/5] CMake Error in CMakeLists.txt:
[08:31:15] : [Step 2/5] The custom command generating
[08:31:15] : [Step 2/5]
[08:31:15] : [Step 2/5] /Users/build/buildAgent/work/64fba3137de0b35f/third-party/build/libpng-prefix/src/libpng-build/scripts/sym.out
[08:31:15] : [Step 2/5]
[08:31:15] : [Step 2/5] is attached to multiple targets:
[08:31:15] : [Step 2/5]
[08:31:15] : [Step 2/5] gensym
[08:31:15] : [Step 2/5] genfiles
[08:31:15] : [Step 2/5]
[08:31:15] : [Step 2/5] but none of these is a common dependency of the other(s). This is not
[08:31:15] : [Step 2/5] allowed by the Xcode "new build system".

I do not claim to understand what "none of these is a common dependency of the other(s)" means.

The custom command that generates sym.out is:

  generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/sym.c"
               OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
               DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h)
  add_custom_target(scripts_sym_out DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out")

The rules for the gensym target are:

  generate_copy(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out"
                OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym"
                DEPENDS scripts_sym_out)
  add_custom_target(gensym DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym")

The genfiles target depends on both the scripts_sym_out target and the gensym target:

  add_custom_target(genfiles
                    DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym" gensym
                            "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers" genvers
                            "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c" pnglibconf_c
                            "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" pnglibconf_h
                            "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" pnglibconf_out
                            "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h" pngprefix_h
                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out" scripts_intprefix_out
                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c" scripts_pnglibconf_c
                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out" scripts_prefix_out
                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out" scripts_sym_out
                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk" symbol-check
                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out" scripts_symbols_out
                            "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out" scripts_vers_out)

I believe this is exactly the state of affairs that results from #403, but it is not working in the context of the 1.6.37 CMakeLists.txt.

@glebm
Copy link
Contributor

glebm commented Mar 31, 2022

v1.6.37 is older than the current libpng16 branch. If my fix is merged, the issue will be fixed in the next 1.6 release

@code-affinity
Copy link

I understand. However, I have to work with what is available to me now, so I took matters into my own hands by applying the same changes to the older version. The 1.6.37 and 1.6.38 CMakeLists.txt are similar enough that the #403 changes were pretty straightforward to apply.

@code-affinity
Copy link

The more expedient solution in my case was to invoke CMake with "-T buildsystem=1", which tells it to use the old XCode build system that can tolerate the libpng CMakeLists.txt design.

@ctruta
Copy link
Member

ctruta commented Sep 10, 2022

Fixed.

@ctruta ctruta closed this as completed Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants