I've installed osgearth package with vcpkg with following command:
vcpkg.exe install osgearth:x64-windows
Now in a CMake I want to use it.
cmake_minimum_required (VERSION 3.10.0)
project (osgmap)
add_definitions (-DOSGMAP_EXPORTS)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
find_package (Osg REQUIRED)
find_package(OsgEarth REQUIRED)
set (PROJECT_SRC
Dummy.cpp
)
add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
target_link_libraries (${PROJECT_NAME} mapapi)
target_compile_features (${PROJECT_NAME} PUBLIC cxx_std_17)
The problem is that I cannot find osgearth package. I've tried different options.
How can I use OsgEarth installed with vcpkg in a CMake project?
The short answer is there are findosg* modules in the cmake distribution and there are not any osgEarth modules to automatically find package paths. Package is either a config or module definition locating both the libs and includes. Vcpkg does not seem to automate package definition and it relies on the modules installed with CMake. What is possible is using find_library and find_path to locate the osgearth files.
find_library(OSGEARTH_LIBRARY osgearth)
assuming you ran vcpkg integrate and use the -DCMAKE_TOOLCHAIN_FILE with cmake. All the libs that were built with vcpkg can be found but not all as packages.
Once you have properly set up the CMAKE_TOOLCHAIN_FILE you need to provide a FindOsgEarth.cmake file. You could use:
# This module defines
# OSGEARTH_LIBRARY
# OSGEARTH_FOUND, if false, do not try to link to osg
# OSGEARTH_INCLUDE_DIRS, where to find the headers
# OSGEARTH_INCLUDE_DIR, where to find the source headers
# to use this module, set variables to point to the osg build
# directory, and source directory, respectively
# OSGEARTHDIR or OSGEARTH_SOURCE_DIR: osg source directory, typically OpenSceneGraph
# OSGEARTH_DIR or OSGEARTH_BUILD_DIR: osg build directory, place in which you've
# built osg via cmake
###### headers ######
MACRO( FIND_OSGEARTH_INCLUDE THIS_OSGEARTH_INCLUDE_DIR THIS_OSGEARTH_INCLUDE_FILE )
FIND_PATH( ${THIS_OSGEARTH_INCLUDE_DIR} ${THIS_OSGEARTH_INCLUDE_FILE}
PATHS
${OSGEARTH_DIR}
$ENV{OSGEARTH_SOURCE_DIR}
$ENV{OSGEARTHDIR}
$ENV{OSGEARTH_DIR}
/usr/local/
/usr/
/sw/ # Fink
/opt/local/ # DarwinPorts
/opt/csw/ # Blastwave
/opt/
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSGEARTH_ROOT]/
~/Library/Frameworks
/Library/Frameworks
PATH_SUFFIXES
/include/
)
ENDMACRO( FIND_OSGEARTH_INCLUDE THIS_OSGEARTH_INCLUDE_DIR THIS_OSGEARTH_INCLUDE_FILE )
FIND_OSGEARTH_INCLUDE( OSGEARTH_INCLUDE_DIR osgEarth/Version )
###### libraries ######
MACRO( FIND_OSGEARTH_LIBRARY MYLIBRARY MYLIBRARYNAME )
FIND_LIBRARY(${MYLIBRARY}
NAMES
${MYLIBRARYNAME}
PATHS
${OSGEARTH_DIR}
$ENV{OSGEARTH_BUILD_DIR}
$ENV{OSGEARTH_DIR}
$ENV{OSGEARTHDIR}
$ENV{OSG_ROOT}
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSGEARTH_ROOT]/lib
/usr/freeware
PATH_SUFFIXES
/lib/
/lib64/
/build/lib/
/build/lib64/
/Build/lib/
/Build/lib64/
)
ENDMACRO(FIND_OSGEARTH_LIBRARY LIBRARY LIBRARYNAME)
FIND_OSGEARTH_LIBRARY( OSGEARTH_LIBRARY osgEarth)
FIND_OSGEARTH_LIBRARY( OSGEARTHFEATURES_LIBRARY osgEarthFeatures)
FIND_OSGEARTH_LIBRARY( OSGEARTHUTIL_LIBRARY osgEarthUtil )
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY osgEarthQt )
FIND_OSGEARTH_LIBRARY( OSGEARTHSYMBOLOGY_LIBRARY osgEarthSymbology )
FIND_OSGEARTH_LIBRARY( OSGEARTHANNOTATION_LIBRARY osgEarthAnnotation )
SET( OSGEARTH_FOUND "NO" )
IF( OSGEARTH_LIBRARY AND OSGEARTH_INCLUDE_DIR )
SET( OSGEARTH_FOUND "YES" )
SET( OSGEARTH_INCLUDE_DIRS ${OSGEARTH_INCLUDE_DIR})
GET_FILENAME_COMPONENT( OSGEARTH_LIBRARIES_DIR ${OSGEARTH_LIBRARY} PATH )
ENDIF( OSGEARTH_LIBRARY AND OSGEARTH_INCLUDE_DIR )
Then add it to your CMakeModules folder and in your CMakeLists.txt:
LIST(APPEND CMAKE_MODULE_PATH "${${PROJECT_NAME}_SOURCE_DIR}/CMakeModules")
FIND_PACKAGE(OsgEarth REQUIRED)
IF(OSGEARTH_FOUND)
MESSAGE(STATUS "OsgEarth found")
ELSE()
MESSAGE(STATUS "OsgEarth NOT found")
ENDIF()
INCLUDE_DIRECTORIES(${OSGEARTH_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OSGEARTH_LIBRARY} ${OSGEARTHFEATURES_LIBRARY}
${OSGEARTHUTIL_LIBRARY} ${OSGEARTHSYMBOLOGY_LIBRARY}
${OSGEARTHANNOTATION_LIBRARY} ...)
Related
Trying to package an application with Microsoft Visual Studio 2022 and qt6 libraries I do not no were to start from. I've done a bit of research most people used qt5 and when I replace the text with qt6 it doesn't seem to work. I used dependency walker to find the necessary libraries and I seem to have achieved a way to add the Visual Studio libraries but not qt and VTK.
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
foreach(p
CMP0071 # 3.10: Let AUTOMOC and AUTOUIC process GENERATED files
)
if(POLICY ${p})
cmake_policy(SET ${p} NEW)
endif()
endforeach()
PROJECT( QtVTKExample )
#set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
if (MSVC_VERSION EQUAL 1930 AND MSVC_TOOLSET_VERSION EQUAL 142)
cmake_host_system_information(RESULT VS_DIR QUERY VS_17_DIR)
file(GLOB MSVC_REDIST_LIBRARIES "${VS_DIR}/VC/Redist/MSVC/*/${MSVC_C_ARCHITECTURE_ID}/Microsoft.VC143.CRT/*.dll")
list(APPEND CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS "${MSVC_REDIST_LIBRARIES}")
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS TRUE)
endif()
include(InstallRequiredSystemLibraries)
# Add to top of file CPACK stuff
include(CTest)
if(WIN32)
set(CPACK_GENERATOR "NSIS")
else()
set(CPACK_GENERATOR "ZIP")
endif()
include(CPack)
find_package(VTK COMPONENTS
vtkCommonColor
vtkCommonCore
vtkCommonDataModel
vtkInteractionStyle
vtkRenderingContextOpenGL2
vtkRenderingCore
vtkRenderingFreeType
vtkRenderingGL2PSOpenGL2
vtkRenderingOpenGL2
QUIET
)
# The CMake build process might generate some new files in the current
# directory. This makes sure they can be found.
set( CMAKE_INCLUDE_CURRENT_DIR ON )
# This allows CMake to run one of Qt's build tools called moc
# if it is needed. moc.exe can be found in Qt's bin directory.
# We'll look at what moc does later.
set( CMAKE_AUTOMOC ON )
set( CMAKE_AUTOUIC ON )
# Find the Qt widgets package. This locates the relevant include and
# lib directories, and the necessary static libraries for linking.
find_package( Qt6Widgets )
set( UIS mainwindow.ui )
qt6_wrap_ui( UI_Srcs ${UIS} )
set( ICONS Icons/icons.qrc )
qt6_add_resources( QRC_Srcs ${ICONS} )
# Also link to VTK
find_package( VTK REQUIRED )
include( ${VTK_USE_FILE} )
# Define the executable output and its sources
add_executable( QtVTKExample MACOSX_BUNDLE
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
tabcontent.cpp
tabcontent.h
tabcontent.ui
currentstl.cpp
currentstl.h
recentstl.cpp
recentstl.h
${UI_Srcs}
${QRC_Srcs}
)
# Tell CMake that the executable depends on the Qt::Widget libraries.
target_link_libraries( QtVTKExample Qt6::Widgets )
# Tell CMake that the executable depends on the VTK libraries
target_link_libraries( QtVTKExample ${VTK_LIBRARIES} )
# /calc_cmake/CMakeLists.txt
install(TARGETS QtVTKExample
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
I would like to use Snap7 ( Multi-platform Ethernet S7 PLC communication suite) to establish a communication between ROS and a Siemens S7 1500.
I encountered a linker problem - Although I can find the includes and the library .so file itself, using a custom FindLibSnap7.cmake, target_link_libraries is not linking against snap7 library. Here my approach and the outputs helping debugging:
(Note: Currently we are forced to use ROS Kinetic, so using the Snap7 Python wrapper seems like not an option cause its written in python3.)
I installed the library:
sudo add-apt-repository ppa:gijzelaar/snap7
sudo apt-get update
sudo apt-get install libsnap71 libsnap7-dev
Result:
$ ll /usr/lib/libsnap7.so
-rwxr-xr-x 1 root root 305944 Apr 24 22:18 /usr/lib/libsnap7.so*
$ ll /usr/include/snap7.h
-rw-r--r-- 1 root root 41954 Jun 2 2015 /usr/include/snap7.h
FindLibSnap7.cmake:
# find libsnap7
#
# exports:
#
# LibSNAP7_FOUND
# LibSNAP7_INCLUDE_DIRS
# LibSNAP7_LIBRARIES
#
find_package(PkgConfig REQUIRED)
# Use pkg-config to get hints about paths
#pkg_check_modules(LibSNAP7_PKGCONF REQUIRED libsnap7)
# Include dir
find_path(LibSNAP7_INCLUDE_DIR
NAMES snap7.h
PATHS ${LibSNAP7_PKGCONF_INCLUDE_DIRS}
)
find_library(
LibSNAP7_LIBRARY
NAMES snap7 libsnap7
PATHS /usr/lib
# PATH_SUFFIXES lib
# NO_DEFAULT_PATH
)
#FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSNAP7 DEFAULT_MSG LibSNAP7_LIBRARY LibSNAP7_INCLUDE_DIR)
message("LibSNAP7_INCLUDE_DIR ${LibSNAP7_INCLUDE_DIR}")
message("LibSNAP7_LIBRARY ${LibSNAP7_LIBRARY}")
set(LibSnap7_LIBRARIES ${LibSNAP7_LIBRARY})
set(LibSnap7_INCLUDE_DIRS ${LibSNAP7_INCLUDE_DIR})
set(LibSnap7_FOUND yes)
# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
#set(LibSNAP7_PROCESS_INCLUDES LibSNAP7_INCLUDE_DIR)
#set(LibSNAP7_PROCESS_LIBS LibSNAP7_LIBRARY)
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(agv_snap7_driver)
set(CMAKE_VERBOSE_MAKEFILE ON)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
##########################################################################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
MESSAGE( STATUS "CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH} )
find_package(LibSnap7 REQUIRED)
include_directories(${LibSnap7_INCLUDE_DIRS})
message("LibSnap7_LIBRARIES ${LibSnap7_LIBRARIES}")
message("LibSnap7_INCLUDE_DIRS ${LibSnap7_INCLUDE_DIRS}")
##########################################################################################
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
nodelet
agv_utils
agv_msgs
)
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS ${THIS_PACKAGE_ROS_DEPS}
DEPENDS LibSnap7
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
${LibSnap7_INCLUDE_DIRS}
)
## Declare a C++ library
add_library(${PROJECT_NAME}
src/agv_snap7_driver_config.cpp
src/agv_snap7_driver.cpp
)
## Add cmake target dependencies of the executable
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
target_link_libraries( ${PROJECT_NAME} ${catkin_LIBRARIES} ${LibSnap7_LIBRARIES})
#############
## Install ##
#############
## Mark libraries for installation
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
## Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
install(FILES nodelet.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
install(DIRECTORY launch/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
FILES_MATCHING PATTERN "*.launch"
PATTERN ".svn" EXCLUDE
)
install(DIRECTORY config/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config
FILES_MATCHING PATTERN "*.yaml"
PATTERN ".svn" EXCLUDE
)
catkin_make output:
-- +++ processing catkin package: 'agv_snap7_driver'
-- ==> add_subdirectory(agv_base_hardware/agv_snap7_driver)
-- CMAKE_MODULE_PATH: /home/twobit/workspaces/bestvc_ws/branches/Gestamp_Amorebieta_01/base/src/agv_base_hardware/agv_snap7_driver/cmake
LibSNAP7_INCLUDE_DIR /usr/include
LibSNAP7_LIBRARY /usr/lib/libsnap7.so
LibSnap7_LIBRARIES /usr/lib/libsnap7.so
LibSnap7_INCLUDE_DIRS /usr/include
lld output
$ ldd libagv_snap7_driver.so | grep snap
libsnappy.so.1 => /usr/lib/x86_64-linux-gnu/libsnappy.so.1 (0x00007fe89c01e000)
So as you can see the includes are found, as well the library. Providing ${LibSnap7_LIBRARIES} to target_link_libraries is not linking agains libsnap7.so
After installing snap7 from source I found the example cpp's are linked correctly.
When anyone has an idea why this incorrect link is happening I would be happy for any help.
Thank you in advance!
I'm currently working on a school project with Visual Studio 2019, and we face a problem:
LINK : fatal error LNK1104: cannot open file 'Irrlicht.lib'
The error only came when we already have compiled our CMake file, the first time it's working.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.9)
project(IndieCMAKE)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 11)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
find_package(Irrlicht)
link_libraries(Irrlicht)
INCLUDE_DIRECTORIES(
"/usr/include/irrlicht"
"./include"
${PROJECT_SOURCE_DIR}/include
)
include_directories(inc)
add_executable(IndieCMAKE
./main.cpp)
Here is my FindIrrlicht.cmake file:
IF (NOT Irrlicht_INCLUDE_DIRS OR NOT Irrlicht_LIBRARIES)
FIND_PATH(Irrlicht_INCLUDE_DIRS
NAMES
irrlicht.h
PATHS
/usr/include/irrlicht/ # Default Fedora28 system include path
/usr/local/include/irrlicht/ # Default Fedora28 local include path
${CMAKE_MODULE_PATH}/include/ # Expected to contain the path to this file for Windows10
${Irrlicht_DIR}/include/ # Irrlicht root directory (if provided)
)
IF (MSVC) # Windows
SET(CMAKE_FIND_LIBRARY_PREFIXES "")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
ELSE (MSVC) # Linux
SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
ENDIF(MSVC)
FIND_LIBRARY(Irrlicht_LIBRARIES
NAMES
Irrlicht
PATHS
/usr/lib64 # Default Fedora28 library path
/usr/lib/ # Some more Linux library path
/usr/lib/x86_64-linux-gnu/ # Some more Linux library path
/usr/local/lib/ # Some more Linux library path
/usr/local/lib64/ # Some more Linux library path
${CMAKE_MODULE_PATH}/ # Expected to contain the path to this file for Windows10
${Irrlicht_DIR}/ # Irrlicht root directory (if provided)
)
ENDIF (NOT Irrlicht_INCLUDE_DIRS OR NOT Irrlicht_LIBRARIES)
IF (Irrlicht_INCLUDE_DIRS AND Irrlicht_LIBRARIES)
SET(Irrlicht_FOUND TRUE)
ELSE (Irrlicht_INCLUDE_DIRS AND Irrlicht_LIBRARIES)
SET(Irrlicht_FOUND FALSE)
ENDIF (Irrlicht_INCLUDE_DIRS AND Irrlicht_LIBRARIES)
IF (Irrlicht_FIND_REQUIRED AND NOT Irrlicht_FOUND)
MESSAGE(FATAL_ERROR
" Irrlicht not found.\n"
" Windows: Fill CMake variable CMAKE_MODULE_PATH to the provided directory.\n"
" Linux: Install Irrlicht using your package manager ($> sudo dnf install irrlicht-devel).\n"
)
ENDIF (Irrlicht_FIND_REQUIRED AND NOT Irrlicht_FOUND)
Here are my CMake GUI variables:
If you are using a CMake Find Module, such as a FindIrrlicht.cmake file, the find_package(Irrlicht) command should populate some Irrlicht_* CMake variables for you. Assuming find_package() actually found the package components correctly, you can use these Irrlicht_* variables in your CMake file to specify where CMake should look for Irrlicht package headers and libraries.
Something like the following CMake file should work:
cmake_minimum_required(VERSION 3.9)
project(IndieCMAKE)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 11)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# Use REQUIRED here, to ensure CMake finds the package before continuing.
find_package(Irrlicht REQUIRED)
# Don't use this command. It's old, and the syntax didn't work, in your case.
#link_libraries(Irrlicht)
# Specify your directories that contain headers, including the Irrlicht headers.
include_directories(
${Irrlicht_INCLUDE_DIRS}
)
# Define your executable target.
add_executable(IndieCMAKE
main.cpp
)
# Link the Irrlicht library to your executable target.
target_link_libraries(IndieCMAKE PRIVATE ${Irrlicht_LIBRARIES})
I have a cmake project which is a static library that i have to share with other teams in my company but just the .lib file and not the source code.
This library depends on Boost.
Now i build the library and transfer the install folder onto another pc (exe_pc) and use it in a exe project (this exe also depends on boost).
Now at compile time i get a linking error saying that E:/Development/vcpkg/installed/x64-windows/lib/boost_system-vc140-mt.lib cannot be opened.
so i open and check the generated LibTargets.cmake and it contains absolute paths of boost library for pc on which the library was built.
# The installation prefix configured by this project.
set(_IMPORT_PREFIX "C:/Program Files/cpp_licensing")
# Create imported target Licensing::liblicensing
add_library(Licensing::liblicensing STATIC IMPORTED)
set_target_properties(Licensing::liblicensing PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "_LICENSING_DEBUG=0"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "\$<\$<NOT:\$<CONFIG:DEBUG>>:E:/Development/vcpkg/installed/x64-windows/lib/boost_system-vc140-mt.lib>;\$<\$<CONFIG:DEBUG>:E:/Development/vcpkg/installed/x64-windows/debug/lib/boost_system-vc140-mt-gd.lib>;\$<\$<NOT:\$<CONFIG:DEBUG>>:E:/Development/vcpkg/installed/x64-windows/lib/boost_filesystem-vc140-mt.lib>;\$<\$<CONFIG:DEBUG>:E:/Development/vcpkg/installed/x64-windows/debug/lib/boost_filesystem-vc140-mt-gd.lib>;cryptopp-static;wbemuuid"
)
LibLicensingTargets-release.cmake
et_target_properties(Licensing::liblicensing PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
IMPORTED_LOCATION_RELEASE "C:/Program Files/cpp_licensing/lib/licensing.lib"
)
list(APPEND _IMPORT_CHECK_TARGETS Licensing::liblicensing )
list(APPEND _IMPORT_CHECK_FILES_FOR_Licensing::liblicensing "C:/Program Files/cpp_licensing/lib/licensing.lib" )
The user is supposed to have boost installed, the only problem i have is that because absolute paths are used in targets file user has to manually change them on his pc in the targets file.
what changes do i make to cmake so that the libraries built folder can be shared. How do i distribute a library built using cmake ??
Here is the cmake for the library project
cmake_minimum_required(VERSION 3.10)
project(liblicensing)
message("~~ Project: " ${PROJECT_NAME})
set(LIB_NAME "${PROJECT_NAME}")
set(PROJECT_VERSION 1.0)
include_directories(
${PROJECT_SOURCE_DIR}/include
)
if (WIN32)
find_package(Boost REQUIRED system filesystem)
find_package(cryptopp REQUIRED)
find_package(unofficial-date REQUIRED)
include_directories(
${Boost_INCLUDE_DIR}
)
else()
find_package(date REQUIRED)
endif ()
file(GLOB_RECURSE HEADER_FILES include/*.h include/*.hpp)
file(GLOB_RECURSE SOURCES src/*.cpp)
add_library(${LIB_NAME} STATIC ${SOURCES} ${HEADER_FILES} )
set_target_properties(
${LIB_NAME}
PROPERTIES
OUTPUT_NAME "licensing"
POSITION_INDEPENDENT_CODE ON
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
LINKER_LANGUAGE CXX
)
if (MSVC)
set_target_properties(${LIB_NAME} PROPERTIES DEBUG_POSTFIX "_d")
endif()
add_library(Licensing::liblicensing ALIAS ${LIB_NAME})
set(INSTALLATION_DIR "${CMAKE_INSTALL_PREFIX}")
set(CMAKE_INSTALL_LIBDIR "${INSTALLATION_DIR}/lib")
set(CMAKE_INSTALL_BINDIR "${INSTALLATION_DIR}/bin")
set(CMAKE_INSTALL_INCLUDEDIR "include")
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${LIB_NAME})
target_include_directories(${LIB_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if (WIN32)
target_link_libraries(
${LIB_NAME}
${Boost_LIBRARIES}
cryptopp-static
wbemuuid
)
else()
target_link_libraries(
${LIB_NAME}
cryptopp
boost_system
boost_filesystem
)
endif ()
if(CMAKE_BUILD_TYPE MATCHES Debug)
target_compile_definitions(${LIB_NAME} PUBLIC _LICENSING_DEBUG=1)
elseif(CMAKE_BUILD_TYPE MATCHES Release)
target_compile_definitions(${LIB_NAME} PUBLIC _LICENSING_DEBUG=0)
endif()
# Expose Projects's public includes to other subprojects through cache variable.
set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include CACHE INTERNAL "${PROJECT_NAME}: Include Directories" FORCE)
###############
# Installation
##
install(TARGETS ${LIB_NAME}
EXPORT LibLicensingTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${LIB_NAME}
FILES_MATCHING PATTERN "*.h*")
install(EXPORT LibLicensingTargets
FILE LibLicensingTargets.cmake
NAMESPACE Licensing::
DESTINATION ${INSTALL_CONFIGDIR}
)
#####################
# ConfigVersion file
##
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/LibLicensingConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/CMake/LibLicensingConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LibLicensingConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
## Install all the helper files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/LibLicensingConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/LibLicensingConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
Not an entire answer but too much for a comment:
If you inspect your file LibLicensingTargets.cmake closely, you see that cryptopp-static and wbemuuid are not resolved down to the library level.
Looking at how you reference Boost you use the oldstyle version (${Boost_LIBRARIES}) that resolves down to the library level.
Try instead to use the targets provided by FindBoost.cmake module as follows:
if (WIN32)
target_link_libraries(
${LIB_NAME}
Boost::system
Boost::filesystem
cryptopp-static
wbemuuid
)
else()
target_link_libraries(
${LIB_NAME}
cryptopp
Boost::system
Boost::filesystem
)
endif()
Another thing that puzzles me is why you added the ALIAS:
add_library(Licensing::liblicensing ALIAS ${LIB_NAME})
This ALIAS is properly created in the LibLicensingTargets.cmake file, so you do not need to create it on your own.
Another thing is, that you are giving your INSTALL command absolute paths. To make the package entirely relocatable you need to use relative paths (relative to the CMAKE_INSTALL_PREFIX, the installation directory).
The following commands should therefore be changed to:
set(CMAKE_INSTALL_LIBDIR "lib")
set(CMAKE_INSTALL_BINDIR "bin")
set(CMAKE_INSTALL_INCLUDEDIR "include")
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${LIB_NAME})
If you further add the line:
export(TARGETS liblicensing NAMESPACE LibLicensing:: FILE LibLicensingTargets.cmake)
to your CMakeLists.txt, outside projects are able to import target from your build tree folder as of liblicensing was installed therein. See the CMake documentation of the export command.
I'm using cmake to build an executable to run on an Intel Galileo board.
My question is how do I include the external mraa library in the build process.
Mraa library
When I download the library from git (1) do I need to build it as described here
Mraa compiling instructions
What do I need to put in my CMakeLists.txt file to pick up the library?
This is what I have thus far in my CMakeLists.txt file but I believe it is incorrect.
### MRAA ###
add_subdirectory(mraa-master/src)
file(GLOB mraa_SRC
"mraa-master/src/*.c"
)
include_directories( "${PROJECT_SOURCE_DIR}/mraa-master/include" )
add_library( ${MRAA_LIBRARY_NAME} SHARED ${mraa_SRC} )
Thank you
cmake_minimum_required(VERSION 2.8)
MESSAGE( STATUS "Starting build process")
SET( CMAKE_VERBOSE_MAKEFILE on )
if (CMAKE_BUILD_TYPE EQUAL "Debug")
MESSAGE(STATUS "Building in debug mode")
elseif (CMAKE_BUILD_TYPE EQUAL "Release")
MESSAGE(STATUS "Building in release mode")
endif()
SET(PROJECT_NAME "TestProject")
SET(APPLICATION_NAME "TestApplication")
SET(SAFE_STRING_LIBRARY "SafeString")
SET(APPLICATION_LIBRARY "Applibrary")
PROJECT( ${PROJECT_NAME} )
MESSAGE( STATUS "PROJECT: " ${PROJECT_NAME} )
SET(WRSDK_PATH "$ENV{WINDRIVER_SDK_DIR}")
IF (WRSDK_PATH)
else()
SET(WRSDK_PATH /opt/windriver/wrlinux/5.0-intel-quark/)
endif()
SET(APPLIBRARY_NAME ${APPLICATION_LIBRARY} )
SET(SAFE_STRING_LIBRARY_NAME ${SAFE_STRING_LIBRARY} )
### SAFE STRING ###
add_subdirectory(SafeStringStaticLibrary/safeclib)
file(GLOB safestring_SRC
"SafeStringStaticLibrary/safeclib/*.c"
)
include_directories( "${PROJECT_SOURCE_DIR}/SafeStringStaticLibrary /safeclib" )
add_library( ${SAFE_STRING_LIBRARY_NAME} SHARED ${safestring_SRC} )
include(ExternalProject)
ExternalProject_Add(mraa
GIT_REPOSITORY https://github.com/intel-iot-devkit/mraa.git
GIT_TAG v0.8.0
UPDATE_COMMAND ""
INSTALL_COMMAND "" )
file(GLOB app_SRC
"classes/*.cpp"
"Logger.cpp"
"sqlite3.c"
"shell.c"
)
add_library( ${APPLIBRARY_NAME} SHARED ${app_SRC})
include_directories( "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/SafeStringStaticLibrary/include" )
add_executable( ${APPLICATION_NAME} ${APPLICATION_NAME}.cpp
include_directories( "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/SafeStringStaticLibrary/include" "${CMAKE_SOURCE_DIR}/classes")
TARGET_LINK_LIBRARIES( ${APPLICATION_NAME} ${APPLIBRARY_NAME} ${SAFE_STRING_LIBRARY_NAME} -lrt -lpthread -lgcov -ldl)
The simplest way for build your project alongside with 3d party project is add_subdirectory() that subproject. Approach below implies that you (manually) download(git clone) sources of mraa project into mraa-lib subdirectory of your project's sources.
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
MESSAGE( STATUS "Starting build process")
# Configure subproject before definition of variables for main project.
#
# Subproject defines *mraa* library target.
add_subdirectory(mraa-lib)
# Before installation, public mraa headers are contained under *api* subdirectory.
include_directories(mraa-lib/api)
... # create executable ${APPLICATION_NAME}
# Linking with mraa library is straightforward.
target_link_libraries(${APPLICATION_NAME} mraa)
That way mraa subproject will be configured, built and installed alongside with your project. So, if you cross-compile your project(using toolchain file, or inside IDE), the subproject will also be cross-compiled.