Re: [CMake] Problem with creating shared library

2018-09-01 Thread Damir Porobic
Any idea how I could fix the last issue in my shared library?

Cmake seems to expect a file with version in its name 
(/usr/local/lib64/libkImageAnnotator.so.0.0.1) but my cmake for the shared 
library only creates a file without version in it's name 
(/usr/local/lib64/libkImageAnnotator.so)


Manually creating a link seems to fix the issue, but I guess there is a way to 
let cmake generate it.


Any idea?


From: Damir Porobic 
Sent: Sunday, August 26, 2018 13:50
To: Sebastián Mancilla
Cc: cmake@cmake.org
Subject: Re: [CMake] Problem with creating shared library


Ok, I've found the issue for the latest problem but I'm not sure how to fix it 
in the CMake file. The make was using an old version of 
/usr/local/lib64/libkImageAnnotator.so.0.0.1 so I removed everything with 
kImageAnnotato in its name from this directory and run again the sudo make 
install which gave me this output


-- Install configuration: "Debug"
-- Up-to-date: 
/usr/local/lib64/cmake/kImageAnnotator/kImageAnnotator-config.cmake
-- Up-to-date: 
/usr/local/lib64/cmake/kImageAnnotator/kImageAnnotator-config-version.cmake
-- Up-to-date: 
/usr/local/lib64/cmake/kImageAnnotator/kImageAnnotator-targets.cmake
-- Up-to-date: 
/usr/local/lib64/cmake/kImageAnnotator/kImageAnnotator-targets-debug.cmake
-- Installing: /usr/local/lib64/libkImageAnnotator.so
-- Set runtime path of "/usr/local/lib64/libkImageAnnotator.so" to 
"/usr/local/lib64"
-- Up-to-date: /usr/local/include/kImageAnnotator
-- Up-to-date: /usr/local/include/kImageAnnotator/KImageAnnotator.h
-- Up-to-date: /usr/local/include/kImageAnnotator/KImageAnnotatorExport.h


So only libkImageAnnotator.so is created and installed, but not the one with 
the version at the end which cmake seems to expect: in my test project

CMake Error at 
/usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake:79 
(message):
  The imported target "kImageAnnotator" references the file

 "/usr/local/lib64/libkImageAnnotator.so.0.0.1"

  but this file does not exist.

When I manually create a link to the installed file:

$ sudo ln -s /usr/local/lib64/libkImageAnnotator.so 
/usr/local/lib64/libkImageAnnotator.so.0.0.1

Everything finally works, but I need to fix this final issue with the missing 
link. This was working earlier I think.



From: Damir Porobic 
Sent: Friday, August 24, 2018 9:37:30 PM
To: Sebastián Mancilla
Cc: cmake@cmake.org
Subject: Re: [CMake] Problem with creating shared library


I've fixed both issues, the second by implementing the pimpl idiom but still I 
can't used the library in the other project, again I get the error with 
undefined reference to the constructor (and a method that I've added):


[ 75%] Linking CXX executable testApp
CMakeFiles/testApp.dir/main.cpp.o: In function `main':
/home/dporobic/projects/testApp/main.cpp:9: undefined reference to 
`KImageAnnotator::KImageAnnotator(QPixmap const&)'
/home/dporobic/projects/testApp/main.cpp:11: undefined reference to 
`KImageAnnotator::testMethod()'
collect2: error: ld returned 1 exit status

But the constructor and the method don't seem to be private anymore:

dporobic@linux ~/projects/kImageAnnotator/build (sharedLibTestBranch)
$ nm -g lib/libkImageAnnotator.so | c++filt | grep "::testMethod\|::KImage"
00014f08 T KImageAnnotator::testMethod()
00014b18 T KImageAnnotator::KImageAnnotator(QPixmap const&)
00014b18 T KImageAnnotator::KImageAnnotator(QPixmap const&)

Also, after the constructor call and before the call to the test method in my 
test project, there is a call to an inherited method (show()) from QWidget and 
the linker is not complaining about this one:

auto kImageAnnotator = new KImageAnnotator(pixmap);
kImageAnnotator->show();
kImageAnnotator->testMethod();



From: Sebastián Mancilla 
Sent: Thursday, August 23, 2018 22:13
To: Damir Porobic
Cc: cmake@cmake.org
Subject: Re: [CMake] Problem with creating shared library

I forgot to update the include path in the patch I sent you.

It should be like this (note that it contains just "include", not 
"include/kImageAnnotator"):

target_include_directories(kImageAnnotator
PUBLIC
$
$
$
)

And kImageAnnotator.h should change the export include to:

#include "kImageAnnotatorExport.h"


You still have a bigger problem, though. kImageAnnotator.h is including private 
headers

#include "../../src/gui/VisibilitySwitcher.h"
#include "../../src/annotations/core/AnnotationArea.h"
#include "../../src/backend/Config.h"
#include "../../src/widgets/ToolPicker.h"
#include "../../src/widgets/ColorPicker.h"
#include "../../src/widgets/SizePicker.h"
#include "../../src/widgets/FillPicker.h"

If those are required by your clients, the

Re: [CMake] Problem with creating shared library

2018-08-26 Thread Damir Porobic
Ok, I've found the issue for the latest problem but I'm not sure how to fix it 
in the CMake file. The make was using an old version of 
/usr/local/lib64/libkImageAnnotator.so.0.0.1 so I removed everything with 
kImageAnnotato in its name from this directory and run again the sudo make 
install which gave me this output


-- Install configuration: "Debug"
-- Up-to-date: 
/usr/local/lib64/cmake/kImageAnnotator/kImageAnnotator-config.cmake
-- Up-to-date: 
/usr/local/lib64/cmake/kImageAnnotator/kImageAnnotator-config-version.cmake
-- Up-to-date: 
/usr/local/lib64/cmake/kImageAnnotator/kImageAnnotator-targets.cmake
-- Up-to-date: 
/usr/local/lib64/cmake/kImageAnnotator/kImageAnnotator-targets-debug.cmake
-- Installing: /usr/local/lib64/libkImageAnnotator.so
-- Set runtime path of "/usr/local/lib64/libkImageAnnotator.so" to 
"/usr/local/lib64"
-- Up-to-date: /usr/local/include/kImageAnnotator
-- Up-to-date: /usr/local/include/kImageAnnotator/KImageAnnotator.h
-- Up-to-date: /usr/local/include/kImageAnnotator/KImageAnnotatorExport.h


So only libkImageAnnotator.so is created and installed, but not the one with 
the version at the end which cmake seems to expect: in my test project

CMake Error at 
/usr/local/share/kImageAnnotatorConfig/cmake/kImageAnnotatorConfig.cmake:79 
(message):
  The imported target "kImageAnnotator" references the file

 "/usr/local/lib64/libkImageAnnotator.so.0.0.1"

  but this file does not exist.

When I manually create a link to the installed file:

$ sudo ln -s /usr/local/lib64/libkImageAnnotator.so 
/usr/local/lib64/libkImageAnnotator.so.0.0.1

Everything finally works, but I need to fix this final issue with the missing 
link. This was working earlier I think.



From: Damir Porobic 
Sent: Friday, August 24, 2018 9:37:30 PM
To: Sebastián Mancilla
Cc: cmake@cmake.org
Subject: Re: [CMake] Problem with creating shared library


I've fixed both issues, the second by implementing the pimpl idiom but still I 
can't used the library in the other project, again I get the error with 
undefined reference to the constructor (and a method that I've added):


[ 75%] Linking CXX executable testApp
CMakeFiles/testApp.dir/main.cpp.o: In function `main':
/home/dporobic/projects/testApp/main.cpp:9: undefined reference to 
`KImageAnnotator::KImageAnnotator(QPixmap const&)'
/home/dporobic/projects/testApp/main.cpp:11: undefined reference to 
`KImageAnnotator::testMethod()'
collect2: error: ld returned 1 exit status

But the constructor and the method don't seem to be private anymore:

dporobic@linux ~/projects/kImageAnnotator/build (sharedLibTestBranch)
$ nm -g lib/libkImageAnnotator.so | c++filt | grep "::testMethod\|::KImage"
00014f08 T KImageAnnotator::testMethod()
00014b18 T KImageAnnotator::KImageAnnotator(QPixmap const&)
00014b18 T KImageAnnotator::KImageAnnotator(QPixmap const&)

Also, after the constructor call and before the call to the test method in my 
test project, there is a call to an inherited method (show()) from QWidget and 
the linker is not complaining about this one:

auto kImageAnnotator = new KImageAnnotator(pixmap);
kImageAnnotator->show();
kImageAnnotator->testMethod();



From: Sebastián Mancilla 
Sent: Thursday, August 23, 2018 22:13
To: Damir Porobic
Cc: cmake@cmake.org
Subject: Re: [CMake] Problem with creating shared library

I forgot to update the include path in the patch I sent you.

It should be like this (note that it contains just "include", not 
"include/kImageAnnotator"):

target_include_directories(kImageAnnotator
PUBLIC
$
$
$
)

And kImageAnnotator.h should change the export include to:

#include "kImageAnnotatorExport.h"


You still have a bigger problem, though. kImageAnnotator.h is including private 
headers

#include "../../src/gui/VisibilitySwitcher.h"
#include "../../src/annotations/core/AnnotationArea.h"
#include "../../src/backend/Config.h"
#include "../../src/widgets/ToolPicker.h"
#include "../../src/widgets/ColorPicker.h"
#include "../../src/widgets/SizePicker.h"
#include "../../src/widgets/FillPicker.h"

If those are required by your clients, then they should be in the 
"include/kImageAnnotator" directory and installed along with 
"kImageAnnotator.h".
Otherwise, consider using the pimpl idiom and remove the includes from the 
public header.


El mié., 22 de ago. de 2018 a la(s) 17:08, Damir Porobic 
(damir_poro...@live.com<mailto:damir_poro...@live.com>) escribió:

Thanks you Sebastián for finding the issue and fixing the CMake, probably would 
have never found out that it was set to private.


The kImageAnnotator-example is working now as expected. Do I need something 
else, except installing the lib, in order to use

Re: [CMake] Problem with creating shared library

2018-08-24 Thread Damir Porobic
I've fixed both issues, the second by implementing the pimpl idiom but still I 
can't used the library in the other project, again I get the error with 
undefined reference to the constructor (and a method that I've added):


[ 75%] Linking CXX executable testApp
CMakeFiles/testApp.dir/main.cpp.o: In function `main':
/home/dporobic/projects/testApp/main.cpp:9: undefined reference to 
`KImageAnnotator::KImageAnnotator(QPixmap const&)'
/home/dporobic/projects/testApp/main.cpp:11: undefined reference to 
`KImageAnnotator::testMethod()'
collect2: error: ld returned 1 exit status

But the constructor and the method don't seem to be private anymore:

dporobic@linux ~/projects/kImageAnnotator/build (sharedLibTestBranch)
$ nm -g lib/libkImageAnnotator.so | c++filt | grep "::testMethod\|::KImage"
00014f08 T KImageAnnotator::testMethod()
00014b18 T KImageAnnotator::KImageAnnotator(QPixmap const&)
00014b18 T KImageAnnotator::KImageAnnotator(QPixmap const&)

Also, after the constructor call and before the call to the test method in my 
test project, there is a call to an inherited method (show()) from QWidget and 
the linker is not complaining about this one:

auto kImageAnnotator = new KImageAnnotator(pixmap);
kImageAnnotator->show();
kImageAnnotator->testMethod();



From: Sebastián Mancilla 
Sent: Thursday, August 23, 2018 22:13
To: Damir Porobic
Cc: cmake@cmake.org
Subject: Re: [CMake] Problem with creating shared library

I forgot to update the include path in the patch I sent you.

It should be like this (note that it contains just "include", not 
"include/kImageAnnotator"):

target_include_directories(kImageAnnotator
PUBLIC
$
$
$
)

And kImageAnnotator.h should change the export include to:

#include "kImageAnnotatorExport.h"


You still have a bigger problem, though. kImageAnnotator.h is including private 
headers

#include "../../src/gui/VisibilitySwitcher.h"
#include "../../src/annotations/core/AnnotationArea.h"
#include "../../src/backend/Config.h"
#include "../../src/widgets/ToolPicker.h"
#include "../../src/widgets/ColorPicker.h"
#include "../../src/widgets/SizePicker.h"
#include "../../src/widgets/FillPicker.h"

If those are required by your clients, then they should be in the 
"include/kImageAnnotator" directory and installed along with 
"kImageAnnotator.h".
Otherwise, consider using the pimpl idiom and remove the includes from the 
public header.


El mié., 22 de ago. de 2018 a la(s) 17:08, Damir Porobic 
(damir_poro...@live.com<mailto:damir_poro...@live.com>) escribió:

Thanks you Sebastián for finding the issue and fixing the CMake, probably would 
have never found out that it was set to private.


The kImageAnnotator-example is working now as expected. Do I need something 
else, except installing the lib, in order to use it in different projects? I've 
created a second project which is identical to the kImageAnnotator-example but 
I get following when I try to build it:


[ 50%] Building CXX object CMakeFiles/testApp.dir/main.cpp.o
In file included from /home/dporobic/projects/testApp/main.cpp:2:0:
/usr/local/include/kImageAnnotator/KImageAnnotator.h:31:35: fatal error: 
KImageAnnotatorExport.h: No such file or directory
 #include 
   ^
compilation terminated.


The includes look like this:

#include 
#include 


And the CMake looks like this:

find_package(kImageAnnotator REQUIRED)

add_executable(testApp main.cpp)
target_link_libraries(testApp kImageAnnotator)


Am I missing something again?



From: Sebastián Mancilla mailto:smanc...@jlab.org>>
Sent: Wednesday, August 22, 2018 00:51
To: Eric Noulard
Cc: Damir Porobic; cmake@cmake.org<mailto:cmake@cmake.org>
Subject: Re: [CMake] Problem with creating shared library

I fixed your problem. Get the attached patch and apply it with "git apply 
".

The kImageAnnotator constructor was private to the library (I just learned that 
Qt does that when creating shared libraries), and that's why you get the 
undefined reference error. You could have checked it with:

nm lib/libkImageAnnotator.so | c++filt | grep ::KImage
000141f6 t KImageAnnotator::KImageAnnotator(QPixmap const&)
000141f6 t KImageAnnotator::KImageAnnotator(QPixmap const&)

The "t" shows it is private.

You have to set the proper export macros to make it visible:

https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application<https://urldefense.proofpoint.com/v2/url?u=https-3A__wiki.qt.io_How-5Fto-5Fcreate-5Fa-5Flibrary-5Fwith-5FQt-5Fand-5Fuse-5Fit-5Fin-5Fan-5Fapplication=DwMFAw=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4=y6-B01YTd3TICi74QxO0Lf

Re: [CMake] Problem with creating shared library

2018-08-23 Thread Sebastián Mancilla
I forgot to update the include path in the patch I sent you.

It should be like this (note that it contains just "include", not
"include/kImageAnnotator"):

target_include_directories(kImageAnnotator
PUBLIC
$
$
$
)

And kImageAnnotator.h should change the export include to:

#include "kImageAnnotatorExport.h"


You still have a bigger problem, though. kImageAnnotator.h is including
private headers

#include "../../src/gui/VisibilitySwitcher.h"
#include "../../src/annotations/core/AnnotationArea.h"
#include "../../src/backend/Config.h"
#include "../../src/widgets/ToolPicker.h"
#include "../../src/widgets/ColorPicker.h"
#include "../../src/widgets/SizePicker.h"
#include "../../src/widgets/FillPicker.h"

If those are required by your clients, then they should be in the
"include/kImageAnnotator" directory and installed along with
"kImageAnnotator.h".
Otherwise, consider using the pimpl idiom and remove the includes from the
public header.


El mié., 22 de ago. de 2018 a la(s) 17:08, Damir Porobic (
damir_poro...@live.com) escribió:

> Thanks you Sebastián for finding the issue and fixing the CMake, probably
> would have never found out that it was set to private.
>
>
> The kImageAnnotator-example is working now as expected. Do I need
> something else, except installing the lib, in order to use it in different
> projects? I've created a second project which is identical to the
> kImageAnnotator-example but I get following when I try to build it:
>
>
> [ 50%] Building CXX object CMakeFiles/testApp.dir/main.cpp.o
> In file included from /home/dporobic/projects/testApp/main.cpp:2:0:
> /usr/local/include/kImageAnnotator/KImageAnnotator.h:31:35: fatal error:
> KImageAnnotatorExport.h: No such file or directory
>  #include 
>^
> compilation terminated.
>
> The includes look like this:
>
> #include 
> #include 
>
>
> And the CMake looks like this:
>
> find_package(kImageAnnotator REQUIRED)
>
> add_executable(testApp main.cpp)
> target_link_libraries(testApp kImageAnnotator)
>
>
> Am I missing something again?
>
>
>
> --
> *From:* Sebastián Mancilla 
> *Sent:* Wednesday, August 22, 2018 00:51
> *To:* Eric Noulard
> *Cc:* Damir Porobic; cmake@cmake.org
> *Subject:* Re: [CMake] Problem with creating shared library
>
> I fixed your problem. Get the attached patch and apply it with "git apply
> ".
>
> The kImageAnnotator constructor was private to the library (I just learned
> that Qt does that when creating shared libraries), and that's why you get
> the undefined reference error. You could have checked it with:
>
> nm lib/libkImageAnnotator.so | c++filt | grep ::KImage
> 000141f6 t KImageAnnotator::KImageAnnotator(QPixmap const&)
> 000141f6 t KImageAnnotator::KImageAnnotator(QPixmap const&)
>
> The "t" shows it is private.
>
> You have to set the proper export macros to make it visible:
>
>
> https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__wiki.qt.io_How-5Fto-5Fcreate-5Fa-5Flibrary-5Fwith-5FQt-5Fand-5Fuse-5Fit-5Fin-5Fan-5Fapplication=DwMFAw=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4=y6-B01YTd3TICi74QxO0LfDQVtz1m7fckmS3ItKkAmE=WmSjv8Q5QDreoWKNX4mS9hZm6lMR1pfhmDpjVug9nKU=>
> http://doc.qt.io/qt-5/sharedlibra
> How to create a library with Qt and use it in an application
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__wiki.qt.io_How-5Fto-5Fcreate-5Fa-5Flibrary-5Fwith-5FQt-5Fand-5Fuse-5Fit-5Fin-5Fan-5Fapplication=DwMFAw=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4=y6-B01YTd3TICi74QxO0LfDQVtz1m7fckmS3ItKkAmE=WmSjv8Q5QDreoWKNX4mS9hZm6lMR1pfhmDpjVug9nKU=>
> wiki.qt.io
> This tutorial illustrates different approaches for using a custom library
> in your application on Windows. The first part explains how to create a
> shared library and how to link against it in your application. The second
> part is about creating and using a static library. Creating a shared
> library ...
> ry.html
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__doc.qt.io_qt-2D5_sharedlibrary.html=DwMFAw=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4=y6-B01YTd3TICi74QxO0LfDQVtz1m7fckmS3ItKkAmE=I_GD4gkI-8u5o_gjXOD-wZKguDdfF2Gu4YG3Swst3hY=>
>
> The patch does that, and now the example links with the library just fine.
> The kImageAnnotatorExport.h header defines the macro, the compile
> definition is set for the shared librar

Re: [CMake] Problem with creating shared library

2018-08-22 Thread Damir Porobic
Thanks you Sebastián for finding the issue and fixing the CMake, probably would 
have never found out that it was set to private.


The kImageAnnotator-example is working now as expected. Do I need something 
else, except installing the lib, in order to use it in different projects? I've 
created a second project which is identical to the kImageAnnotator-example but 
I get following when I try to build it:


[ 50%] Building CXX object CMakeFiles/testApp.dir/main.cpp.o
In file included from /home/dporobic/projects/testApp/main.cpp:2:0:
/usr/local/include/kImageAnnotator/KImageAnnotator.h:31:35: fatal error: 
KImageAnnotatorExport.h: No such file or directory
 #include 
   ^
compilation terminated.


The includes look like this:

#include 
#include 


And the CMake looks like this:

find_package(kImageAnnotator REQUIRED)

add_executable(testApp main.cpp)
target_link_libraries(testApp kImageAnnotator)


Am I missing something again?



From: Sebastián Mancilla 
Sent: Wednesday, August 22, 2018 00:51
To: Eric Noulard
Cc: Damir Porobic; cmake@cmake.org
Subject: Re: [CMake] Problem with creating shared library

I fixed your problem. Get the attached patch and apply it with "git apply 
".

The kImageAnnotator constructor was private to the library (I just learned that 
Qt does that when creating shared libraries), and that's why you get the 
undefined reference error. You could have checked it with:

nm lib/libkImageAnnotator.so | c++filt | grep ::KImage
000141f6 t KImageAnnotator::KImageAnnotator(QPixmap const&)
000141f6 t KImageAnnotator::KImageAnnotator(QPixmap const&)

The "t" shows it is private.

You have to set the proper export macros to make it visible:

https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
http://doc.qt.io/qt-5/sharedlibra
<http://doc.qt.io/qt-5/sharedlibrary.html>
How to create a library with Qt and use it in an 
application<https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application>
wiki.qt.io
This tutorial illustrates different approaches for using a custom library in 
your application on Windows. The first part explains how to create a shared 
library and how to link against it in your application. The second part is 
about creating and using a static library. Creating a shared library ...

ry.html

The patch does that, and now the example links with the library just fine. The 
kImageAnnotatorExport.h header defines the macro, the compile definition is set 
for the shared library target in the CMakeLists.txt. I guess you'll  have to do 
the same for all classes used by the unit tests, no sure of the Qt development 
practices.

I also reworked your CMake files a bit. I am sending a single patch, though. 
Sorry.


El mar., 21 de ago. de 2018 a la(s) 14:29, Eric Noulard 
(eric.noul...@gmail.com<mailto:eric.noul...@gmail.com>) escribió:


Le lun. 20 août 2018 à 19:05, Damir Porobic 
mailto:damir_poro...@live.com>> a écrit :

Hi Eric,


yes, this is the project. I have pushed my current state to this branch 
https://github.com/DamirPorobic/kImageAnnotator/tree/sharedLibTestBranch<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_DamirPorobic_kImageAnnotator_tree_sharedLibTestBranch=DwMFaQ=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4=r4LA5jjr_jrRNhddqyy5IsuqRRwHEPCwRMFbxoU1ChI=j_vYMAeNlkSJPzPWt5eGGRXiqm4RocWUGgyctA8SGE4=>


I've tried also without the generate_export_headers (cleaned everything up 
before trying out) but I get the same result.


KImageAnnotator::KImageAnnotator(QPixmap const&)should be exposed by the 
handwritten file, that's true, I think I got something mixed up there and I 
don't actually need the generate_export_headers, but as said, even without the 
line, it's not working.

I'm quite lost with the file layout.

in example/main.cpp you do:
#include 
so I guess you expect that
target_link_libraries(kImageAnnotator-example PRIVATE 
kImageAnnotator::kImageAnnotator)

will bring you the include path to "kImageAnnotator/KImageAnnotator.h" along 
with the [imported] target

in your main tree (not in example) there is a trick because you did:

add_library(kImageAnnotator::kImageAnnotator ALIAS kImageAnnotator)

and then in the test directory you do:

target_link_libraries(${UnitTestName} Qt5::Test kimageannotator_LIB)

with

add_library(kimageannotator_LIB STATIC ${kimageannotator_SRCS})

so AFAIU you compile your kImageAnnotator library twice. Once for building the 
target you expect to use in example/ subdir
and another time as a STATIC lib for the unit test. So the unit test is not 
linking to the same object lib at all ??

I am not used to KDE development but all this seems very fuzzy to me.

May be you could get more precise help from people who know better about KDE 
dev and the specific CMake machinery that

Re: [CMake] Problem with creating shared library

2018-08-21 Thread Sebastián Mancilla
I fixed your problem. Get the attached patch and apply it with "git apply
".

The kImageAnnotator constructor was private to the library (I just learned
that Qt does that when creating shared libraries), and that's why you get
the undefined reference error. You could have checked it with:

nm lib/libkImageAnnotator.so | c++filt | grep ::KImage
000141f6 t KImageAnnotator::KImageAnnotator(QPixmap const&)
000141f6 t KImageAnnotator::KImageAnnotator(QPixmap const&)

The "t" shows it is private.

You have to set the proper export macros to make it visible:

https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application
http://doc.qt.io/qt-5/sharedlibrary.html

The patch does that, and now the example links with the library just fine.
The kImageAnnotatorExport.h header defines the macro, the compile
definition is set for the shared library target in the CMakeLists.txt. I
guess you'll  have to do the same for all classes used by the unit tests,
no sure of the Qt development practices.

I also reworked your CMake files a bit. I am sending a single patch,
though. Sorry.


El mar., 21 de ago. de 2018 a la(s) 14:29, Eric Noulard (
eric.noul...@gmail.com) escribió:

>
>
> Le lun. 20 août 2018 à 19:05, Damir Porobic  a
> écrit :
>
>> Hi Eric,
>>
>>
>> yes, this is the project. I have pushed my current state to this branch
>> https://github.com/DamirPorobic/kImageAnnotator/tree/sharedLibTestBranch
>> 
>>
>> I've tried also without the generate_export_headers (cleaned everything
>> up before trying out) but I get the same result.
>>
>>
>> KImageAnnotator::KImageAnnotator(QPixmap const&)should be exposed by the
>> handwritten file, that's true, I think I got something mixed up there and I
>> don't actually need the generate_export_headers, but as said, even
>> without the line, it's not working.
>>
>
> I'm quite lost with the file layout.
>
> in example/main.cpp you do:
> #include 
> so I guess you expect that
> target_link_libraries(kImageAnnotator-example PRIVATE
> kImageAnnotator::kImageAnnotator)
>
> will bring you the include path to "kImageAnnotator/KImageAnnotator.h"
> along with the [imported] target
>
> in your main tree (not in example) there is a trick because you did:
>
> add_library(kImageAnnotator::kImageAnnotator ALIAS kImageAnnotator)
>
> and then in the test directory you do:
>
> target_link_libraries(${UnitTestName} Qt5::Test kimageannotator_LIB)
>
> with
>
> add_library(kimageannotator_LIB STATIC ${kimageannotator_SRCS})
>
> so AFAIU you compile your kImageAnnotator library twice. Once for building
> the target you expect to use in example/ subdir
> and another time as a STATIC lib for the unit test. So the unit test is
> not linking to the same object lib at all ??
>
> I am not used to KDE development but all this seems very fuzzy to me.
>
> May be you could get more precise help from people who know better about
> KDE dev and the specific CMake machinery that comes along
> like ECM (https://github.com/KDE/extra-cmake-modules
> )
> you seems to be using.
>
> --
> Eric
>


-- 
Sebastian Mancilla Matta
CCTVal, UTFSM
Valparaíso, Chile


kia.patch
Description: Binary data
-- 

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


Re: [CMake] Problem with creating shared library

2018-08-21 Thread Eric Noulard
Le lun. 20 août 2018 à 19:05, Damir Porobic  a
écrit :

> Hi Eric,
>
>
> yes, this is the project. I have pushed my current state to this branch
> https://github.com/DamirPorobic/kImageAnnotator/tree/sharedLibTestBranch
>
> I've tried also without the generate_export_headers (cleaned everything up
> before trying out) but I get the same result.
>
>
> KImageAnnotator::KImageAnnotator(QPixmap const&)should be exposed by the
> handwritten file, that's true, I think I got something mixed up there and I
> don't actually need the generate_export_headers, but as said, even
> without the line, it's not working.
>

I'm quite lost with the file layout.

in example/main.cpp you do:
#include 
so I guess you expect that
target_link_libraries(kImageAnnotator-example PRIVATE
kImageAnnotator::kImageAnnotator)

will bring you the include path to "kImageAnnotator/KImageAnnotator.h"
along with the [imported] target

in your main tree (not in example) there is a trick because you did:

add_library(kImageAnnotator::kImageAnnotator ALIAS kImageAnnotator)

and then in the test directory you do:

target_link_libraries(${UnitTestName} Qt5::Test kimageannotator_LIB)

with

add_library(kimageannotator_LIB STATIC ${kimageannotator_SRCS})

so AFAIU you compile your kImageAnnotator library twice. Once for building
the target you expect to use in example/ subdir
and another time as a STATIC lib for the unit test. So the unit test is not
linking to the same object lib at all ??

I am not used to KDE development but all this seems very fuzzy to me.

May be you could get more precise help from people who know better about
KDE dev and the specific CMake machinery that comes along
like ECM (https://github.com/KDE/extra-cmake-modules) you seems to be using.

-- 
Eric
-- 

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


Re: [CMake] Problem with creating shared library

2018-08-20 Thread Damir Porobic
Hi Eric,


yes, this is the project. I have pushed my current state to this branch 
https://github.com/DamirPorobic/kImageAnnotator/tree/sharedLibTestBranch


I've tried also without the generate_export_headers (cleaned everything up 
before trying out) but I get the same result.


KImageAnnotator::KImageAnnotator(QPixmap const&)should be exposed by the 
handwritten file, that's true, I think I got something mixed up there and I 
don't actually need the generate_export_headers, but as said, even without the 
line, it's not working.


Cheers,

Damir


From: Eric Noulard 
Sent: Sunday, August 19, 2018 22:44
To: Damir Porobic
Cc: smanc...@jlab.org; CMake Mailinglist
Subject: Re: [CMake] Problem with creating shared library

Hi Damir,

May be the issue has nothing to do with the way you build the exported 
<>Config.cmake files.
Since may be some nasty detail slipped in, could you tell us if the project is 
public.
It looks like this one:
https://github.com/DamirPorobic/kImageAnnotator

may be you can push a branch that contains the exact thing that fails on your 
side and it may be easier to review the detail?

on the master of this repo there does not seem to have any "example" dir.

However you already have hand written header file:
https://github.com/DamirPorobic/kImageAnnotator/blob/master/src/gui/KImageAnnotator.h

which has the very same name as the "exported header you generate":
generate_export_header(kImageAnnotator
EXPORT_MACRO_NAME KIMAGEANNOTATOR_API
EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/include/KImageAnnotator.h
)

so may be
KImageAnnotator::KImageAnnotator(QPixmap const&)
is exposed by the hand-written file and not by the generated one so
that your unit test links ok but your "example" does not ?

Did you check the content of the generated header file?








Le dim. 19 août 2018 à 15:17, Damir Porobic 
mailto:damir_poro...@live.com>> a écrit :

Thanks Sebastián for providing those links!


I've followed the second link that you've provided but somehow I'm still 
running into issue.


I've changed the directory structure to this:

- kImageAnnotator
- cmake
- kImageAnnotator-config.cmake.in<http://config.cmake.in>
- example
- main.cpp
- CMakeLists.txt
- include
- kImageAnnotator
- KImageAnnotator.h // the main api header
- src
- KImageAnnotator.cpp
- "And all other .cpp and .h files"
- CMakeLists.txt
- CMakeLists.txt

src/CMakeList.txt looks like this:
add_library(kImageAnnotator ${kimageannotator_SRCS} 
${CMAKE_SOURCE_DIR}/include/kImageAnnotator/KImageAnnotator.h)

add_library(kImageAnnotator::kImageAnnotator ALIAS kImageAnnotator)

option(BUILD_SHARED_LIBS "Build shared library" ON)
include(GenerateExportHeader)

generate_export_header(kImageAnnotator
EXPORT_MACRO_NAME KIMAGEANNOTATOR_API
EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/include/KImageAnnotator.h
)

target_include_directories(kImageAnnotator
PUBLIC
$
$
$
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

set_target_properties(kImageAnnotator PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

find_package(Qt5 ${QT_MIN_VERSION} REQUIRED Widgets)

find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS CoreAddons I18n 
WidgetsAddons)

target_link_libraries(kImageAnnotator Qt5::Widgets KF5::CoreAddons KF5::I18n 
KF5::WidgetsAddons)

include(GNUInstallDirs)

install(TARGETS kImageAnnotator
EXPORT kImageAnnotator-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${LIBLEGACY_INCLUDE_DIRS}
)

install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/kImageAnnotator
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT kImageAnnotator-targets
FILE kImageAnnotator-targets.cmake
NAMESPACE kImageAnnotator::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kImageAnnotator
)


include(CMakePackageConfigHelpers)

configure_package_config_file(

${CMAKE_SOURCE_DIR}/cmake/kImageAnnotator-config.cmake.in<http://kImageAnnotator-config.cmake.in>
${CMAKE_BINARY_DIR}/cmake/kImageAnnotator-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kImageAnnotator
)

write_basic_package_version_file(
${CMAKE_BINARY_DIR}/cmake/kImageAnnotator-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(FILES
${CMAKE_BINARY_DIR}/cmake/kImageAnnotator-config.cmake
${CMAKE_BINARY_DIR}/cmake/kImageAnnotator-config-version.cmake
DESTINATION ${CMAKE_INSTALL_L

Re: [CMake] Problem with creating shared library

2018-08-19 Thread Eric Noulard
 Widgets)
>
> find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS CoreAddons I18n
> WidgetsAddons)
>
> if(NOT TARGET kImageAnnotator::kImageAnnotator)
>   include("${CMAKE_CURRENT_LIST_DIR}/kImageAnnotator-targets.cmake")
> endif()
>
>
>
> example/CMakeLists.txt looks like this:
>
> add_executable(kImageAnnotator-example
> ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
>
> target_link_libraries(kImageAnnotator-example PRIVATE
> kImageAnnotator::kImageAnnotator)
>
>
>
> And example/main.cpp looks like this:
>
> #include 
> #include 
>
> int main(int argc, char **argv)
> {
> QApplication app(argc, argv);
> QPixmap pixmap(QSize(500, 500));
> pixmap.fill(QColor(Qt::darkGreen));
> auto kImageAnnotator = new KImageAnnotator(pixmap);
> kImageAnnotator->show();
>
> return app.exec();
> }
>
>
>
> Still I'm getting following error when trying to build
> kImageAnnotator-example:
>
> Scanning dependencies of target kImageAnnotator-example
> [ 98%] Building CXX object
> example/CMakeFiles/kImageAnnotator-example.dir/main.cpp.o
> [ 98%] Building CXX object
> example/CMakeFiles/kImageAnnotator-example.dir/kImageAnnotator-example_autogen/mocs_compilation.cpp.o
> [100%] Linking CXX executable kImageAnnotator-example
> CMakeFiles/kImageAnnotator-example.dir/main.cpp.o: In function `main':
> /home/dporobic/projects/kImageAnnotator/example/main.cpp:29: undefined
> reference to `KImageAnnotator::KImageAnnotator(QPixmap const&)'
> collect2: error: ld returned 1 exit status
> example/CMakeFiles/kImageAnnotator-example.dir/build.make:98: recipe for
> target 'example/kImageAnnotator-example' failed
>
> Any idea what I'm doing wrong? It looks like the same issue that I was
> having earlier.
>
>
> --
> *From:* Sebastián Mancilla 
> *Sent:* Wednesday, August 15, 2018 21:48
> *To:* damir_poro...@live.com
> *Cc:* cmake@cmake.org
> *Subject:* Re: [CMake] Problem with creating shared library
>
> You are mixing the config file and the targets file.
>
> The config file is a template that you normally put in cmake/
> FooConfig.cmake.in
>
> You copy the template into the binary dir:
>
> include(CMakePackageConfigHelpers)
>
> set(INSTALL_CONFIGDIR lib/cmake/Foo)
>
> configure_package_config_file(
>   "${CMAKE_CURRENT_LIST_DIR}/cmake/FooConfig.cmake.in"
>   "${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake"
>   INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
> )
>
> It is a good idea to create a version file:
>
> write_basic_package_version_file(
>   "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake"
>   VERSION ${PROJECT_VERSION}
>   COMPATIBILITY SameMajorVersion
>)
>
> And then install both:
>
> install(FILES
> "${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake"
> "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake"
>   DESTINATION ${INSTALL_CONFIGDIR}
>   COMPONENT Devel
> )
>
> For the targets is a different file. When you install the library you
> should use
>
> install(TARGETS Foo EXPORT FooTargets ...)
>
> And then export and install the targets:
>
> # Into the build tree
> export(EXPORT FooTargets
>   FILE "${CMAKE_CURRENT_BINARY_DIR}/FooTargets.cmake"
>   NAMESPACE Foo::
> )
>
> # Into PREFIX
> install(EXPORT FooTargets
>   FILE FooTargets.cmake
>   NAMESPACE Foo::
>   DESTINATION ${INSTALL_CONFIGDIR}
>   COMPONENT Devel
> )
>
> Finally, your template FooConfig.cmake.in should look like this:
>
>   include(CMakeFindDependencyMacro)
>
>   @PACKAGE_INIT@
>
>   # list your required dependencies here
>   find_dependency(Threads)
>
>   if(NOT TARGET Foo::Foo)
> include("${CMAKE_CURRENT_LIST_DIR}/FooTargets.cmake")
>   endif()
>
> All this is pretty much the same for any project. Here are the best links
> explaining it:
>
> https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
> http://unclejimbo.github.io/2018/06/08/Modern-CMake-for-Library-Developers/
>
>
>
>
> El mié., 15 de ago. de 2018 a la(s) 05:32, Damir Porobic (
> damir_poro...@live.com) escribió:
>
> Hi Folks,
>
>
> I'm trying to write a shared library and run into an issue where I can't
> find any clues to where the problem is.
>
> I have a project with following structure:
>
>
> src/
>
> dir1/
>
> file1.h
>
> file1.cpp
>
> dir2/
>
> file2.h
> file2.cpp
>
>
>
> Now I have this

Re: [CMake] Problem with creating shared library

2018-08-19 Thread Damir Porobic
2018 21:48
To: damir_poro...@live.com
Cc: cmake@cmake.org
Subject: Re: [CMake] Problem with creating shared library

You are mixing the config file and the targets file.

The config file is a template that you normally put in 
cmake/FooConfig.cmake.in<http://FooConfig.cmake.in>

You copy the template into the binary dir:

include(CMakePackageConfigHelpers)

set(INSTALL_CONFIGDIR lib/cmake/Foo)

configure_package_config_file(
  
"${CMAKE_CURRENT_LIST_DIR}/cmake/FooConfig.cmake.in<http://FooConfig.cmake.in>"
  "${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake"
  INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)

It is a good idea to create a version file:

write_basic_package_version_file(
  "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake"
  VERSION ${PROJECT_VERSION}
  COMPATIBILITY SameMajorVersion
   )

And then install both:

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake"
  DESTINATION ${INSTALL_CONFIGDIR}
  COMPONENT Devel
)

For the targets is a different file. When you install the library you should use

install(TARGETS Foo EXPORT FooTargets ...)

And then export and install the targets:

# Into the build tree
export(EXPORT FooTargets
  FILE "${CMAKE_CURRENT_BINARY_DIR}/FooTargets.cmake"
  NAMESPACE Foo::
)

# Into PREFIX
install(EXPORT FooTargets
  FILE FooTargets.cmake
  NAMESPACE Foo::
  DESTINATION ${INSTALL_CONFIGDIR}
  COMPONENT Devel
)

Finally, your template FooConfig.cmake.in<http://FooConfig.cmake.in> should 
look like this:

  include(CMakeFindDependencyMacro)

  @PACKAGE_INIT@

  # list your required dependencies here
  find_dependency(Threads)

  if(NOT TARGET Foo::Foo)
include("${CMAKE_CURRENT_LIST_DIR}/FooTargets.cmake")
  endif()

All this is pretty much the same for any project. Here are the best links 
explaining it:

https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
http://unclejimbo.github.io/2018/06/08/Modern-CMake-for-Library-Developers/




El mié., 15 de ago. de 2018 a la(s) 05:32, Damir Porobic 
(damir_poro...@live.com<mailto:damir_poro...@live.com>) escribió:

Hi Folks,


I'm trying to write a shared library and run into an issue where I can't find 
any clues to where the problem is.

I have a project with following structure:


src/

dir1/

file1.h

file1.cpp

dir2/

file2.h

file2.cpp



Now I have this CMakeList:

cmake_minimum_required(VERSION 3.5)

project(kImageAnnotator VERSION 0.0.1 LANGUAGES CXX)


...


add_library(${PROJECT_NAME} SHARED ${kimageannotator_SRCS})
target_link_libraries(${PROJECT_NAME} Qt5::Widgets KF5::CoreAddons KF5::I18n 
KF5::WidgetsAddons)

target_include_directories(${PROJECT_NAME} PUBLIC 
$ $)

set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} 
SOVERSION 1)

set(kimageannotator_CONFIG ${PROJECT_NAME}Config)

install(TARGETS ${PROJECT_NAME} EXPORT ${kimageannotator_CONFIG}
ARCHIVE  DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY  DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME  DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION 
${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})

install(EXPORT ${kimageannotator_CONFIG} DESTINATION 
share/${kimageannotator_CONFIG}/cmake)

export(TARGETS ${PROJECT_NAME} FILE ${kimageannotator_CONFIG}.cmake)


In another test project, I add the library like this:
...
find_package(kImageAnnotator REQUIRED)

add_executable(testApp main.cpp)
target_link_libraries(testApp Qt5::Widgets kImageAnnotator)


Now when I try to build my test project, I get this:

dporobic@linux ~/projects/testApp/build
$ cmake .. && make
-- Could not set up the appstream test. appstreamcli is missing.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dporobic/projects/testApp/build
[ 25%] Automatic moc for target testApp
[ 25%] Built target testApp_automoc
Scanning dependencies of target testApp
[ 50%] Building CXX object CMakeFiles/testApp.dir/main.cpp.o
[ 75%] Building CXX object CMakeFiles/testApp.dir/testApp_automoc.cpp.o
[100%] Linking CXX executable testApp
CMakeFiles/testApp.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x8e): undefined reference to 
`KImageAnnotator::KImageAnnotator(QPixmap const&)'
collect2: error: ld returned 1 exit status
CMakeFiles/testApp.dir/build.make:120: recipe for target 'testApp' failed
make[2]: *** [testApp] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/testApp.dir/all' failed
make[1]: *** [CMakeFiles/testApp.dir/all] Error 2
Makefile:94: recipe for target 'all' failed
make: *** [all] Error 2

Any idea how I could/should troubleshoot such issue?

Thanks in advance!

Regards,
Damir



--

Powered by www.

Re: [CMake] Problem with creating shared library

2018-08-15 Thread Sebastián Mancilla
You are mixing the config file and the targets file.

The config file is a template that you normally put in cmake/
FooConfig.cmake.in

You copy the template into the binary dir:

include(CMakePackageConfigHelpers)

set(INSTALL_CONFIGDIR lib/cmake/Foo)

configure_package_config_file(
  "${CMAKE_CURRENT_LIST_DIR}/cmake/FooConfig.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake"
  INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)

It is a good idea to create a version file:

write_basic_package_version_file(
  "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake"
  VERSION ${PROJECT_VERSION}
  COMPATIBILITY SameMajorVersion
   )

And then install both:

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake"
  DESTINATION ${INSTALL_CONFIGDIR}
  COMPONENT Devel
)

For the targets is a different file. When you install the library you
should use

install(TARGETS Foo EXPORT FooTargets ...)

And then export and install the targets:

# Into the build tree
export(EXPORT FooTargets
  FILE "${CMAKE_CURRENT_BINARY_DIR}/FooTargets.cmake"
  NAMESPACE Foo::
)

# Into PREFIX
install(EXPORT FooTargets
  FILE FooTargets.cmake
  NAMESPACE Foo::
  DESTINATION ${INSTALL_CONFIGDIR}
  COMPONENT Devel
)

Finally, your template FooConfig.cmake.in should look like this:

  include(CMakeFindDependencyMacro)

  @PACKAGE_INIT@

  # list your required dependencies here
  find_dependency(Threads)

  if(NOT TARGET Foo::Foo)
include("${CMAKE_CURRENT_LIST_DIR}/FooTargets.cmake")
  endif()

All this is pretty much the same for any project. Here are the best links
explaining it:

https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
http://unclejimbo.github.io/2018/06/08/Modern-CMake-for-Library-Developers/




El mié., 15 de ago. de 2018 a la(s) 05:32, Damir Porobic (
damir_poro...@live.com) escribió:

> Hi Folks,
>
>
> I'm trying to write a shared library and run into an issue where I can't
> find any clues to where the problem is.
>
> I have a project with following structure:
>
>
> src/
>
> dir1/
>
> file1.h
>
> file1.cpp
>
> dir2/
>
> file2.h
> file2.cpp
>
>
>
> Now I have this CMakeList:
>
> cmake_minimum_required(VERSION 3.5)
>
> project(kImageAnnotator VERSION 0.0.1 LANGUAGES CXX)
>
> ...
>
>
> add_library(${PROJECT_NAME} SHARED ${kimageannotator_SRCS})
> target_link_libraries(${PROJECT_NAME} Qt5::Widgets KF5::CoreAddons
> KF5::I18n KF5::WidgetsAddons)
>
> target_include_directories(${PROJECT_NAME} PUBLIC
> $ $)
>
> set_target_properties(${PROJECT_NAME} PROPERTIES VERSION
> ${PROJECT_VERSION} SOVERSION 1)
>
> set(kimageannotator_CONFIG ${PROJECT_NAME}Config)
>
> install(TARGETS ${PROJECT_NAME} EXPORT ${kimageannotator_CONFIG}
> ARCHIVE  DESTINATION ${CMAKE_INSTALL_LIBDIR}
> LIBRARY  DESTINATION ${CMAKE_INSTALL_LIBDIR}
> RUNTIME  DESTINATION ${CMAKE_INSTALL_BINDIR})
> install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION
> ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
>
> install(EXPORT ${kimageannotator_CONFIG} DESTINATION
> share/${kimageannotator_CONFIG}/cmake)
>
> export(TARGETS ${PROJECT_NAME} FILE ${kimageannotator_CONFIG}.cmake)
>
>
> In another test project, I add the library like this:
> ...
> find_package(kImageAnnotator REQUIRED)
>
> add_executable(testApp main.cpp)
> target_link_libraries(testApp Qt5::Widgets kImageAnnotator)
>
>
> Now when I try to build my test project, I get this:
>
> dporobic@linux ~/projects/testApp/build
> $ cmake .. && make
> -- Could not set up the appstream test. appstreamcli is missing.
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /home/dporobic/projects/testApp/build
> [ 25%] Automatic moc for target testApp
> [ 25%] Built target testApp_automoc
> Scanning dependencies of target testApp
> [ 50%] Building CXX object CMakeFiles/testApp.dir/main.cpp.o
> [ 75%] Building CXX object CMakeFiles/testApp.dir/testApp_automoc.cpp.o
> [100%] Linking CXX executable testApp
> CMakeFiles/testApp.dir/main.cpp.o: In function `main':
> main.cpp:(.text+0x8e): undefined reference to
> `KImageAnnotator::KImageAnnotator(QPixmap const&)'
> collect2: error: ld returned 1 exit status
> CMakeFiles/testApp.dir/build.make:120: recipe for target 'testApp' failed
> make[2]: *** [testApp] Error 1
> CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/testApp.dir/all'
> failed
> make[1]: *** [CMakeFiles/testApp.dir/all] Error 2
> Makefile:94: recipe for target 'all' failed
> make: *** [all] Error 2
>
> Any idea how I could/should troubleshoot such issue?
>
> Thanks in advance!
>
> Regards,
> Damir
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> 

Re: [CMake] Problem with creating shared library

2018-08-15 Thread Eric Noulard
Le mer. 15 août 2018 à 10:32, Damir Porobic  a
écrit :

> Hi Folks,
>
>
> I'm trying to write a shared library and run into an issue where I can't
> find any clues to where the problem is.
>
> I have a project with following structure:
>
>
> src/
>
> dir1/
>
> file1.h
>
> file1.cpp
>
> dir2/
>
> file2.h
> file2.cpp
>
>
>
> Now I have this CMakeList:
>
> cmake_minimum_required(VERSION 3.5)
>
> project(kImageAnnotator VERSION 0.0.1 LANGUAGES CXX)
>
> ...
>
>
> add_library(${PROJECT_NAME} SHARED ${kimageannotator_SRCS})
> target_link_libraries(${PROJECT_NAME} Qt5::Widgets KF5::CoreAddons
> KF5::I18n KF5::WidgetsAddons)
>
> target_include_directories(${PROJECT_NAME} PUBLIC
> $ $)
>
> set_target_properties(${PROJECT_NAME} PROPERTIES VERSION
> ${PROJECT_VERSION} SOVERSION 1)
>
> set(kimageannotator_CONFIG ${PROJECT_NAME}Config)
>
> install(TARGETS ${PROJECT_NAME} EXPORT ${kimageannotator_CONFIG}
> ARCHIVE  DESTINATION ${CMAKE_INSTALL_LIBDIR}
> LIBRARY  DESTINATION ${CMAKE_INSTALL_LIBDIR}
> RUNTIME  DESTINATION ${CMAKE_INSTALL_BINDIR})
> install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION
> ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
>
> install(EXPORT ${kimageannotator_CONFIG} DESTINATION
> share/${kimageannotator_CONFIG}/cmake)
>
> export(TARGETS ${PROJECT_NAME} FILE ${kimageannotator_CONFIG}.cmake)
>
>
> In another test project, I add the library like this:
> ...
> find_package(kImageAnnotator REQUIRED)
>
> add_executable(testApp main.cpp)
> target_link_libraries(testApp Qt5::Widgets kImageAnnotator)
>
>
> Now when I try to build my test project, I get this:
>
> dporobic@linux ~/projects/testApp/build
> $ cmake .. && make
> -- Could not set up the appstream test. appstreamcli is missing.
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /home/dporobic/projects/testApp/build
> [ 25%] Automatic moc for target testApp
> [ 25%] Built target testApp_automoc
> Scanning dependencies of target testApp
> [ 50%] Building CXX object CMakeFiles/testApp.dir/main.cpp.o
> [ 75%] Building CXX object CMakeFiles/testApp.dir/testApp_automoc.cpp.o
> [100%] Linking CXX executable testApp
> CMakeFiles/testApp.dir/main.cpp.o: In function `main':
> main.cpp:(.text+0x8e): undefined reference to
> `KImageAnnotator::KImageAnnotator(QPixmap const&)'
> collect2: error: ld returned 1 exit status
> CMakeFiles/testApp.dir/build.make:120: recipe for target 'testApp' failed
> make[2]: *** [testApp] Error 1
> CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/testApp.dir/all'
> failed
> make[1]: *** [CMakeFiles/testApp.dir/all] Error 2
> Makefile:94: recipe for target 'all' failed
> make: *** [all] Error 2
>
> Any idea how I could/should troubleshoot such issue?
>

Try to compile in verbose mode

make VERBOSE=1

and have a look at the culprit link line.
You should see the reference to your previously built shared lib.

Check whether this lib is where it should be (may be you didn't install it?)

then check which kImageAnnotatorConfig.cmake file is used by the testApp
project in order to see if any
[wrong and not up to date] test & trial version of this file is lying
around.


-- 
Eric
-- 

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