CMake: export third party headers to directory - cmake

Using CMake I am using a third party library, TinyThread++, it is a simple Thread library wrapper and only contains 1 source files and 2 header files.
In my project CMakeList.txt I added the following line:
add_library(TinyThread STATIC ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/TinyThread/source/tinythread.cpp)
And then added a dependency to this library to the my executable this is working great.
I am trying to figure out how to copy or export the two header files to a common include directory I am using in my project.
${CMAKE_CURRENT_SOURCE_DIR}/../../include
What is the recommended way to do this?

If you simply want to "use" those headerfiles while compiling, you can use include_directories() like Naszta explains.
In case you really want to copy the files, you can use configure_file() or file( COPY ... ) (check the bottom of the section on the file() command).

I think you should do something like this:
SET(TINY_THREAD_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "TinyThread include path")
SET(TINY_THREAD_SOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/tinythread.cpp" CACHE FILEPATH "TinyThread source file")
...
INCLUDE_DIRECTORIES(${TINY_THREAD_INCLUDE_PATH})
ADD_LIBRARY(TinyThread STATIC ${TINY_THREAD_SOURCE_FILE})
This way you could reuse them later by their name. If you would like to hide them in normal mode:
MARK_AS_ADVANCED(TINY_THREAD_INCLUDE_PATH TINY_THREAD_SOURCE_FILE)

Related

file strings requires and filename and output variable in cmake

target_link_libraries(${PROJECT_NAME}
serializer
iothub_client
iothub_client_mqtt_transport
umqtt
aziotsharedutil
ssl
crypto
curl
ssl..... utils)
Hello there , I am working on a project where I have a large set of libraries, and have use it like it (shown above). but instead of hardcoding these libraries explicitly,i want write it in a one line.
now I want to write it in a one line for linking, so specifically, what I have tried in the root level I have created a file called "library.lst" and in this .lst file I am giving the path of that library
build/src/con/shared/virtual/serializer/serializer.a"
build/src/con/shared/virtual/iothub_client/iothub_client.a"
build/src/con/shared/virtual/umqtt/ umqtt.a"
build/src/con/shared/virtual/utils/utlis.a
## write for every library
I am placing this .lst file in the folder called "filelist", e.g filelist/Library.lst where it will take all the libraries and will link.
so what I wrote this In each camkelists.txt where this library used by writing
file(STRINGS ${filelist} library) ,
target_link_libraries(${PROJECT NAME} ${library}),
but when I am running this script I an getting the errors like
"error:- "file strings requires and filename and output variable",
and I also have creates build.sh file where I am giving the path of it
"-D"filelist=%FILELISTSPATH%\library.lst"
" so could you please help me here and also need some explanation on it to understand it in a better way.Thanks in advance.

Why doesn't cmake find_package(VTK) find VTK_INCLUDE_DIRS after building VTK from source and installing?

I’m running cmake version 3.23.0-rc1, on ubuntu 20.04.
I built vtk-8.2 from source; cmake, make, then ‘make install’. Now I am trying to find the VTK package for my own application, using cmake’s find_package(VTK). The application’s CMakeLists.txt contains this:
find_package(VTK)
message("VTK_FOUND: ${VTK_FOUND}")
message("VTK_INCLUDE_DIRS: ${VTK_INCLUDE_DIRS}")
message("VTK_LIBRARIES: ${VTK_LIBRARIES}")
Result is that VTK_FOUND=1, VTK_LIBRARIES contains many entries, but VTK_INCLUDE_DIRS is blank/empty. Why would this be?
I do see file /usr/local/lib/cmake/vtk-8.2, which contains many *.cmake files. But I don’t see a corresponding /usr/local/include/cmake directory, despite the presence of /usr/local/include/vtk-8.2. Is that expected? Here is the output:
VTK_FOUND: 1
VTK_INCLUDE_DIRS:
VTK_LIBRARIES: VTK::WrappingTools;VTK::ViewsQt;VTK::ViewsInfovis;VTK::CommonColor;VTK::ViewsContext2D;VTK::loguru;VTK::TestingRendering;VTK::TestingCore;VTK::vtksys;VTK::RenderingQt;VTK::PythonContext2D;VTK::RenderingVolumeOpenGL2;VTK::RenderingOpenGL2;VTK::glew;VTK::opengl;VTK::PythonInterpreter;VTK::Python;VTK::RenderingLabel;VTK::octree;VTK::RenderingLOD;VTK::RenderingImage;VTK::RenderingContextOpenGL2;VTK::IOVeraOut;VTK::hdf5;VTK::IOTecplotTable;VTK::IOSegY;VTK::IOParallelXML;VTK::IOPLY;VTK::IOOggTheora;VTK::theora;VTK::ogg;VTK::IONetCDF;VTK::netcdf;VTK::IOMotionFX;VTK::pegtl;VTK::IOParallel;VTK::jsoncpp;VTK::IOMINC;VTK::IOLSDyna;VTK::IOInfovis;VTK::libxml2;VTK::zlib;VTK::IOImport;VTK::IOGeometry;VTK::IOVideo;VTK::IOMovie;VTK::IOExportPDF;VTK::libharu;VTK::IOExportGL2PS;VTK::RenderingGL2PSOpenGL2;VTK::gl2ps;VTK::png;VTK::IOExport;VTK::RenderingVtkJS;VTK::RenderingSceneGraph;VTK::IOExodus;VTK::exodusII;VTK::IOEnSight;VTK::IOCityGML;VTK::pugixml;VTK::IOAsynchronous;VTK::IOAMR;VTK::InteractionImage;VTK::ImagingStencil;VTK::ImagingStatistics;VTK::ImagingMorphological;VTK::ImagingMath;VTK::GUISupportQtSQL;VTK::IOSQL;VTK::sqlite;VTK::GUISupportQt;VTK::GeovisCore;VTK::libproj;VTK::InfovisLayout;VTK::ViewsCore;VTK::InteractionWidgets;VTK::RenderingVolume;VTK::RenderingAnnotation;VTK::ImagingHybrid;VTK::ImagingColor;VTK::InteractionStyle;VTK::FiltersTopology;VTK::FiltersSelection;VTK::FiltersSMP;VTK::FiltersPython;VTK::FiltersProgrammable;VTK::FiltersPoints;VTK::FiltersVerdict;VTK::verdict;VTK::FiltersParallelImaging;VTK::FiltersImaging;VTK::ImagingGeneral;VTK::FiltersHyperTree;VTK::FiltersGeneric;VTK::FiltersFlowPaths;VTK::FiltersAMR;VTK::FiltersParallel;VTK::FiltersTexture;VTK::FiltersModeling;VTK::FiltersHybrid;VTK::RenderingUI;VTK::DomainsChemistry;VTK::CommonPython;VTK::WrappingPythonCore;VTK::ChartsCore;VTK::InfovisCore;VTK::FiltersExtraction;VTK::ParallelDIY;VTK::diy2;VTK::IOXML;VTK::IOXMLParser;VTK::expat;VTK::ParallelCore;VTK::IOLegacy;VTK::IOCore;VTK::doubleconversion;VTK::lz4;VTK::lzma;VTK::utf8;VTK::FiltersStatistics;VTK::eigen;VTK::ImagingFourier;VTK::ImagingSources;VTK::IOImage;VTK::DICOMParser;VTK::jpeg;VTK::metaio;VTK::tiff;VTK::RenderingContext2D;VTK::RenderingFreeType;VTK::freetype;VTK::kwiml;VTK::RenderingCore;VTK::FiltersSources;VTK::ImagingCore;VTK::FiltersGeometry;VTK::FiltersGeneral;VTK::CommonComputationalGeometry;VTK::FiltersCore;VTK::CommonExecutionModel;VTK::CommonDataModel;VTK::CommonSystem;VTK::CommonMisc;VTK::CommonTransforms;VTK::CommonMath;VTK::CommonCore
find_package(VTK) no longer sets VTK_INCLUDE_DIRS variable. If you look into description part of vtk-config.cmake (script CMake/vtk-config.cmake.in contains template of that file), then you find no note about VTK_INCLUDE_DIRS.
Since VTK_LIBRARIES variable contains IMPORTED targets (in form of VTK::foo), linking with the content of that variable using target_link_libraries will automatically provide include directories.

CMakeLists using variables to define source/include locations

I have an AndroidStudio project with 'C' files in. I can compile and run as-is.
My native files are in
src/main/jni/aes
src/main/jni/libjpeg
src/main/jni/smuglib
I am trying to move the source to a location external to the Android studio project so that I can use it from several locations/projects to avoid copy/paste/mistake cycle.
I have defined the include path in CMakeLists.txt
include_directories(src/main/jni/aes src/main/jni/libjpeg src/main/jni/smuglib)
And have specified the files in the add_library command
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/jni/aes/aes.c
src/main/jni/smuglib/smuglib.c
.... etc
How do I set up a variable to refer to these paths, eg 'src/main/jni/aes' so that I can use it in both the include and in the source list?
I tried variations on
set(aes_src, src/main/jni/aes)
but uses of it as ${aes_src} either in the include path statement or in the source list give me all sorts of arcane errors which I am at a loss to understand.
I will generate some of these and include them if folk think it would help, but I am likely barking up the wrong kettle of fish with this approach.
Is there a better approach?
It is set(VAR_NAME item1 item2 item3). No commas needed.

Build Complex Project Filter via CMake

I built a C++ project which the file structure as same as the image
Every Cpp file is an isolated executable file. And I would like to build a project filter as same as the file structure via CMake.
The following code sample shows the root CMakeLists.txt I wrote for this purpose:
project(Samples)
source_group( "Samples\\ClientSamples" FILES ${PROJECT_SOURCE_DIR}/ClientSamples/ClientSamplesMain.cpp )
source_group( "Samples\\GenericSamples" FILES ${PROJECT_SOURCE_DIR}/GenericSamples/GenericSamplesMain.cpp )
source_group( "Samples\\ServerSamples" FILES ${PROJECT_SOURCE_DIR}/ServerSamples/ServerSamplesDemo.cpp ${PROJECT_SOURCE_DIR}/ServerSamples/HttpServerSample.cpp )
add_subdirectory(GenericSamples)
add_subdirectory(ServerSamples)
add_subdirectory(ClientSamples)
And the result didn't match my expectation.
The result is
.
So, is there a way to reach the goal?
Best Regards.

Cmake script problems find_path

I have put these two lines in my Findglm.cmake file to point to the headers for this header library.
find_path(glm_INCLUDE_DIR NAMES glm.hpp matrix_transform.hpp type_ptr.hpp PATHS
${CMAKE_SOURCE_DIR}/libs/glm-0.9.3.2/glm ${CMAKE_SOURCE_DIR}/libs/glm-0.9.3.2/glm/gtc
${CMAKE_SOURCE_DIR}/libs/glm-0.9.3.2/glm/gtx ${CMAKE_SOURCE_DIR}/libs/glm-0.9.3.2glm/core)
set(glm_INCLUDE_DIRS ${glm_INCLUDE_DIR})
However when I generate my Xcode project it says that it cannot locate matrix_transform.hpp and type_ptr.hpp
I have played around with this some more it appears to only find the first argument I am wondering if I am using find path wrong ?
I am using cmake 2.8.8 darwinports.
The find_path() command returns single directory. In your case, it's the first dir, which contains the first file.
If this glm will be always located in your source dir, it would be sufficient to do
include_directories(${CMAKE_SOURCE_DIR}/libs/glm-0.9.3.2/glm
${CMAKE_SOURCE_DIR}/libs/glm-0.9.3.2/glm/gtc
${CMAKE_SOURCE_DIR}/libs/glm-0.9.3.2/glm/gtx
${CMAKE_SOURCE_DIR}/libs/glm-0.9.3.2/glm/core)
The find_path() is used to determine dir somewhere outside of your project.