I am trying to convince cmake/cpack to build a shared library package (component lib) and a development package (component dev).
The lib component should only contain the shared library, and should have no dependencies.
The dev component should only contain the header file, and should depend on the lib component.
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.5)
project(libmy)
add_library(my SHARED src/main/my.c)
target_include_directories(my PUBLIC include)
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_CONTACT "peter.spierenburg#nautel.com")
install(TARGETS my
LIBRARY
DESTINATION /usr/local/lib
COMPONENT lib)
install(FILES include/my.h
DESTINATION /usr/local/include
COMPONENT dev)
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON)
include(CPack)
cpack_add_component(lib REQUIRED)
cpack_add_component(dev DEPENDS lib)
A build nets me two deb packages libmy-0.1.1-Linux-dev.deb and libmy-0.1.1-Linux-lib.deb. However, the dev package does not depend on the lib package.
Related
Got error when I build the project like in the below. I tried so many things but never succeeded. I'm using m1 MacBook. Is this related with this error ?
[CXX1405] exception while building Json A problem occurred starting process 'command '/Users/serhat/Library/Android/sdk/cmake/3.18.1/bin/cmake''
in build.gradle:
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
and this is CmakeList.txt :
# For more information about using CMake with Android Studio,read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
I fixed this issue :
softwareupdate --install-rosetta
I just wonder how you can know how to properly case the libraries in vcpkg?
i.e.
find_package(gtest REQUIRED) will fail but
find_package(GTest REQUIRED) will pass
What I mean is if I list the installed packages I get them in lowercase letters, i.e.
CMake suite maintained and supported by Kitware (kitware.com/cmake).
~/Proj$ cd vcpkg
~/Proj/vcpkg$ ./vcpkg list
fftw3:x64-linux 3.3.10#3 FFTW is a C subroutine library for computing the...
gtest:x64-linux 1.11.0#3 GoogleTest and GoogleMock testing frameworks
vcpkg-cmake-config:x64-linux 2021-12-28
vcpkg-cmake:x64-linux 2021-12-20
So if I for instance want to add fftw3, how can I tell which case it is?
find_package(fftw3 REQUIRED) fails...
Assuming you are correctly adding -DCMAKE_TOOLCHAIN_FILE=$HOME/Proj/vcpkg/scripts/buildsystems/vcpkg.cmake to your build, then what you're observing has nothing to do with vcpkg in particular.
find_package is as case-sensitive as the filesystem you're on. On Windows, gtest will happen to work, but the real name is GTest, so only that one works on Linux. The name of the fftw3 package is, similarly, FFTW3.
Vcpkg very helpfully tells you this, too:
$ ./vcpkg install fftw3:x64-linux
...
The package fftw3 provides CMake targets:
find_package(FFTW3 CONFIG REQUIRED)
target_link_libraries(main PRIVATE FFTW3::fftw3)
find_package(FFTW3f CONFIG REQUIRED)
target_link_libraries(main PRIVATE FFTW3::fftw3f)
find_package(FFTW3l CONFIG REQUIRED)
target_link_libraries(main PRIVATE FFTW3::fftw3l)
$ ./vcpkg install gtest:x64-linux
...
The package gtest provides CMake targets:
find_package(GTest CONFIG REQUIRED)
target_link_libraries(main PRIVATE GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main)
I have to import a libft4222.so.1.2.3 into a CMake project on Linux. There are no symlinks without version information like a plain libmyimportedlibrary.so. I am writing a FindLibFT4222.cmake to make the library usable in my project.
In my project, a shared library uses libft4222 like this:
if (LIBFT4222_FOUND)
if (NOT TARGET LibFT4222::LibFT4222)
add_library(LibFT4222::LibFT4222 UNKNOWN IMPORTED)
set_target_properties(LibFT4222::LibFT4222
PROPERTIES IMPORTED_LOCATION ${LibFT4222_LIBS})
target_include_directories(LibFT4222::LibFT4222
INTERFACE
${LibFT4222_INCLUDE_DIR})
endif()
endif()
LibFT4222_LIBS points to the imported location of the libft4222.so.1.2.3:
/path/to/libft4222.so.1.2.3
I am adding this library as a dependency to a shared library A in my project.
Finally, I have an executable depending on A.
When I link the executable, the linker reports an error that it cannot find libft4222.so
When I add libft4222 directly to the executable, it works.
The error message I get:
/usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: warning: libft4222.so, needed by libSomeOtherLib.so, not found (try using -rpath or -rpath-link)
How do I tell CMake to correctly handle libft4222.so.1.2.3 and not to omit .1.2.3?
Update 1: I looked at the SONAME property of libft4222.so.1.2.3:
$ arm-linux-gnueabihf-objdump -p libft4222.so.1.4.4.44 | grep SONAME
SONAME libft4222.so
So I guess creating the symlinks is unavoidable.
I'm new to esp-idf developement and I want to build a static library for esp32.
I've read the espressif documentation (available here : Programming Guide) but I can't manage to create a proper .a file.
The idea is to develop a new library of wrapper and functions which include functions from esp-dsp library. I've add the esp-dsp component to my project and created my own component: my_component.
There is my project structure right now:
- first_project/
- CMakeLists.txt
- sdkconfig
- components/ - esp-dsp/ - CMakeLists.txt
- ...
- ...
- my_component/ - CMakeLists.txt
- my_component.c
- include/
- my_component.h
- main/ - CMakeLists.txt
- main.c
- build/
Following are the CMakeLists.txt files:
CMakeLists.txt (first_project)
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(first_test)
CMakeLists.txt (main)
idf_component_register(SRCS "main.c"
INCLUDE_DIRS "."
REQUIRES my_component esp-dsp)
CMakeLists.txt (my_component)
idf_component_register(SRCS "my_component.c"
INCLUDE_DIRS "include"
REQUIRES esp-dsp)
In my_component.c there are functions from esp-dsp
With the previous files, I managed to create a binary to flash into ESP32 board but the next step is to build a static library (my_library.a) where there are functions inside my_component.c.
So I tried to modify CmakeLists.txt (main) in order to create the static library [MyStaticLib.a] regarding the component my_component
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(first_test)
ADD_LIBRARY( MyStaticLib STATIC
components/my_component/my_component.c )
SET( APP_EXE StaticTest )
ADD_EXECUTABLE( ${APP_EXE}
main/main.c )
TARGET_LINK_LIBRARIES( ${APP_EXE}
MyStaticLib )
However, during the build, I can't see the include path folder of my_component. Then the compilation failed because of my_component.h:No such file or directory
FAILED: CMakeFiles/MyStaticLib.dir/components/my_component/my_component.c.obj
ccache C:\Users\julien\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-gcc.exe -mlongcalls -Wno-frame-address -g -MD -MT CMakeFiles/MyStaticLib.dir/components/my_component/my_component.c.obj -MF CMakeFiles\MyStaticLib.dir\components\my_component\my_component.c.obj.d -o CMakeFiles/MyStaticLib.dir/components/my_component/my_component.c.obj -c ../components/my_component/my_component.c
../components/my_component/my_component.c:2:10: fatal error: my_component.h: No such file or directory
The problem is only present when I modify the CMakeLists.txt from main to build the static library.
I though the variable INCLUDE_DIRS from CMakeLists.txt file could solved the problem but in vain.
Any idea where I'm doing wrong in CMakeLists.txt parameter in order to build .a static library to be used as a component in other project?
Regards.
Just build the example with your component added as you do.
You will see all the components got build as a library(.a) under build/esp-idf/ folder.
Use that libmy_component.a in other projects along with libesp_dsp.a.
cmake_minimum_required(VERSION 3.15)
project(hello)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
set(CMAKE_CXX_STANDARD 11)
add_executable(hello main.cpp)
INCLUDE_DIRECTORIES(${GLFW_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(hello ${GLFW_STATIC_LIBRARIES})
It tells me
CMake Error at /home/user/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5233.144/bin/cmake/linux/share/cmake-3.15/Modules/FindPkgConfig.cmake:696 (message):
None of the required 'glfw3' found
when I try to build it. My glfw folder is located at /usr/local/include/GLFW.
AFAIK, glfw3 is using CMake as the build system,
(src: packages.debian.org/fr/sid/amd64/libglfw3-dev/filelist)
which uses modern CMake, so you don't need GLFW_INCLUDE_DIRS etc...
Inside this file /usr/lib/cmake/glfw3/glfw3Targets.cmake (loaded by /usr/lib/cmake/glfw3/glfw3Config.cmake), you'll see:
...
# Create imported target glfw
add_library(glfw SHARED IMPORTED)
set_target_properties(glfw PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "GLFW_DLL"
INTERFACE_INCLUDE_DIRECTORIES "/usr/include"
)
...
So you can simply use:
find_package(glfw3 REQUIRED)
...
target_link_libraries(Foo glfw)
ps: same as my previous comment