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.
Related
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?
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.
Having used Eclipse for more years than I care to admit, I'm currently trying to get adjusted to IntelliJ (2016.2, Community) but I'm having a hard time with the totally different UI metaphors/concepts.
I'd like to be able to have a window layout like this:
+--------+------------------------
| | |
| (1) | |
| | |
|+-------+ Source editor |
| | |
| (2) | |
| |-----------------------+
| | |
| | Console output etc. |
+--------+-----------------------+
Luckily, this question helped me with splitting panes to get (1) and (2).
However, I have not been able to find out how to rearrange tool windows so that I can get a (for example) Terminal tool window that is directly underneath the source editor pane, instead of one that looks like this:
+--------+------------------------
| | |
| (1) | |
| | |
|+-------+ Source editor |
| | |
| (2) | |
+--------------------------------+
| |
| Console output etc. |
+--------------------------------+
Open "Settings" > "Appearance & Behavior" > "Appearance" and enable "Widescreen tool window layout".
Tested in DataGrip and PyCharm. Should be exactly the same in IDEA, Webstorm as far as i know - i used them all and the UI is the same everywhere (and i like that).
You could just float the panels next to your IntelliJ main windows like this screenshot.
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.
I have a teambuild setup that builds a solution that has several projects in it. When the build is done all the binaries are lumped in to a single location.
Is there a good way to get these to go in project specific folders? (Similar to what you get when you build in Visual Studio?)
Example:
MySolution
|
+-> Project 1
|
+-> Project 2
|
+-> Project 3
|
+-> Project 4
Right now TeamBuild gives me this by default:
Binaries
|
+-> Project1.exe, Project2.exe, Project3.exe, Project4.exe, Project1Support.dll, Project2Support.dll, Project3Support.dll, Project4Support.dll
What I want is:
Binaires
|
+-> Project 1
| |
| +->Project1.exe
| |
| +->Project1Support.dll
|
+-> Project 2
| |
| +->Project2.exe
| |
| +->Project2Support.dll
|
+-> Project 3
| |
| +->Project3.exe
| |
| +->Project3Support.dll
|
+-> Project 4
|
+->Project4.exe
|
+->Project4Support.dll
Do I have to manually copy each file around? Is there an easier way? (I hope so.)
Aaron Hallberg has a great post on this exact scenario here.
If you're going to be plowing through as much TFSBuild customization as I have done recently, you may want to check out the rest of his blog as well.