Skip to content

Commit 750677c

Browse files
committed
CMake: Manage sources and includes better
- Switch to AUTOMOC for Qt classes - Eliminate globbing of source subdirs - Call `include_directories()` in top-level CMakeLists - Make header files PUBLIC library sources - Make other sources PRIVATE
1 parent 42daa20 commit 750677c

File tree

4 files changed

+107
-94
lines changed

4 files changed

+107
-94
lines changed

CMakeLists.txt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ configure_file(include/OpenShotVersion.h.in include/OpenShotVersion.h @ONLY)
7272
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/OpenShotVersion.h
7373
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libopenshot)
7474

75-
############### Set up include paths #################
76-
list(APPEND OPENSHOT_INCLUDE_DIRS
77-
${CMAKE_CURRENT_SOURCE_DIR}/include
78-
${CMAKE_CURRENT_SOURCE_DIR}/include/effects
79-
${CMAKE_CURRENT_SOURCE_DIR}/include/Qt
80-
${CMAKE_CURRENT_BINARY_DIR}/include )
81-
8275
#### Enable C++11 (for std::shared_ptr support)
8376
set(CMAKE_CXX_STANDARD 11)
8477
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -88,9 +81,9 @@ IF (WIN32)
8881
SET_PROPERTY(GLOBAL PROPERTY WIN32 "WIN32")
8982
ENDIF(WIN32)
9083

91-
############## FIND ALL QT RELATED HEADERS ##############
92-
set(QT_HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/Qt)
93-
FILE(GLOB QT_HEADER_FILES "${QT_HEADER_DIR}/*.h")
84+
include_directories(
85+
${CMAKE_CURRENT_SOURCE_DIR}/include
86+
${CMAKE_CURRENT_BINARY_DIR}/include)
9487

9588
############## PROCESS src/ DIRECTORIES ##############
9689
add_subdirectory(src)

src/CMakeLists.txt

Lines changed: 104 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
2525
################################################################################
2626

27-
# Pick up our include directories from the parent context
28-
include_directories(${OPENSHOT_INCLUDE_DIRS})
29-
30-
####### Display summary of options/dependencies ######
27+
# Collect and display summary of options/dependencies
3128
include(FeatureSummary)
3229

3330
################ OPTIONS ##################
@@ -36,6 +33,9 @@ option(USE_SYSTEM_JSONCPP "Use system installed JsonCpp, if found" ON)
3633
option(DISABLE_BUNDLED_JSONCPP "Don't fall back to bundled JsonCpp" OFF)
3734
option(ENABLE_IWYU "Enable 'Include What You Use' scanner (CMake 3.3+)" OFF)
3835

36+
# Automatically process Qt classes with meta-object compiler
37+
set(CMAKE_AUTOMOC True)
38+
3939
################ WINDOWS ##################
4040
# Set some compiler options for Windows
4141
# required for libopenshot-audio headers
@@ -90,9 +90,6 @@ FIND_PACKAGE(OpenShotAudio 0.1.8 REQUIRED)
9090
# Include Juce headers (needed for compile)
9191
include_directories(${LIBOPENSHOT_AUDIO_INCLUDE_DIRS})
9292

93-
# Manually moc Qt files
94-
qt5_wrap_cpp(MOC_FILES ${QT_HEADER_FILES})
95-
9693
################# BLACKMAGIC DECKLINK ###################
9794
# Find BlackMagic DeckLinkAPI libraries
9895
IF (ENABLE_BLACKMAGIC)
@@ -147,73 +144,71 @@ if(ENABLE_IWYU)
147144
endif()
148145
add_feature_info("IWYU (include-what-you-use)" ENABLE_IWYU "Scan all source files with 'iwyu'")
149146

150-
#### GET LIST OF EFFECT FILES ####
151-
FILE(GLOB EFFECT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/effects/*.cpp")
152-
153-
#### GET LIST OF QT PLAYER FILES ####
154-
FILE(GLOB QT_PLAYER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Qt/*.cpp")
155-
156-
############### SET LIBRARY SOURCE FILES #################
157-
SET ( OPENSHOT_SOURCE_FILES
158-
AudioBufferSource.cpp
159-
AudioReaderSource.cpp
160-
AudioResampler.cpp
161-
CacheBase.cpp
162-
CacheDisk.cpp
163-
CacheMemory.cpp
164-
ChunkReader.cpp
165-
ChunkWriter.cpp
166-
Color.cpp
167-
Clip.cpp
168-
ClipBase.cpp
169-
Coordinate.cpp
170-
CrashHandler.cpp
171-
DummyReader.cpp
172-
ReaderBase.cpp
173-
RendererBase.cpp
174-
WriterBase.cpp
175-
EffectBase.cpp
176-
${EFFECT_FILES}
177-
EffectInfo.cpp
178-
FFmpegReader.cpp
179-
FFmpegWriter.cpp
180-
Fraction.cpp
181-
Frame.cpp
182-
FrameMapper.cpp
183-
KeyFrame.cpp
184-
OpenShotVersion.cpp
185-
ZmqLogger.cpp
186-
PlayerBase.cpp
187-
Point.cpp
188-
Profiles.cpp
189-
QtImageReader.cpp
190-
QtPlayer.cpp
191-
Settings.cpp
192-
Timeline.cpp
193-
QtTextReader.cpp
194-
QtHtmlReader.cpp
195-
196-
197-
# Qt Video Player
198-
${QT_PLAYER_FILES}
199-
${MOC_FILES})
200-
201-
# ImageMagic related files
202-
IF (ImageMagick_FOUND)
203-
SET ( OPENSHOT_SOURCE_FILES ${OPENSHOT_SOURCE_FILES}
204-
ImageReader.cpp
205-
ImageWriter.cpp
206-
TextReader.cpp)
207-
ENDIF (ImageMagick_FOUND)
208-
209-
# BlackMagic related files
210-
IF (BLACKMAGIC_FOUND)
211-
SET ( OPENSHOT_SOURCE_FILES ${OPENSHOT_SOURCE_FILES}
212-
DecklinkInput.cpp
213-
DecklinkReader.cpp
214-
DecklinkOutput.cpp
215-
DecklinkWriter.cpp)
216-
ENDIF (BLACKMAGIC_FOUND)
147+
# Main library sources
148+
set(OPENSHOT_SOURCES
149+
AudioBufferSource.cpp
150+
AudioReaderSource.cpp
151+
AudioResampler.cpp
152+
CacheBase.cpp
153+
CacheDisk.cpp
154+
CacheMemory.cpp
155+
ChunkReader.cpp
156+
ChunkWriter.cpp
157+
Color.cpp
158+
Clip.cpp
159+
ClipBase.cpp
160+
Coordinate.cpp
161+
CrashHandler.cpp
162+
DummyReader.cpp
163+
ReaderBase.cpp
164+
RendererBase.cpp
165+
WriterBase.cpp
166+
EffectBase.cpp
167+
EffectInfo.cpp
168+
FFmpegReader.cpp
169+
FFmpegWriter.cpp
170+
Fraction.cpp
171+
Frame.cpp
172+
FrameMapper.cpp
173+
KeyFrame.cpp
174+
OpenShotVersion.cpp
175+
ZmqLogger.cpp
176+
PlayerBase.cpp
177+
Point.cpp
178+
Profiles.cpp
179+
QtHtmlReader.cpp
180+
QtImageReader.cpp
181+
QtPlayer.cpp
182+
QtTextReader.cpp
183+
Settings.cpp
184+
Timeline.cpp)
185+
186+
# Video effects
187+
set(EFFECTS_SOURCES
188+
effects/Bars.cpp
189+
effects/Blur.cpp
190+
effects/Brightness.cpp
191+
effects/ChromaKey.cpp
192+
effects/ColorShift.cpp
193+
effects/Crop.cpp
194+
effects/Deinterlace.cpp
195+
effects/Hue.cpp
196+
effects/Mask.cpp
197+
effects/Negate.cpp
198+
effects/Pixelate.cpp
199+
effects/Saturation.cpp
200+
effects/Shift.cpp
201+
effects/Wave.cpp)
202+
203+
# Qt video player components
204+
set(QT_PLAYER_SOURCES
205+
Qt/AudioPlaybackThread.cpp
206+
Qt/PlayerDemo.cpp
207+
Qt/PlayerPrivate.cpp
208+
Qt/VideoCacheThread.cpp
209+
Qt/VideoPlaybackThread.cpp
210+
Qt/VideoRenderer.cpp
211+
Qt/VideoRenderWidget.cpp)
217212

218213

219214
# Get list of headers
@@ -224,9 +219,13 @@ SET(CMAKE_MACOSX_RPATH 0)
224219

225220
############### CREATE LIBRARY #################
226221
# Create shared openshot library
227-
add_library(openshot SHARED
228-
${OPENSHOT_SOURCE_FILES}
229-
${headers} )
222+
add_library(openshot SHARED)
223+
224+
target_sources(openshot
225+
PRIVATE
226+
${OPENSHOT_SOURCES} ${EFFECTS_SOURCES} ${QT_PLAYER_SOURCES}
227+
PUBLIC
228+
${headers})
230229

231230
# Set SONAME and other library properties
232231
set_target_properties(openshot
@@ -236,6 +235,34 @@ set_target_properties(openshot
236235
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
237236
)
238237

238+
# Add optional ImageMagic-dependent sources
239+
if(ImageMagick_FOUND)
240+
target_sources(openshot PRIVATE
241+
ImageReader.cpp
242+
ImageWriter.cpp
243+
TextReader.cpp)
244+
endif()
245+
246+
# BlackMagic related files
247+
if(BLACKMAGIC_FOUND)
248+
target_sources(openshot PRIVATE
249+
DecklinkInput.cpp
250+
DecklinkReader.cpp
251+
DecklinkOutput.cpp
252+
DecklinkWriter.cpp)
253+
endif()
254+
255+
# Location of our includes, both internally and when installed
256+
target_include_directories(openshot
257+
PRIVATE
258+
${CMAKE_SOURCE_DIR}/include
259+
${CMAKE_BINARY_DIR}/include
260+
PUBLIC
261+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
262+
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
263+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libopenshot>)
264+
265+
239266
################### JSONCPP #####################
240267
# Include jsoncpp headers (needed for JSON parsing)
241268
if (USE_SYSTEM_JSONCPP)
@@ -342,7 +369,6 @@ endif()
342369
############### LINK LIBRARY #################
343370
SET ( REQUIRED_LIBRARIES
344371
${LIBOPENSHOT_AUDIO_LIBRARIES}
345-
${QT_LIBRARIES}
346372
${PROFILER}
347373
)
348374

src/bindings/ruby/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
2525
################################################################################
2626

27-
# Pick up our include directories from the parent context
28-
include_directories(${OPENSHOT_INCLUDE_DIRS})
29-
3027
############### RUBY BINDINGS ################
3128
FIND_PACKAGE(SWIG 3.0 REQUIRED)
3229
INCLUDE(${SWIG_USE_FILE})

tests/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
2525
################################################################################
2626

27-
# Pick up our include directories from the parent context
28-
include_directories(${OPENSHOT_INCLUDE_DIRS})
29-
3027
SET(TEST_MEDIA_PATH "${PROJECT_SOURCE_DIR}/src/examples/")
3128

3229
################ WINDOWS ##################

0 commit comments

Comments
 (0)