I apologize for top-posting, but I can't imagine how I could add my
comments next to your particular statements (which is not your
fault, it's just because this problem is - as you wrote -
difficult). Or maybe not, if you adhere to some "rules" of best
practices.
1. First of all, it's not a good idea to have one version of FLTK
"installed" in a default system location and trying to build an
application using another build or install location, or maybe other
combinations of different FLTK builds (maybe one for 1.3, and
another one for 1.4). The general recommendation for using different
FLTK builds is simple: never install any of these builds in default
system locations to avoid such conflicts in the first place. If you
build/install FLTK in non-system locations and use the full path for
building your specific applications, then there should be no
conflicts. I'm doing this all the time...
> When I rebuild with ...SYSTEM_LIBPNG=ON, the directory
/usr/local/include/FL/images is NOT removed. Should it?
2. You're missing one very important point in this statement.
You don't build directly in '/usr/local/include/FL/...',
do you?
What you are missing is the install step in this process.
But there is another option in FLTK's build system: uninstall.
So, if you had executed the `uninstall` step (e.g. `make uninstall`)
with the old/previous build settings (!), i.e. before
you even reconfigure the build, then that would (or at least should)
have removed all the previous build artifacts. However, just
installing another build over the previous build location
does not remove any old files, and it would not even know which
files to remove. Therefore it can't remove any files in the
'FL/images' folder when you build and install w/o the bundled image
libraries.
One aspect of `fltk-config` is that it tries to be smart and checks
the existence of some files in or below the main install location.
That's how it works. If there are files left from a previous
install, then fltk-config will very likely make wrong decisions.
Note: fltk-config is no longer necessary and should not be used if
you build FLTK (and your application) with CMake.
3. Since FLTK 1.4 we definitely recommend to
(a) build FLTK with CMake
(b) build FLTK applications with CMake as well, and
(c) use CMake's CONFIG (NO_MODULE) mode to find FLTK
(d) use "modern CMake" to build applications, i.e. to link to
`fltk::fltk` etc. to benefit from CMake's knowledge of include and
link directories rather than using CMake variables like
FLTK_INCLUDE_DIRECTORIES or similar.
With all these recommendations above you don't use fltk-config at
all, and this is way better and more reliable than to try to use
`fltk-config`, particularly if it was installed in a system
location. *IF* you want/need to use fltk-config for different FLTK
builds nevertheless, then you should at least take care to use the
full path of fltk-config to use the specific version of the build.
4. Last but not least: even with CMake's features to change build
options there can be unexpected issues because CMake caches results
of previous searches in its CMakeCache.txt
of the build folder. Therefore it can be necessary to
clean the entire CMake build folder to remove cached values (or at
least to remove CMakeCache.txt).
I'm aware that you may not be able or want to follow all
recommendations above, particularly if you have to use another build
system for a particular application. However, not installing FLTK in
default system locations and using the full path for `fltk-config`
should improve the situation. This implies not to install FLTK
packages from the Linux distro etc. if you need different FLTK
versions on the same system because these packages will be installed
in system locations.
I hope this helps. Somehow.