My linux machine has directory /usr/local/include/vtk-8.2/
How can cmake find this directory using glob expression âvtk-8â?
I tried this:
file(GLOB result LIST_DIRECTORIES true RELATIVE /usr/local â*vtk-8*â)
But ${result} is empty.
What am I doing wrong?
Thanks!
(cmake version 3.23.0-rc1, ubuntu 20.08)
What am I doing wrong?
You are searching for vtk-8 in current source directory. Search for them in /usr/local if you want to.
file(GLOB result LIST_DIRECTORIES true RELATIVE /usr/local /usr/local/*vtk-8*)
Related
I tried multiple approaches:
install(TARGETS tgt RUNTIME DESTINATION /usr/bin RENAME another_name) ignores RENAME without any warning. Documentation says no about RENAME for TARGETS.
add_executable(zbus-publish ALIAS zbus-example-publisher) gives an error
install TARGETS given target "zbus-publish" which is an alias.
tried to install symlinks to installed targets
install(CODE "execute_process(COMMAND ln -s zbus-example-publisher ${DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/zbus-publish
COMMAND ln -s zbus-example-subscriber ${DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/zbus-subscribe)
message(==================================================)"
But it expands DESTDIR to nothing.
I need DESTDIR because use make DESTDIR=xxxx to test my installation. It is very convenient. And also useful when cross-compiling.
CMake version 3.17.2
I found an answer here
You can change the Prefix, Output Name and Suffix using the set_target_properties() function and the PREFIX / OUTPUT_NAME / SUFFIX property in the following way:
Prefix:
set_target_properties(new_thing PROPERTIES PREFIX "")
Output Name:
set_target_properties(new_thing PROPERTIES OUTPUT_NAME "better_name")
Suffix:
set_target_properties(new_thing PROPERTIES SUFFIX ".so.1")
This is not exactly what I looked for. But works in special case.
I'd like to keep OUTPUT_NAMEs as is and create symlinks during install.
I'm having problems convincing cmake/cpack to generate a debian package that contains a single executable quine stored in a specific folder named /absolute/path.
According to https://cmake.org/cmake/help/v2.8.0/cmake.html#command:install I should be able to use an absolute path:
DESTINATION arguments specify the directory on disk to which a file
will be installed. If a full path (with a leading slash or drive
letter) is given it is used directly. If a relative path is given it
is interpreted relative to the value of CMAKE_INSTALL_PREFIX.
Here is my C file quine.c:
char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";main(){printf(s,34,s,34);}
and my CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
project(quine)
file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
add_executable(quine ${SOURCES})
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Nobody")
install(
TARGETS quine
RUNTIME DESTINATION /absolute/path
)
include(CPack)
In an empty subdirectory called build I invoke the following:
$ cmake ..
$ make package
and the resulting package is only 512 bytes in length, and a:
$ dpkg -c quine-0.1.1-Linux.deb
confirms that the package is empty.
What am I doing wrong?
How do I find all directories named include in cmake? For instance, if the directory structure is like that:
root
include/
a/
include/
b/
c/
d/
include/
I'd like to assign to a variable all found paths:
root/include
root/a/include
root/b/c/d/include
I tried to use GLOBE_RECURSE, but with no success.
file(GLOB_RECURSE include_dirs LIST_DIRECTORIES true
RELATIVE ${CMAKE_SOURCE_DIR} "include")
This works since CMake 3.3, as option LIST_DIRECTORIES appears only in this version. (By default, for GLOB_RECURSE mode option LIST_DIRECTORIES is false).
I don't understand the usage of INSTALL_DIR in ExternalProject_Add command. I try to use it but it does not seem to work. Here is an example of a CMakeLists.txt, using Eigen library which compiles quickly:
cmake_minimum_required (VERSION 2.6)
project (example CXX)
include(ExternalProject)
include(ProcessorCount)
set(CMAKE_VERBOSE_MAKEFILE ON)
ProcessorCount(N)
if(NOT N EQUAL 0)
set(CMAKE_BUILD_FLAGS -j${N})
endif()
ExternalProject_Add
(
mylib
PREFIX myprefix
DOWNLOAD_COMMAND wget http://bitbucket.org/eigen/eigen/get/3.2.4.tar.gz && tar xvzf 3.2.4.tar.gz -C mylib --strip-components=1
)
I chose the following project hierarchy:
project
CMakeLists.txt
build/
From build repository, I type:
cmake ..
make
The installation process fails with the following message:
file cannot create directory: /usr/local/include/eigen3.
Maybe need administrative privileges.
As far as I understand, it means that I need to define a "prefix" during the configuration step:
cmake -D CMAKE_INSTALL_PREFIX=$INSTALL_DIR ..
But, the INSTALL_DIR variable is already defined in the ExternalProject_Add command. However, I get the same error when I modify the value of INSTALL_DIR by adding
INSTALL_DIR myprefix/src/install
in the ExternalProject_Add command.
So, what is INSTALL_DIR useful for?
What am I doing wrong?
Of course, I know how to provide my own configuration command to add a prefix and solve the problem. But it is not my question. My question is: if I have to do that, what is the purpose of INSTALL_DIR?
From what I found in this discussion https://www.mail-archive.com/cmake#cmake.org/msg51663.html (scroll to the end of the page to navigate through the thread messages) it is indeed pretty common thing to use CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/contrib
Furthermore, lurking through the ExternalProject.cmake module I found out that the only effect setting this directory has is that CMake will create directory specified in INSTALL_DIR before doing anything else.
Also, it will set the property that you can gather through ExternalProject_Get_Property(${project_name} install_dir) command.
And that's pretty much it.
// As of CMake version 3.2.2
I have copied FindEigen3.cmake into my source directory.
I then added:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})
to my CMakeLists.txt to tell CMake to use this .cmake file.
Then in my CMakeLists.txt I do:
FIND_PACKAGE(Eigen3)
I have the environent variable EIGEN3_INCLUDE_DIR set to /home/doriad/src/eigen
When I run CMake, I get:
-- Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) (Required is at least version "2.91.0")
This is a fresh clone from Mercurial, so the version should be at least 3.
Any suggestions?
If I set the module path INCORRECTLY, I get some clues:
Adjust CMAKE_MODULE_PATH to find FindEigen3.cmake or set Eigen3_DIR to the
directory containing a CMake configuration file for Eigen3. The file will
have one of the following names:
Eigen3Config.cmake
eigen3-config.cmake
However, I didn't find either of those files in either the source dir or build dir of Eigen3. I tried to set Eigen3_DIR=/home/doriad/src/eigen, but that didn't work either.
Thoughts?
Thanks,
David
It worked for me, when I installed the eigen3 package (e.g. using -DCMAKE_INSTALL_PREFIX=/home/doriad/install), and also set the CMAKE_INSTALL_PREFIX variable of the cmake package that is using eigen3 to the same directory.
Because of the problems with findscripts, I've actually started using pkg-config instead. For that you need to enable pkg-config support in the eigen3 cmake, and use the pkg-config macro in your own cmake script. Advantage is that you don't need to set any environment variables anymore.
find_package( PkgConfig )
pkg_check_modules( EIGEN3 REQUIRED eigen3 )
include_directories( ${EIGEN3_INCLUDE_DIRS} )