Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using libopenshot in C++ CMake project #72

Closed
federicomassa opened this issue Dec 14, 2017 · 4 comments
Closed

Using libopenshot in C++ CMake project #72

federicomassa opened this issue Dec 14, 2017 · 4 comments
Labels
stale This issue has not had any activity in 90 days :(

Comments

@federicomassa
Copy link

federicomassa commented Dec 14, 2017

System Details:

Operating System / Distro: Ubuntu
OpenShot Version: 0.1.8

Issue Description and steps to reproduce:
Sorry for the very basic questions, I am probably missing some basic CMake concept. The issue is pretty simple: I have a C++ CMake project and I want to use Openshot to produce a video.

1)I cannot find a Cmake module to be able to do find_package(openshot). But this is secondary, I have written my finder, but it seems odd to me that it is not already provided in a CMake-based project.
2) Once I find the openshot library, I cannot do #include "OpenShot.h" because it doesn't find the external dependencies (like JuceLibraries/*.h in openshot-audio library). Usually, when I write my own libraries, I solve this just by using target_link_libraries, but this relies on the writer of the library to have defined an include interface in a target_include_directories.

Again, I am probably missing something very easy, so forgive me but as you probably know CMake's documentation really lacks on clarity (in my opinion, at least).

[ 97%] Built target openshot
[ 97%] Building CXX object Tests/HighwayViewer/CMakeFiles/TOpenShot.dir/TOpenShot.cpp.o
In file included from /home/federico-asus/Simulator/LocalMonitor/Tests/HighwayViewer/../../Utility/libopenshot-0.1.8/include/OpenShot.h:99:0,
                 from /home/federico-asus/Simulator/LocalMonitor/Tests/HighwayViewer/TOpenShot.cpp:2:
/home/federico-asus/Simulator/LocalMonitor/Tests/HighwayViewer/../../Utility/libopenshot-0.1.8/include/AudioBufferSource.h:40:40: fatal error: JuceLibraryCode/JuceHeader.h: No such file or directory
compilation terminated.
Tests/HighwayViewer/CMakeFiles/TOpenShot.dir/build.make:62: recipe for target 'Tests/HighwayViewer/CMakeFiles/TOpenShot.dir/TOpenShot.cpp.o' failed
make[3]: *** [Tests/HighwayViewer/CMakeFiles/TOpenShot.dir/TOpenShot.cpp.o] Error 1
CMakeFiles/Makefile2:1321: recipe for target 'Tests/HighwayViewer/CMakeFiles/TOpenShot.dir/all' failed
make[2]: *** [Tests/HighwayViewer/CMakeFiles/TOpenShot.dir/all] Error 2
CMakeFiles/Makefile2:1333: recipe for target 'Tests/HighwayViewer/CMakeFiles/TOpenShot.dir/rule' failed
make[1]: *** [Tests/HighwayViewer/CMakeFiles/TOpenShot.dir/rule] Error 2
Makefile:496: recipe for target 'TOpenShot' failed
make: *** [TOpenShot] Error 2
@DylanC
Copy link

DylanC commented Dec 14, 2017

@jonoomph - Any idea on this one?

@federicomassa
Copy link
Author

NB In #1 it is described a similar problem, but in that case the include issue appears (interestingly on the same Juce header file) already when building libopenshot. In my case, instead, I can build libopenshot, but I cannot use it in a different project.

@federicomassa
Copy link
Author

federicomassa commented Dec 14, 2017

So, I have found a temporary solution which I don't really like because it involves changing your src/CMakeLists.txt file, but it works. Before explaining my solution, I should clarify that I have copied libopenshot into my project and I am building it like it was a module of my own project. However, I think this will work even when libopenshot is normally installed into the system, but I haven't tried it yet because it is not a priority for me.

So, I have just put, for each include_directories(${PATH}) command in src/CMakeLists.txt file, a call to target_include_directories(openshot PUBLIC ${PATH}) at the end of the file (plus another one for ${headers} variable).

target_include_directories(openshot PUBLIC ${ImageMagick_INCLUDE_DIRS})
target_include_directories(openshot PUBLIC ${FFMPEG_INCLUDE_DIR})
target_include_directories(openshot PUBLIC ${LIBOPENSHOT_AUDIO_INCLUDE_DIRS})
target_include_directories(openshot PUBLIC ${Qt5Widgets_INCLUDE_DIRS})
target_include_directories(openshot PUBLIC ${Qt5Core_INCLUDE_DIRS})
target_include_directories(openshot PUBLIC ${Qt5Gui_INCLUDE_DIRS})
target_include_directories(openshot PUBLIC ${Qt5Multimedia_INCLUDE_DIRS})
target_include_directories(openshot PUBLIC ${Qt5MultimediaWidgets_INCLUDE_DIRS})

if (BLACKMAGIC_FOUND)
		# Include headers (needed for compile)
		target_include_directories(openshot PUBLIC ${BLACKMAGIC_INCLUDE_DIR})
endif()

target_include_directories(openshot PUBLIC ${ZMQ_INCLUDE_DIRS})

if (USE_SYSTEM_JSONCPP)
	target_include_directories(openshot PUBLIC ${JSONCPP_INCLUDE_DIRS})
else()
	target_include_directories(openshot PUBLIC ../thirdparty/jsoncpp/include)
endif(USE_SYSTEM_JSONCPP)

target_include_directories(openshot PUBLIC ${headers})

This way, CMake handles the dependencies automatically and I can do, from my libraries, something like:

target_link_libraries(MyProject openshot)
target_include_directories(MyProject PUBLIC ${openshot_INCLUDE_DIR})

(This works in my case because openshot is built inside my project, but in general this should be done after an appopriate find_library/find_path or find_package call)

where you should set openshot_INCLUDE_DIR variable to your own path (possibly just writing a FindOpenShot.cmake module and calling find_package(openshot) ). After this, you should be able to include libopenshot headers simply with #include "OpenShot.h" .

Again, I do not really like this solution, but it's the best I could do to make this work.
Also, instead of just adding at the end of the file target_include_directories like I did, it would be better to find a way to replace the include_directories commands with target_include_directories, but I did not do that because target_include_directories requires the name of the library to be already defined, which is not in this case (at least for the first include_directories calls).

@stale
Copy link

stale bot commented Mar 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale This issue has not had any activity in 90 days :( label Mar 12, 2020
@stale stale bot closed this as completed Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This issue has not had any activity in 90 days :(
Projects
None yet
Development

No branches or pull requests

2 participants