target_link_libraries erroneously pulls in MODULE library at link time - module

I have two C++ projects using CMake 3.12.2.
The first one is MODULE library (a dynamically loaded plugin). It installs a DLL, a header file and the configuration file for CMake.
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(MyPlugin LANGUAGES CXX)
set(CMAKE_DEBUG_POSTFIX "d")
# MODULE libraries are dynamically loaded at runtime and never linked against
add_library(MyPlugin MODULE
include/a.h
src/a.cpp
src/b.h
src/b.cpp
)
target_include_directories(MyPlugin
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/MyPlugin>
PRIVATE
src
)
install(TARGETS MyPlugin EXPORT MyPluginConfig
# MODULE libraries are installed as LIBRARY
LIBRARY DESTINATION plugins COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime
PUBLIC_HEADER DESTINATION include/MyPlugin COMPONENT Development
)
install(FILES $<TARGET_PDB_FILE:MyPlugin> DESTINATION plugins OPTIONAL COMPONENT Runtime)
install(
DIRECTORY include/
DESTINATION include/MyPlugin
FILES_MATCHING PATTERN "*.h"
)
install(EXPORT MyPluginConfig
NAMESPACE MyPlugin::
DESTINATION lib/cmake/MyPlugin
)
The second one is a simple executable which pulls in the header file of the plugin via target_link_libraries (the modern CMake way).
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(MyExe LANGUAGES CXX)
set(CMAKE_DEBUG_POSTFIX "d")
find_package(MyPlugin REQUIRED)
add_executable(MyExe src/main.cpp)
target_link_libraries(MyExe MyPlugin::MyPlugin)
Using the vs2015 generated solution the link fails because the plugin DLL is fed during the link of the executable...
Has anyone a solution for this or should I file a bug?
Regards.

A solution to this issue is to split the library in two: an interface library which only provides the headers and a module library which does not export any header.
The module library CMakeLists.txt becomes:
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(MyPlugin LANGUAGES CXX)
set(CMAKE_DEBUG_POSTFIX "d")
# Move public headers to a dedicated INTERFACE library
add_library(MyPluginInterface INTERFACE)
add_custom_target(Includes SOURCES include/a.h)
target_include_directories(MyPluginInterfacecmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(MyPlugin LANGUAGES CXX)
set(CMAKE_DEBUG_POSTFIX "d")
# Move public headers to a dedicated INTERFACE library
add_library(MyPluginInterface INTERFACE)
add_custom_target(Includes SOURCES include/a.h)
target_include_directories(MyPluginInterface
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/MyPlugin>
)
install(TARGETS MyPluginInterface EXPORT MyPluginConfig
PUBLIC_HEADER DESTINATION include/MyPlugin COMPONENT Development
)
# MODULE libraries are dynamically loaded at runtime and never linked against
add_library(MyPlugin MODULE
src/a.cpp
src/b.h
src/b.cpp
)
target_link_libraries(MyPlugin MyPluginInterface)
install(TARGETS MyPlugin
# MODULE libraries are installed as LIBRARY
LIBRARY DESTINATION plugins COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime
)
install(FILES $<TARGET_PDB_FILE:MyPlugin> DESTINATION plugins OPTIONAL COMPONENT Runtime)
install(
DIRECTORY include/
DESTINATION include/MyPlugin
FILES_MATCHING PATTERN "*.h"
)
install(EXPORT MyPluginConfig
NAMESPACE MyPlugin::
DESTINATION lib/cmake/MyPlugin
)
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/MyPlugin>
)
install(TARGETS MyPluginInterface EXPORT MyPluginConfig
PUBLIC_HEADER DESTINATION include/MyPlugin COMPONENT Development
)
# MODULE libraries are dynamically loaded at runtime and never linked against
add_library(MyPlugin MODULE
src/a.cpp
src/b.h
src/b.cpp
)
target_link_libraries(MyPlugin MyPluginInterface)
install(TARGETS MyPlugin
# MODULE libraries are installed as LIBRARY
LIBRARY DESTINATION plugins COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime
)
install(FILES $<TARGET_PDB_FILE:MyPlugin> DESTINATION plugins OPTIONAL COMPONENT Runtime)
install(
DIRECTORY include/
DESTINATION include/MyPlugin
FILES_MATCHING PATTERN "*.h"
)
install(EXPORT MyPluginConfig
NAMESPACE MyPlugin::
DESTINATION lib/cmake/MyPlugin
)
The executable CMakeLists.txt becomes:
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(MyExe LANGUAGES CXX)
set(CMAKE_DEBUG_POSTFIX "d")
find_package(MyPlugin REQUIRED)
add_executable(MyExe src/main.cpp)
target_link_libraries(MyExe MyPlugin::MyPluginInterface)

Related

CMake/CPack is inserting dynamic links instead of regular files for external shared libraries

I need to use an specific external shared library on a project. It links fine, and locally it runs like a charm.
The problem is when I need to make a distribution package. When I run cpack the output file has the symbolic links to these external shared libraries. I need it to include the external libraries as well (not just the symbolic link). How can I do it?
Here is my CMakeLists.txt
project(test VERSION 1.0.0 LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 11)
set(Protobuf_LIBRARIES $ENV{CONDA_PREFIX}/lib/libprotobuf.so)
add_executable(test main.cpp)
target_link_libraries(test
${Protobuf_LIBRARIES}
)
include(GNUInstallDirs)
install(TARGETS test
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(FILES ${Protobuf_LIBRARIES}
DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries
)
set(CPACK_PACKAGE_NAME "Test")
include(CPack)
=== EDIT ===
Following #alex-reinking suggestion, and for the sake of completition on this question, here is the CMakeLists.txt working. It still has a problem with dependencies pointing to local dynamic libraries, so I needed to use an external app to solve that on OSX ( https://github.com/auriamg/macdylibbundler/ ). Be aware that, on this example, I'm including a Linux library.
project(test VERSION 1.0.0 LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 11)
set(Protobuf_LIBRARIES $ENV{CONDA_PREFIX}/lib/libprotobuf.so)
add_executable(test main.cpp)
target_link_libraries(test
${Protobuf_LIBRARIES}
)
include(GNUInstallDirs)
install(TARGETS test
RUNTIME_DEPENDENCY_SET A-dependency
)
install(RUNTIME_DEPENDENCY_SET A-dependency PRE_EXCLUDE_REGEXES )
install(FILES ${MYLIB_LOCATION} DESTINATION ${CMAKE_INSTALL_LIBDIR})
set(CPACK_PACKAGE_NAME "Test")
include(CPack)```

How to create cmake project with components

Im trying to create project in Cmake which contains components.
So another project can use this project using:
find_package(ltk COMPONENTS Core Networking REQUIRED)
target_link_libraries(test ltk::Core ltk::Networking)
My library project (called ltk)
Here is a project tree:
ltk/
|--- CMakeLists.txt
|--- ltkConfig.cmake.in
|--- ltkConfigVersion.cmake.in
|
+--- Core/
| |--- core.cc
| |--- core.h
| |--- CMakeLists.txt
|
+--- Networking/
|--- networking.cc
|--- networking.h
|--- CMakeLists.txt
Full project is here: https://gitlab.com/T0maas/cmake-testing
The file ltk/CMakeLists.txt has this content:
set(project ltk)
set(LTK_VERSION 0.0.1)
cmake_minimum_required(VERSION 3.21)
project(${project})
add_subdirectory(Core)
add_subdirectory(Networking)
foreach(p LIB BIN INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
endforeach()
export(TARGETS Core Networking FILE "${PROJECT_BINARY_DIR}/ltkTargets.cmake")
export(PACKAGE ltk)
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
configure_file(ltkConfig.cmake.in "${PROJECT_BINARY_DIR}/ltkConfig.cmake" #ONLY)
set(CONF_INCLUDE_DIRS "\${LTK_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(ltkConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ltkConfig.cmake" #ONLY)
configure_file(ltkConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/ltkConfigVersion.cmake" #ONLY)
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ltkConfig.cmake"
"${PROJECT_BINARY_DIR}/ltkConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/${project}" )
install(EXPORT ltkTargets DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/${project}" )
And the Core/CMakeLists.txt contains this:
set (component Core)
add_library(${component} SHARED core.cc )
add_library(${project}::${component} ALIAS ${component})
set_target_properties(${component} PROPERTIES PUBLIC_HEADER "core.h")
install(TARGETS ${component}
EXPORT ltkTargets
COMPONENT ${component}
LIBRARY DESTINATION lib/ltk
ARCHIVE DESTINATION lib/ltk
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include/ltk/
)
The Networking/CMakeLists.txt is similar to Core/CMakeLists.txt
File ltkConfig.cmake.in contains this:
get_filename_component(LTK_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(LTK_INCLUDE_DIRS "#CONF_INCLUDE_DIRS#")
if(NOT TARGET Core AND NOT LTK_BINARY_DIR)
include("${LTK_CMAKE_DIR}/ltkTargets.cmake")
endif()
if(NOT TARGET Networking AND NOT LTK_BINARY_DIR)
include("${LTK_CMAKE_DIR}/ltkTargets.cmake")
endif()
set(LTK_LIBRARIES Core Networking)
And the ltkConfigVersion.cmake.in:
set(PACKAGE_VERSION "#LTK_VERSION#")
# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
After install this project I see some files in /usr/lib/cmake/ltk:
ltkTargets-noconfig.cmake
ltkTargets.cmake
ltkConfigVersion.cmake
ltkConfig.cmake
Testing
But now when I try to configure some testing project, which has following CMakeLists.txt:
cmake_minimum_required(VERSION 3.21)
project(test)
find_package(ltk COMPONENTS Core REQUIRED)
add_executable(main main.cc)
target_link_libraries(main ltk::Core)
It shows following errors:
-- Configuring done
CMake Error at CMakeLists.txt:4 (add_executable):
Target "main" links to target "ltk::Core" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
-- Generating done
I've read following links, but this doesn't helped me:
https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-to-create-a-ProjectConfig.cmake-file
How to configure project with COMPONENTS in cmake
Edit
Now I added NAMESPACE ltk:: to install(EXPORT) in ltk/CMakeLists.txt:
install(EXPORT ltkTargets DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/${project}" NAMESPACE ltk::)
But the testing project which contains #include <core.h> complains:
fatal error: core.h: No such file or directory
Path to /usr/include/ltk has not been exported.
Edit 2
Fixed include problems with:
Added to {Core, Networking}/CMakeLists.txt
target_include_directories(${component} PUBLIC $<INSTALL_INTERFACE:include/ltk>)
Now I can use in my testing project this:
target_include_directories(main PUBLIC ltk)

How to export CMake targets with dependant include directories?

I am trying to export CMake targets such that they also include the public include directories of dependant targets.
Let there be three separate but depending CMake projects:
foobar_result defines a data type and methods for this datatype in result.hpp
foobar_interface defines a header-only abstract class in foobar_interface.hpp which uses the datatype defined in foobar_result (#include <result.hpp>)
foobar_implA is an implementation (foobar_implA.cpp, foobar_implA.hpp) of the abstract class in foobar_interface (#include <foobar_interface.hpp>), and hence indirectly depends on the datatype definition (it #include <result.hpp> via #include <foobar_interface.hpp>)
What I want to achieve is that when foobar_implA is find_package(foobar_interface), it should automatically populate the include directories and libraries with the dependencies of foobar_interface so that foobar_implA does not have to discover foobar_result's include directories manually.
So far, I tried to specify the three CMake projects as follows.
1. foobar_result
foobar_result defines a standard library with headers:
cmake_minimum_required(VERSION 3.5)
project(foobar_result)
include(GNUInstallDirs)
add_library(result SHARED src/result.cpp)
target_include_directories(result PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>
)
install(EXPORT ${PROJECT_NAME}
DESTINATION share/${PROJECT_NAME}/cmake
FILE ${PROJECT_NAME}Config.cmake
)
install(TARGETS result EXPORT ${PROJECT_NAME})
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
)
The exported foobar_resultConfig.cmake:
add_library(result SHARED IMPORTED)
set_target_properties(result PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
)
and foobar_resultConfig-noconfig.cmake:
set_target_properties(result PROPERTIES
IMPORTED_LOCATION_NOCONFIG "${_IMPORT_PREFIX}/lib/libresult.so"
IMPORTED_SONAME_NOCONFIG "libresult.so"
)
correctly define the includes and libraries.
2. foobar_interface
The interface uses the result library:
cmake_minimum_required(VERSION 3.5)
project(foobar_interface)
include(GNUInstallDirs)
find_package(foobar_result REQUIRED)
add_library(foobar_interface INTERFACE)
target_link_libraries(foobar_interface INTERFACE result)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>
)
install(EXPORT ${PROJECT_NAME}
DESTINATION share/${PROJECT_NAME}/cmake
FILE ${PROJECT_NAME}Config.cmake
)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
)
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME})
Now, although the interface foobar_interface links the result library, the exported configuration:
add_library(foobar_interface INTERFACE IMPORTED)
set_target_properties(foobar_interface PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "result"
)
only depends on the result library, but not its include directories. foobar_interface only exports its own INTERFACE_INCLUDE_DIRECTORIES, but not those of its dependency foobar_result.
3. foobar_implA
The implementation of the interface depends only on foobar_implA:
cmake_minimum_required(VERSION 3.5)
project(foobar_implA)
include(GNUInstallDirs)
find_package(foobar_interface REQUIRED)
add_library(foobar_implA SHARED src/foobar_implA.cpp)
target_link_libraries(foobar_implA PUBLIC foobar_interface)
target_include_directories(foobar_implA PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>
)
install(EXPORT ${PROJECT_NAME}
DESTINATION share/${PROJECT_NAME}/cmake
FILE ${PROJECT_NAME}Config.cmake
)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
)
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME})
fails with:
In file included from [...]/src/foobar_implA/include/foobar_implA.hpp:3,
from [...]/src/foobar_implA/src/foobar_implA.cpp:1:
[...]/install/foobar_interface/include/foobar_interface.hpp:3:10: fatal error: result.hpp: No such file or directory
3 | #include <result.hpp>
| ^~~~~~~~~~~~
because find_package(foobar_interface) will not populate the include directories with the one defined in foobar_result.
I can only work around this issue by manually including foobar_result again:
find_package(foobar_result REQUIRED)
target_link_libraries(foobar_implA PUBLIC result)
but this is obviously not what I want, as this would not scale well when the dependencies in foobar_interface increase.
I am using colcon to separate the build and install spaces for all three projects. This way, all projects have to properly export and import their include and link directories. Installing all projects in the same prefix would also circumvent this problem, as foobar_interface include directories would also contain headers from foobar_result.

Cannot specify compile options for imported target "..."

I want to provide the users of my library with two targets: one that specifies the include path etc., and one that carries useful extra compile options. However, for the extra target some of my users are getting the error
Cannot specify compile options for imported target "myproject::extra"
so it seems on older CMake versions.
I tested with CMake 3.9.2. The test project, including CI is on GitHub, with failing build here.
(How) can my approach be rendered robust for all CMake versions?
The project's main CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(myproject)
add_library(myproject INTERFACE)
set(MYPROJECT_VERSION "1.0.0")
target_include_directories(myproject INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION include)
install(TARGETS myproject EXPORT myproject-targets)
install(EXPORT myproject-targets FILE myprojectTargets.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/myproject")
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/myprojectConfigVersion.cmake" VERSION ${MYPROJECT_VERSION} COMPATIBILITY AnyNewerVersion)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/myprojectConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/myprojectConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/myproject")
The project's myprojectConfig.cmake:
include(CMakeFindDependencyMacro)
if(NOT TARGET myproject)
include("${CMAKE_CURRENT_LIST_DIR}/myprojectTargets.cmake")
endif()
if(NOT TARGET myproject::extra)
add_library(myproject::extra INTERFACE IMPORTED)
if(MSVC)
target_compile_options(myproject::extra INTERFACE /W4)
else()
target_compile_options(myproject::extra INTERFACE -Wall)
endif()
endif()
The user's project CMakeLists.txt could then look as follows:
cmake_minimum_required(VERSION 3.0)
project(myexec)
find_package(myproject REQUIRED)
add_executable(myexec main.cpp)
target_link_libraries(myexec PRIVATE myproject myproject::extra)
List of functions applicable for IMPORTED and INTERFACE targets changes as CMake evolves.
Most of such functions affects only on specific target properties. So, instead of calling a function, you may set the property directly. This will work in any CMake version:
# Works only in new CMake versions
target_compile_options(myproject::extra INTERFACE /W4)
# Equivalent which works in any CMake version
set_property(TARGET myproject::extra PROPERTY INTERFACE_COMPILE_OPTIONS /W4)

Cannot find good include directory and lib in my project after find_package

I'm building my own library using this CMakeLists.txt :
PROJECT (AstroLib)
cmake_minimum_required(VERSION 3.0)
set(AALib_VERSION_MAJOR 1 CACHE STRING "major version" FORCE)
set(AALib_VERSION_MINOR 95 CACHE STRING "minor version" FORCE)
set(AALib_VERSION ${AALib_VERSION_MAJOR}.${AALib_VERSION_MINOR} CACHE STRING "version" FORCE)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
include(GenerateExportHeader)
file(GLOB AALib_SRCS "AALIb/source/*.cpp")
file(GLOB AALib_Headers "AALIb/include/*.h" "AALIb/include/*.hpp")
message ("AALib_VERSION ${AALib_VERSION}")
message ("CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}")
message ("CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}")
add_library (AALib STATIC ${AALib_SRCS})
target_include_directories(AALib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/AALib/include>
$<INSTALL_INTERFACE:include>
PRIVATE AALib/source)
generate_export_header( AALib )
set_property(TARGET AALib PROPERTY VERSION ${AALib_VERSION})
install(TARGETS AALib EXPORT AALibConfig
LIBRARY DESTINATION "lib/${CMAKE_BUILD_TYPE}"
ARCHIVE DESTINATION "lib/${CMAKE_BUILD_TYPE}"
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/AALib_export.h" DESTINATION include COMPONENT Devel)
install(FILES ${AALib_Headers} DESTINATION include)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/AALib/AALibConfigVersion.cmake"
VERSION ${AALib_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(TARGETS AALib
FILE "${CMAKE_CURRENT_BINARY_DIR}/AALib/AALibConfig.cmake"
NAMESPACE Upstream::
)
install(EXPORT AALibConfig DESTINATION AALib/cmake)
set(FOO "rtatzera")
#configure_file(AALibTargets.cmake "${CMAKE_CURRENT_BINARY_DIR}/AALib/AALibConfig.cmake" COPYONLY)
set(ConfigPackageLocation lib/cmake/AALib)
message ("ConfigPackageLocation ${ConfigPackageLocation}")
install(EXPORT AALibConfig
FILE
AALibConfig.cmake
NAMESPACE
Upstream::
DESTINATION
${ConfigPackageLocation}
)
I run cmake-gui with this cmakelists.txt and I can build and install my library on my computer.
Now I want to use this lib in another project using this cmakelists.txt :
cmake_minimum_required(VERSION 3.0)
PROJECT (DataMeteo)
find_package(OpenCV REQUIRED)
find_package(AALib REQUIRED)
file(GLOB DataMeteo_SRCS
"*.h"
"*.cpp")
ADD_EXECUTABLE (DataMeteo ${DataMeteo_SRCS})
message ( "AALib = ${AAlib}")
if (OpenCV_FOUND AND AALib_FOUND)
target_link_libraries( DataMeteo PUBLIC ${AALIb_} ${OpenCV_LIBS})
else (OpenCV_FOUND AND AALib_FOUND)
message("OPENC not found or AALib NOT FOUND ")
endif (OpenCV_FOUND AND AALib_FOUND)
In VS project I can find all opencv libs and include but I cannot find include and lib of my own Library. There is no error when I run cmake-gui.
Where is error(s) in my code (cmakelists.txt)?
Configuration Windows 10 64 bits VS2017 CMake 3.11.0