[cmake-developers] For a certain use case, CMake configures linking to the *same* library in both -L... -l... form and raw file form

2019-08-17 Thread Alan W. Irwin

To temporarily work around some bugs in cmake-d support for the D
language case, I modified our normal use case for PLplot linking
between our D examples and D binding.  And that lead to the peculiar
result mentioned on the subject line which I have now also confirmed
for the Fortran language.  (So I presume this result holds both for
externally supported languages such as D and languages officially
supported by CMake such as Fortran.)

The PLplot Fortran examples link to the PLplot Fortran binding library
whose target name is PLPLOT::plplotfortran.  And PLplot uses
non-transitive linking on my (Linux, Debian Buster) platform.

So in the shared library build case, if I link the Fortran examples
using my normal method:

target_link_libraries(x${STRING_INDEX}f PLPLOT::plfortrandemolib 
PLPLOT::plplotfortran)

the resulting link command for our x00f example (and similarly for all
the rest) is

[100%] Linking Fortran executable x00f
cd /home/software/plplot/HEAD/build_dir/examples/fortran && 
/home/software/cmake/install-3.13.2/bin/cmake -E cmake_link_script 
CMakeFiles/x00f.dir/link.txt --verbose=1
/usr/bin/gfortran   -O3 -Wuninitialized -Wunused CMakeFiles/x00f.dir/x00f.f90.o  -o x00f -Wl,-rpath,/home/software/plplot/HEAD/build_dir/bindings/fortran ../libplfortrandemolib.a ../../bindings/fortran/libplplotfortran.so.0.2.0 
make[3]: Leaving directory '/home/software/plplot/HEAD/build_dir'

[100%] Built target x00f

which is the expected result (which mentions the link to the
plplotfortran library only in raw file format).  (N.B. I set the
environment variable FFLAGS="-O3 -Wuninitialized -Wunused" which
explains those special gfortran options.)

However, if I link the Fortran examples with

target_link_libraries(x${STRING_INDEX}f PLPLOT::plfortrandemolib 
$)
add_dependencies(x${STRING_INDEX}f PLPLOT::plplotfortran)

the resulting link command for our x00f example (and similarly for all
the rest) is

[100%] Linking Fortran executable x00f
cd /home/software/plplot/HEAD/build_dir/examples/fortran && 
/home/software/cmake/install-3.13.2/bin/cmake -E cmake_link_script 
CMakeFiles/x00f.dir/link.txt --verbose=1
/usr/bin/gfortran   -O3 -Wuninitialized -Wunused CMakeFiles/x00f.dir/x00f.f90.o  -o x00f  -L/home/software/plplot/HEAD/build_dir/bindings/fortran -Wl,-rpath,/home/software/plplot/HEAD/build_dir/bindings/fortran ../libplfortrandemolib.a -lplplotfortran ../../bindings/fortran/libplplotfortran.so.0.2.0 
make[3]: Leaving directory '/home/software/plplot/HEAD/build_dir'

[100%] Built target x00f

I expected that the result would simply link to the plplotfortran
library in "-L/home/software/plplot/HEAD/build_dir/bindings/fortran
-lplplotfortran" form so that redundant mention of the *same* library
in raw file form (../../bindings/fortran/libplplotfortran.so.0.2.0)
was a surprise to me.

My guess is this is actually an expected (albeit peculiar) result for
the above use case due to the existing general design of CMake
language support, but I thought I had better mention this result here
in case it is due to a bug in that support.

Alan
__
Alan W. Irwin

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.org); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__

Linux-powered Science
__
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers


Re: [cmake-developers] ninja generator does NOT use absolute paths at rules?

2019-08-17 Thread Claus Klein
There is a workaround about this issue:

Create the binary_dir (build) outside the source_dir!
Than every path to source files are absolute ;-)

i.e.:
clausklein$ make -n check
mkdir -p ../.build-samples-Debug
cd ../.build-samples-Debug && cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug 
-DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON 
-DCMAKE_CXX_COMPILER=/opt/local/bin/clang++ 
/Users/clausklein/Workspace/cpp/samples
ln -sf 
/Users/clausklein/Workspace/cpp/samples/../.build-samples-Debug/compile_commands.json
 .
run-clang-tidy.py -header-filter='/Users/clausklein/Workspace/cpp/samples/.*' 
-checks='-*,misc-*,boost-*,cert-*,-misc-unused-parameters' | tee 
run-clang-tidy.log 2>&1
egrep '\b(warning|error):' run-clang-tidy.log | perl -pe 's/(^.*) 
(warning|error):/\2/' | sort -u
clausklein$ 


-Claus

> Am 23.07.2019 um 13:03 schrieb Brad King :
> 
> On 7/22/19 4:47 PM, Claus Klein wrote:
>> Than I realized , the ninja.rules files contains NO absolute paths
>> to target source and header files.
> 
> Historically the Ninja ecosystem encourages use of relative paths.
> There is an issue for this in CMake:
> 
>  https://gitlab.kitware.com/cmake/cmake/issues/13894#note_233789
> 
> and fixing it correctly depends on fixing another issue in Ninja:
> 
>  https://github.com/ninja-build/ninja/issues/1251
> 
> -Brad

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers