<div dir="ltr">You are mixing the config file and the targets file.<div><br></div><div>The config file is a template that you normally put in cmake/<a href="http://FooConfig.cmake.in">FooConfig.cmake.in</a></div><div><br></div><div>You copy the template into the binary dir:</div><div><br></div><div><div> include(CMakePackageConfigHelpers)</div><br class="gmail-Apple-interchange-newline"></div><div><div> set(INSTALL_CONFIGDIR lib/cmake/Foo)</div><br class="gmail-Apple-interchange-newline"></div><div><div> configure_package_config_file(</div><div> "${CMAKE_CURRENT_LIST_DIR}/cmake/<a href="http://FooConfig.cmake.in">FooConfig.cmake.in</a>"</div><div> "${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake"</div><div> INSTALL_DESTINATION ${INSTALL_CONFIGDIR}</div><div> )</div><div><br></div><div>It is a good idea to create a version file:</div><div><div> </div><div> write_basic_package_version_file(</div><div> "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake"</div><div> VERSION ${PROJECT_VERSION}</div><div> COMPATIBILITY SameMajorVersion</div><div> )</div></div><div><br></div><div>And then install both:</div><div><br></div><div><div> install(FILES</div><div> "${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake"</div><div> "${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake"</div><div> DESTINATION ${INSTALL_CONFIGDIR}</div><div> COMPONENT Devel</div><div> )</div></div><div><br></div><div>For the targets is a different file. When you install the library you should use</div><div><br></div><div> install(TARGETS Foo EXPORT FooTargets ...)</div><div><br></div><div>And then export and install the targets:<br></div></div><div><br></div><div> # Into the build tree</div><div><div> export(EXPORT FooTargets</div><div> FILE "${CMAKE_CURRENT_BINARY_DIR}/FooTargets.cmake"</div><div> NAMESPACE Foo::</div><div> )</div><div> </div><div> # Into PREFIX</div><div> install(EXPORT FooTargets</div><div> FILE FooTargets.cmake</div><div> NAMESPACE Foo::</div><div> DESTINATION ${INSTALL_CONFIGDIR}</div><div> COMPONENT Devel</div><div> )</div></div><div><br></div><div>Finally, your template <a href="http://FooConfig.cmake.in">FooConfig.cmake.in</a> should look like this:</div><div><br></div><div><div> include(CMakeFindDependencyMacro)</div><div><br></div><div> @PACKAGE_INIT@</div><div> </div><div> # list your required dependencies here</div><div> find_dependency(Threads)</div><div><br></div><div> if(NOT TARGET Foo::Foo)</div><div> include("${CMAKE_CURRENT_LIST_DIR}/FooTargets.cmake")</div><div> endif()</div></div><div><br></div><div>All this is pretty much the same for any project. Here are the best links explaining it:</div><div><br></div><div><a href="https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/">https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/</a><br></div><div><a href="http://unclejimbo.github.io/2018/06/08/Modern-CMake-for-Library-Developers/">http://unclejimbo.github.io/2018/06/08/Modern-CMake-for-Library-Developers/</a><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">El mié., 15 de ago. de 2018 a la(s) 05:32, Damir Porobic (<a href="mailto:damir_porobic@live.com">damir_porobic@live.com</a>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div id="m_-5021389302390682568divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif,"EmojiFont","Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p style="margin-top:0;margin-bottom:0">Hi Folks,</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">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.
<br>
<br>
I have a project with following structure:</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Consolas,Courier,monospace">src/</span></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Consolas,Courier,monospace"> dir1/</span></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Consolas,Courier,monospace"> file1.h</span><br>
<span style="font-family:Consolas,Courier,monospace"></span></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Consolas,Courier,monospace"> file1.cpp</span></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<p style="margin-top:0;margin-bottom:0"><span></span></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Consolas,Courier,monospace"> dir2/</span></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Consolas,Courier,monospace"> file2.h</span><br>
<span style="font-family:Consolas,Courier,monospace"></span></p>
<span style="font-family:Consolas,Courier,monospace"></span><span style="font-family:Consolas,Courier,monospace"> file2.cpp</span>
<p></p>
<p style="margin-top:0;margin-bottom:0"><span><span><br>
</span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span><br>
</span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span>Now I have this CMakeList:</span></span></p>
<p style="margin-top:0;margin-bottom:0"><span><span></span></span></p>
<div><span style="font-family:Consolas,Courier,monospace">cmake_minimum_required(VERSION 3.5)</span><br>
<span style="font-family:Consolas,Courier,monospace"></span><br>
<span style="font-family:Consolas,Courier,monospace">project(kImageAnnotator VERSION 0.0.1 LANGUAGES CXX)</span></div>
<span style="font-family:Consolas,Courier,monospace"></span><br>
<span style="font-family:Consolas,Courier,monospace"></span>
<p></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<p style="margin-top:0;margin-bottom:0"><span><span><span style="font-family:Consolas,Courier,monospace">...</span><br>
<span style="font-family:Consolas,Courier,monospace"></span></span></span></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<p style="margin-top:0;margin-bottom:0"><span><span style="font-family:Consolas,Courier,monospace"><br>
</span></span></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<p style="margin-top:0;margin-bottom:0"><span><span></span></span></p>
<span style="font-family:Consolas,Courier,monospace"></span>
<div><span style="font-family:Consolas,Courier,monospace">add_library(${PROJECT_NAME} SHARED ${kimageannotator_SRCS})</span><br>
<span style="font-family:Consolas,Courier,monospace">target_link_libraries(${PROJECT_NAME} Qt5::Widgets KF5::CoreAddons KF5::I18n KF5::WidgetsAddons)</span><br>
<span style="font-family:Consolas,Courier,monospace"></span><br>
<span style="font-family:Consolas,Courier,monospace">target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include>)</span><br>
<span style="font-family:Consolas,Courier,monospace"></span><br>
<span style="font-family:Consolas,Courier,monospace">set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 1)</span><br>
<span style="font-family:Consolas,Courier,monospace"></span><br>
<span style="font-family:Consolas,Courier,monospace">set(kimageannotator_CONFIG ${PROJECT_NAME}Config)</span><br>
<span style="font-family:Consolas,Courier,monospace"></span><br>
<span style="font-family:Consolas,Courier,monospace">install(TARGETS ${PROJECT_NAME} EXPORT ${kimageannotator_CONFIG}</span><br>
<span style="font-family:Consolas,Courier,monospace"> ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}</span><br>
<span style="font-family:Consolas,Courier,monospace"> LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}</span><br>
<span style="font-family:Consolas,Courier,monospace"> RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})</span><br>
<span style="font-family:Consolas,Courier,monospace">install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})</span><br>
<span style="font-family:Consolas,Courier,monospace"></span><br>
<span style="font-family:Consolas,Courier,monospace">install(EXPORT ${kimageannotator_CONFIG} DESTINATION share/${kimageannotator_CONFIG}/cmake)</span><br>
<span style="font-family:Consolas,Courier,monospace"></span><br>
<span style="font-family:Consolas,Courier,monospace">export(TARGETS ${PROJECT_NAME} FILE ${kimageannotator_CONFIG}.cmake)</span></div>
<div><span><span><br>
</span></span></div>
<div><span><span><br>
</span></span></div>
<div><span><span>In another test project, I add the library like this:</span></span></div>
<div><span><span><span style="font-family:Consolas,Courier,monospace">...</span><br>
<span style="font-family:Consolas,Courier,monospace"></span></span></span></div>
<span style="font-family:Consolas,Courier,monospace"></span>
<div><span><span><span style="font-family:Consolas,Courier,monospace"></span>
<div><span style="font-family:Consolas,Courier,monospace">find_package(kImageAnnotator REQUIRED)</span><br>
<span style="font-family:Consolas,Courier,monospace"></span><br>
<span style="font-family:Consolas,Courier,monospace">add_executable(testApp main.cpp)</span><br>
<span style="font-family:Consolas,Courier,monospace">target_link_libraries(testApp Qt5::Widgets kImageAnnotator)</span></div>
<div><span><span></span></span><br>
</div>
</span></span></div>
<div><br>
</div>
<div>Now when I try to build my test project, I get this:</div>
<div><br>
</div>
<div>
<div><span style="font-family:Consolas,Courier,monospace">dporobic@linux ~/projects/testApp/build</span><br>
<span style="font-family:Consolas,Courier,monospace">$ cmake .. && make</span><br>
<span style="font-family:Consolas,Courier,monospace">-- Could not set up the appstream test. appstreamcli is missing.</span><br>
<span style="font-family:Consolas,Courier,monospace">-- Configuring done</span><br>
<span style="font-family:Consolas,Courier,monospace">-- Generating done</span><br>
<span style="font-family:Consolas,Courier,monospace">-- Build files have been written to: /home/dporobic/projects/testApp/build</span><br>
<span style="font-family:Consolas,Courier,monospace">[ 25%] Automatic moc for target testApp</span><br>
<span style="font-family:Consolas,Courier,monospace">[ 25%] Built target testApp_automoc</span><br>
<span style="font-family:Consolas,Courier,monospace">Scanning dependencies of target testApp</span><br>
<span style="font-family:Consolas,Courier,monospace">[ 50%] Building CXX object CMakeFiles/testApp.dir/main.cpp.o</span><br>
<span style="font-family:Consolas,Courier,monospace">[ 75%] Building CXX object CMakeFiles/testApp.dir/testApp_automoc.cpp.o</span><br>
<span style="font-family:Consolas,Courier,monospace">[100%] Linking CXX executable testApp</span><br>
<span style="font-family:Consolas,Courier,monospace">CMakeFiles/testApp.dir/main.cpp.o: In function `main':</span><br>
<span style="font-family:Consolas,Courier,monospace">main.cpp:(.text+0x8e): undefined reference to `KImageAnnotator::KImageAnnotator(QPixmap const&)'</span><br>
<span style="font-family:Consolas,Courier,monospace">collect2: error: ld returned 1 exit status</span><br>
<span style="font-family:Consolas,Courier,monospace">CMakeFiles/testApp.dir/build.make:120: recipe for target 'testApp' failed</span><br>
<span style="font-family:Consolas,Courier,monospace">make[2]: *** [testApp] Error 1</span><br>
<span style="font-family:Consolas,Courier,monospace">CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/testApp.dir/all' failed</span><br>
<span style="font-family:Consolas,Courier,monospace">make[1]: *** [CMakeFiles/testApp.dir/all] Error 2</span><br>
<span style="font-family:Consolas,Courier,monospace">Makefile:94: recipe for target 'all' failed</span><br>
<span style="font-family:Consolas,Courier,monospace">make: *** [all] Error 2</span><br>
<br>
</div>
Any idea how I could/should troubleshoot such issue? <br>
</div>
<div><br>
</div>
<div>Thanks in advance!</div>
<div><br>
</div>
<div>Regards,</div>
<div>Damir<br>
</div>
<div><br>
</div>
<br>
<p></p>
</div>
</div>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cmake.org_Wiki_CMake-5FFAQ&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=JJ5RqPyjdlGGc3fT-5nQQM-JcJzwjBZU6ciOQlmEJVs&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cmake.org_Wiki_CMake-5FFAQ&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=JJ5RqPyjdlGGc3fT-5nQQM-JcJzwjBZU6ciOQlmEJVs&e=</a> <br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_support.html&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=vUHQvc_7Ovi_5BDjy3JYFOIvTmihTSFOQNndNSpMOnA&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_support.html&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=vUHQvc_7Ovi_5BDjy3JYFOIvTmihTSFOQNndNSpMOnA&e=</a> <br>
CMake Consulting: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_consulting.html&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=91AJA3BxTfHAvsi0mAzkszAyUUmE2xfwbLgN_fYvFO4&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_consulting.html&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=91AJA3BxTfHAvsi0mAzkszAyUUmE2xfwbLgN_fYvFO4&e=</a> <br>
CMake Training Courses: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_training.html&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=isQW6paMIqhUFaejOZ4qfUiSVwNiR1yxoQn4J91yb8o&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_training.html&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=isQW6paMIqhUFaejOZ4qfUiSVwNiR1yxoQn4J91yb8o&e=</a> <br>
<br>
Visit other Kitware open-source projects at <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com_opensource_opensource.html&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=ose8YVW10s6tWkujUCq162vyyipCdlw-MW93qUlqdGk&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com_opensource_opensource.html&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=ose8YVW10s6tWkujUCq162vyyipCdlw-MW93qUlqdGk&e=</a> <br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__cmake.org_mailman_listinfo_cmake&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=KftR51q4EGgNERicS2QyHvzlrNaqb11IUwwbz1YTjVU&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__cmake.org_mailman_listinfo_cmake&d=DwICAg&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=1H4kXxGuNG-DAo1qM-u8bdF6AKKHkJoiCuqwZ4QLvtY&s=KftR51q4EGgNERicS2QyHvzlrNaqb11IUwwbz1YTjVU&e=</a> <br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="font-size:small;font-family:arial">Sebastian Mancilla Matta</div><div style="font-size:small;font-family:arial">CCTVal, UTFSM</div><div style="font-size:small;font-family:arial">Valparaíso, Chile</div></div></div>