I have the following folder structure:
Project
|-Sources
| |-Package1
| |-Component11
| |-include
| |-header.hpp
| |-src
| |-source.cpp
| |-CMakeLists.txt
| |-Component12
| |-include
| |-header.hpp
| |-src
| |-source.cpp
| |-CMakeLists.txt
| |-CMakeLists.txt
| |-Package2
| |-Component21
| |-...
| |-Component22
| |-...
| |-CMakeLists.txt
| |-CMakeLists.txt
|-CMakeLists.txt
Lets say that in this design the component21 have a dependency on component11.
I would like to include the header files of component11 in this component as:
#include<Project/Package1/Component11/header.hpp> without repeating this path in include folder of component11 by creating sub directories there. Is there a way in cmake that i can achieve this?
Related
I'm trying to include libheif into my project using cmake. Libheif is more complicated than what I've worked with before because it requires you externally build and include libde265.
Attempt #1:
I have used vcpkg to export pre-built binary packages, this creates a directory called libheif which includes everything here:
+---bin
| heif.dll
| libde265.dll
| libx265.dll
| libx265.pdb
|
+---debug
| +---bin
| | heif.dll
| | libde265.dll
| | libx265.dll
| | libx265.pdb
| |
| \---lib
| | heif.lib
| | libde265.lib
| | libx265.lib
| | x265-static.lib
| |
| \---pkgconfig
| libheif.pc
| x265.pc
|
+---include
| | x265.h
| | x265_config.h
| |
| +---libde265
| | de265.h
| |
| \---libheif
| heif.h
|
+---lib
| | heif.lib
| | libde265.lib
| | libx265.lib
| | x265-static.lib
| |
| \---pkgconfig
| libheif.pc
| x265.pc
|
+---share
| +---libde265
| | copyright
| | libde265Config-debug.cmake
| | libde265Config-release.cmake
| | libde265Config.cmake
| | libde265ConfigVersion.cmake
| | vcpkg_abi_info.txt
| |
| +---libheif
| | | copyright
| | | libheif-config-debug.cmake
| | | libheif-config-release.cmake
| | | libheif-config-version.cmake
| | | libheif-config.cmake
| | | vcpkg_abi_info.txt
| | |
| | \---.vs
| | ProjectSettings.json
| | slnx.sqlite
| |
| \---x265
| copyright
| vcpkg_abi_info.txt
|
\---tools
+---libde265
| dec265.exe
| enc265.exe
| libde265.dll
|
\---x265
x265.exe
(There were more headers, I removed them because one illustrates the point) I put folder libheif in my external folder in my project. Then in CMakeLists.txt I have tried using
target_link_libraries(my_project ${CMAKE_SOURCE_DIR}/external/libheif/lib/heif)
that then fails looking for heif.obj file that is not there. It does find the dlls though.
After that failed, I tried again, this time using the .cmake files in the share directory:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/external/libheif/share/libheif)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/external/libheif/share/libde265)
include(libheif-config)
include(libde265Config)
This I get unresolved external symbol when trying to use anything in libheif.
Attempt #2:
I tried including libeheif by adding it as a submodule git submodule add https://github.com/strukturag/libheif.git external/libheif
and then in CMakeLists.txt I added:
include_directories(external/libheif/include)
include_directories(external/libheif/include/libheif)
include_directories(external/libheif/include/libde265)
add_subdirectory(external/libheif)
target_link_libraries(my_project libheif)
This results in unresolved external symbols whenever I try to use anything in the libheif library.
Other information
The only successful thing I have been able to do is include the headers directory so intellisence recognizes when I #include <heif.h>
I have looked all over on how to include dll and libraries, but all the results either need me to use the cmake GUI, which I am not sure I can because I'm working on this project with other people and I want to make sure it works on their computer without having to use the cmake GUI.
Same with just using vcpkg to include it, I dont want my teammates to have to use it as well, I need to just use CMakeLists.txt
This tutorial would be helpful but the generate stuff is above my head and I couldnt find what it meant by generate. It might be a rabbit hole I loose a day over.
I am working on Windows 10, I will eventually need to make it so it can build on OSX but I'm just trying to get it to work on windows for now.
I am trying to understand why each of these approaches failed. I would rather go down the path of attempt #2 because I feel like that is better for down the road when I need to make it compile for mac as well. Thank you.
Then in CMakeLists.txt I have tried using:
target_link_libraries(my_project
${CMAKE_SOURCE_DIR}/external/libheif/lib/heif)
I think you should use:
target_link_directories( ${PROJECT_NAME}
PRIVATE ./external/libheif/lib/heif
)
target_link_libraries( ${PROJECT_NAME} PRIVATE
heif
xxx
)
target_link_directories : Add link directories to a target.
Description
I'm currently creating a program that would turn a model from simulink and matlab into an FMU.
As I want to automate the process as much as possible I want to also automate the build process for both an EXE, to extract information in the C-API supplied, and later a DLL for the FMU. My plan was to do this with CMake, which is why I'm here. As I know the layout of the code generation (See further down), I could go ahead and make multiple CMakeLists and just have a part of my python script paste them into their repsective folders. BUT, I wanted to make sure this was the only way of doing it (Multiple CMakeLists) before going ahead.
Question
Is there anyway to only have one CMakeLists with many multiple categories? Do I just include all subfolders that include files with target_include_directories() or have I understood that completely wrong? Is there a way to make target_include_directories() to also include subfolders?
My current directory looks like this:
\---CMakeListExperiment
| main.c
| CMakeLists.txt <--- Is it possible to make this the only CMakeLists?
|
+---R2017b
| |
| |
| +---extern
| | \---include
| | tmwtypes.h
| |
| +---rtw
| | \---c
| | \---src
| | | rt_logging.h
| | | rtw_capi.h
| | | rtw_modelmap_logging.h
| | | rt_logging.c
| | | rt_mxclassid.h
| | | rt_logging_mmi.c
| | | rtw_modelmap.h
| | | rt_logging_mmi.h
| | | rtw_modelmap_utils.c
| | |
| | +---common
| | | rt_main.c
| | |
| | \---ext_mode
| | \---common
| | ext_work.h
| |
| \---simulink
| \---include
| rtw_matlogging.h
| sysran_types.h
| rtw_extmode.h
| sl_sample_time_defs.h
| simstruc_types.h
| sl_types_def.h
| rtw_solver.h
| rtw_continuous.h
|
+---multi_grt_rtw
| rtGetInf.c
| rtwtypes.h
| rt_nonfinite.h
| multiword_types.h
| multi_capi.h
| rtmodel.h
| buildInfo.mat
| defines.txt
| rtGetNaN.h
| builtin_typeid_types.h
| rt_nonfinite.c
| multi_capi.c
| rtGetNaN.c
| multi.h
| multi_capi_host.h
| rtGetInf.h
| multi_private.h
| multi_types.h
| multi_data.c
| multi.c
I'm usually very bad at explaining things, so if there's any confusion let me know. I'm also new to posting at SO, which is why I would love feedback. Cheers
EDIT 1:
I have tried the following CMakeLists. I can get this working if I move all sourcefiles inside "/multi_grt_rtw/, but will fail if these files are in their folders that comes produced by matlab. Fail as in "can't find files".
cmake_minimum_required(VERSION 3.0)
project(hello-vsc C)
file(GLOB_RECURSE SOURCES_NORMAL RELATIVE ${CMAKE_SOURCE_DIR} "multi_grt_rtw/*.c")
file(GLOB_RECURSE SOURCES_MATLAB RELATIVE ${CMAKE_SOURCE_DIR} "R2017b/*.c")
set(SOURCE main.c)
include_directories(${CMAKE_SOURCE_DIR}/multi_grt_rtw)
include_directories(${CMAKE_SOURCE_DIR}/R2017b)
add_executable(main ${SOURCE} ${SOURCES_NORMAL} ${SOURCES_MATLAB})
My guess is that include_directories is not recursive (Not searching subdirectories for sourcefiles), so my question is if there's any way to do that? Make include_directories recursive?
The other two, in theory?, working options are
A) As everything is always produced the same, write all CMakeLists needed and copy them, with a script, to correct folder during execution.
B) Add multiple include_directories() to main directory CMakeLists
Now when I have had some time away from work, I guess my question is a bit weird. But it would still be intresting finding out if include_directories() could be used in the way I want it to be, as I can't find much information about it.
I'm considering aerospike for one of our projects. So I currently created a 3 node cluster and loaded some data on it.
Sample data
ns: imei
set: imei_data
+-------------------+-----------------------+-----------------------+----------------------------+--------------+--------------+
| imsi | fcheck | lcheck | msc | fcheck_epoch | lcheck_epoch |
+-------------------+-----------------------+-----------------------+----------------------------+--------------+--------------+
| "413010324064956" | "2017-03-01 14:30:26" | "2017-03-01 14:35:30" | "13d20b080011044917004100" | 1488358826 | 1488359130 |
| "413012628090023" | "2016-09-21 10:06:49" | "2017-09-16 13:54:40" | "13dc0b080011044917006100" | 1474432609 | 1505550280 |
| "413010130130320" | "2016-12-29 22:05:07" | "2017-10-09 16:17:10" | "13d20b080011044917003100" | 1483029307 | 1507546030 |
| "413011330114274" | "2016-09-06 01:48:06" | "2017-10-09 11:53:41" | "13d20b080011044917003100" | 1473106686 | 1507530221 |
| "413012629781993" | "2017-08-16 16:03:01" | "2017-09-13 18:10:48" | "13dc0b080011044917004100" | 1502879581 | 1505306448 |
Then I created a secondary index on lcheck_epoch using AQL since I want to query based on date.
create index idx_lcheck on imei.imei_data (lcheck_epoch) NUMERIC
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
| ns | bin | indextype | set | state | indexname | path | type |
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
| "imei" | "lcheck_epoch" | "NONE" | "imei_data" | "RW" | "idx_lcheck" | "lcheck_epoch" | "NUMERIC" |
+--------+----------------+-----------+-------------+-------+--------------+----------------+-----------+
When I execute
select imsi from imei.imei_data where idx_lcheck=1476165806
I'm getting
Error: (204) AEROSPIKE_ERR_INDEX
Please explain.
You're using the index name, not the bin name, in your query. Try this:
SELECT imsi FROM imei.imei_data WHERE lcheck_epoch=1476165806
Or
SELECT imsi FROM imei.imei_data WHERE lcheck_epoch BETWEEN 1490000000 AND 1510000000
Just a note, you can do much more complex queries using predicate filtering through several of the language clients (Java, C, C#, Go). For example the PredExp class of the Java client (see examples.)
I am trying to build a LaTeX document with scons where some of the sources of the PDF target are targets of other builders. This works great until I try to combine that with variant directories. It looks like once I add the variant directory to the SConscript call, all the built sources no longer get scanned properly into the dependency tree for the PDF target.
Am I doing something wrong in my minimal working example to setup this type of build?
>> scons --version
SCons by Steven Knight et al.:
script: v2.5.1.rel_2.5.1:3735:9dc6cee5c168[MODIFIED], 2016/11/03 14:02:02, by bdbaddog on mongodog
engine: v2.5.1.rel_2.5.1:3735:9dc6cee5c168[MODIFIED], 2016/11/03 14:02:02, by bdbaddog on mongodog
engine path: ['/usr/lib/scons/SCons']
Copyright (c) 2001 - 2016 The SCons Foundation
>> tree
.
├── SConstruct
└── src
├── document.tex
├── foo.in
└── SConscript
1 directory, 4 files
>> cat SConstruct
# SConscript('src/SConscript') # <- Works
SConscript('src/SConscript', variant_dir='build', duplicate=0) # <- Error
>> cat src/foo.in
Bar
>> cat src/document.tex
\documentclass{article}
\begin{document}
\input{foo}
\end{document}
>> cat src/SConscript
Command('foo.tex', 'foo.in', Copy('$TARGET', '$SOURCE'))
PDF('document.tex')
>> scons --tree=prune
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cd build && pdflatex -interaction=nonstopmode -recorder document.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(/nfs/msdev/users/bellockk/Development/SConsMakoTeX/SOQ/src/document.tex
LaTeX2e <2016/03/31>
Babel <3.9r> and hyphenation patterns for 3 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)) (./document.aux)
! LaTeX Error: File `foo.tex' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: tex)
Enter file name:
! Emergency stop.
<read *>
l.3 \input{foo}
^^M
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on document.log.
pdflatex returned an error, check the log file
scons: *** [build/document.pdf] Error 1
+-.
+-SConstruct
+-build
| +-src/SConscript
| +-build/document.acn
| | +-build/document.pdf
| | +-src/document.tex
| +-build/document.acr
| | +-[build/document.pdf]
| +-build/document.alg
| | +-[build/document.pdf]
| +-build/document.aux
| | +-[build/document.pdf]
| +-build/document.bbl
| | +-[build/document.pdf]
| +-build/document.bcf
| | +-[build/document.pdf]
| +-build/document.blg
| | +-[build/document.pdf]
| +-build/document.fls
| | +-[build/document.pdf]
| +-build/document.glg
| | +-[build/document.pdf]
| +-build/document.glo
| | +-[build/document.pdf]
| +-build/document.gls
| | +-[build/document.pdf]
| +-build/document.idx
| | +-[build/document.pdf]
| +-build/document.ilg
| | +-[build/document.pdf]
| +-build/document.ind
| | +-[build/document.pdf]
| +-build/document.lof
| | +-[build/document.pdf]
| +-build/document.log
| | +-[build/document.pdf]
| +-build/document.lot
| | +-[build/document.pdf]
| +-build/document.nav
| | +-[build/document.pdf]
| +-build/document.nlg
| | +-[build/document.pdf]
| +-build/document.nlo
| | +-[build/document.pdf]
| +-build/document.nls
| | +-[build/document.pdf]
| +-build/document.out
| | +-[build/document.pdf]
| +-[build/document.pdf]
| +-build/document.snm
| | +-[build/document.pdf]
| +-build/document.synctex.gz
| | +-[build/document.pdf]
| +-src/document.tex
| +-build/document.toc
| | +-[build/document.pdf]
| +-src/foo.in
| +-build/foo.tex
| +-src/foo.in
+-src
+-src/SConscript
+-src/document.tex
+-src/foo.in
scons: building terminated because of errors.
All of my projects have the following structure tree:
project
|----utils
| |----util_1
| | |----inc_directory(hpp files inside)
| | |----src_directory(cpp files inside)
| ..........
| ..........
| |----util_n
| | |----inc_directory(hpp files inside)
| | |----src_directory(cpp files inside)
|
|----main.cpp
|----CMakeLists.txt
I want to write a generic CMakeLists.txt file that will allow me to compile any project which has the same structure.