pnggroup / libpng

LIBPNG: Portable Network Graphics support, official libpng repository
http://libpng.sf.net
Other
1.25k stars 612 forks source link

can not pass compile when pass 'PNG_PREFIX' by using cmake #490

Open lanewei120 opened 1 year ago

lanewei120 commented 1 year ago

On Linux ubuntu 22.04, Steps to reproduce

  1. clone codes, store at /home/user.name/libpng
  2. cd libpng
  3. mkdir build;mkdir install_dir
  4. cmake ../ -DPNG_SHARED=OFF -DPNG_STATIC=ON -DPNG_TESTS=OFF -DPNGPREFIX=test -DCMAKE_PREFIX_PATH="/home/user.name/libpng" -DCMAKE_INSTALL_PREFIX="/home/user.name/libpng"
  5. cmake --build . --target install --config Release -j4
-- Symbol prefix:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user.name/libpng/build
[  1%] Built target scripts_symbols_out
[  2%] Built target scripts_pnglibconf_c
[  4%] Built target pnglibconf_c
Scanning dependencies of target symbol-check
Scanning dependencies of target pnglibconf_out
[  5%] Generating scripts/symbols.chk
[  6%] Generating pnglibconf.out
[  8%] Built target symbol-check
[  9%] Built target pnglibconf_out
Scanning dependencies of target scripts_prefix_out
Scanning dependencies of target pnglibconf_h
[ 10%] Generating scripts/prefix.out
[ 12%] Generating scripts/prefix.out
CMake Error at scripts/genout.cmake:90 (file):
  file RENAME failed to rename

    /home/user.name/libpng/build/scripts/prefix.out.tf2

  to

    /home/user.name/libpng/build/scripts/prefix.out

  because: No such file or directory

make[2]: *** [CMakeFiles/pnglibconf_h.dir/build.make:74: scripts/prefix.out] Error 1
make[2]: *** Deleting file 'scripts/prefix.out'
make[1]: *** [CMakeFiles/Makefile2:494: CMakeFiles/pnglibconf_h.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 14%] Built target scripts_prefix_out
make: *** [Makefile:141: all] Error 2
lanewei120 commented 1 year ago

it seems after this commit, it can not pass compile anymore with flag '-DPNG_PREFIX=xxx'

@glebm

commit cbf8c64b58d50038aa051cdcd595923f57191295
Author: Gleb Mazovetskiy <glex.spb@gmail.com>
Date:   Sat Dec 4 11:23:42 2021 +0000

    cmake: Correctly handle generated files

    Generated files depend on other generated files, and this previously
    resulted in the same custom command output being a dependency of
    multiple other custom commands without a shared custom targets.

    Adds a top-level target for each generated file and ensures that
    commands that depend on generated files also depend on the corresponding
    custom targets.

    Per CMake documentation:

    > Do not list the output in more than one independent target
    > that may build in parallel or the two instances of the rule
    > may conflict (instead use add_custom_target to drive the command
    > and make the other targets depend on that one).

    Signed-off-by: Cosmin Truta <ctruta@gmail.com>
jbowler commented 1 week ago

Hum:

../configure --with-libpng-prefix=conf; make -j; make -j check works and symbols are prefixed with conf

cmake .. -DPNG_PREFIX=cmake; make; make test works and the symbols are prefixed with cmake

cmake .. -DPNG_PREFIX=cmake; make -j fails, as reported

So pngprefix.h is being built twice in the same place (apparently). A work-round is to build without -j. This works:

cmake .. -DPNG_PREFIX=cmake; make -j; make; make -j test

The double build of pngprefix.h can be seen in the make output; Generating scripts/prefix.out appears twice with make -j

That said I can't even find where the dependencies on scripts/prefix.out are; needs a fix from @ctruta. Building -DPNG_SHARED=off doesn't help either (as reported.)