Skip to content

Commit d3cd4f3

Browse files
authored
Merge pull request #210 from ferdnyc/cmake-version
Cmake 3.1+ project updates (and 3.12+ SWIG build fixes)
2 parents 4c5851d + 42e2c99 commit d3cd4f3

File tree

7 files changed

+286
-70
lines changed

7 files changed

+286
-70
lines changed

CMakeLists.txt

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#
55
# @section LICENSE
66
#
7-
# Copyright (c) 2008-2014 OpenShot Studios, LLC
7+
# Copyright (c) 2008-2019 OpenShot Studios, LLC
88
# <http://www.openshotstudios.com/>. This file is part of
9-
# OpenShot Library (libopenshot), an open-source project dedicated to
10-
# delivering high quality video editing and animation solutions to the
9+
# OpenShot Library (libopenshot), an open-source project dedicated to
10+
# delivering high quality video editing and animation solutions to the
1111
# world. For more information visit <http://www.openshot.org/>.
1212
#
1313
# OpenShot Library (libopenshot) is free software: you can redistribute it
@@ -24,24 +24,29 @@
2424
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
2525
################################################################################
2626

27-
cmake_minimum_required(VERSION 2.8.11)
27+
cmake_minimum_required(VERSION 3.1...3.14 FATAL_ERROR)
2828

29-
MESSAGE("--------------------------------------------------------------")
30-
MESSAGE("Welcome to the OpenShot Build System! CMake will now check for all required build")
31-
MESSAGE("dependencies and notify you of any missing files or other issues. If you have any")
32-
MESSAGE("questions or issues, please visit <http://www.openshot.org/>.")
29+
message("\
30+
-----------------------------------------------------------------
31+
Welcome to the OpenShot Build System!
32+
33+
CMake will now check libopenshot's build dependencies and inform
34+
you of any missing files or other issues.
35+
36+
For more information, please visit <http://www.openshot.org/>.
37+
-----------------------------------------------------------------")
3338

3439
################ ADD CMAKE MODULES ##################
3540
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
3641

3742
################ GET VERSION INFORMATION FROM VERSION.H ##################
38-
MESSAGE("--------------------------------------------------------------")
39-
MESSAGE("Determining Version Number (from Version.h file)")
43+
message(STATUS "Determining Version Number (from Version.h file)")
4044

4145
#### Get the lines related to libopenshot version from the Version.h header
42-
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/include/Version.h OPENSHOT_VERSION_LINES
43-
REGEX "#define[ ]+OPENSHOT_VERSION_.*[0-9]+;.*")
44-
46+
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/include/Version.h
47+
OPENSHOT_VERSION_LINES
48+
REGEX "#define[ ]+OPENSHOT_VERSION_.*[0-9]+;.*")
49+
4550
#### Set each line into it's own variable
4651
list (GET OPENSHOT_VERSION_LINES 0 LINE_MAJOR)
4752
list (GET OPENSHOT_VERSION_LINES 1 LINE_MINOR)
@@ -53,22 +58,27 @@ STRING(REGEX REPLACE "#define[ ]+OPENSHOT_VERSION_MAJOR[ ]+([0-9]+);(.*)" "\\1"
5358
STRING(REGEX REPLACE "#define[ ]+OPENSHOT_VERSION_MINOR[ ]+([0-9]+);(.*)" "\\1" MINOR_VERSION "${LINE_MINOR}")
5459
STRING(REGEX REPLACE "#define[ ]+OPENSHOT_VERSION_BUILD[ ]+([0-9]+);(.*)" "\\1" BUILD_VERSION "${LINE_BUILD}")
5560
STRING(REGEX REPLACE "#define[ ]+OPENSHOT_VERSION_SO[ ]+([0-9]+);(.*)" "\\1" SO_VERSION "${LINE_SO}")
56-
set(PROJECT_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${BUILD_VERSION}")
5761

58-
MESSAGE("--> MAJOR Version: ${MAJOR_VERSION}")
59-
MESSAGE("--> MINOR Version: ${MINOR_VERSION}")
60-
MESSAGE("--> BUILD Version: ${BUILD_VERSION}")
61-
MESSAGE("--> SO/API/ABI Version: ${SO_VERSION}")
62-
MESSAGE("--> VERSION: ${PROJECT_VERSION}")
63-
MESSAGE("")
62+
message(STATUS "MAJOR Version: ${MAJOR_VERSION}")
63+
message(STATUS "MINOR Version: ${MINOR_VERSION}")
64+
message(STATUS "BUILD Version: ${BUILD_VERSION}")
65+
message(STATUS "SO/API/ABI Version: ${SO_VERSION}")
66+
message(STATUS "Determining Version Number - done")
6467

6568
################### SETUP PROJECT ###################
66-
PROJECT(openshot)
67-
MESSAGE("--------------------------------------------------------------")
68-
MESSAGE("Generating build files for ${PROJECT_NAME} (${PROJECT_VERSION})")
69+
PROJECT(libopenshot LANGUAGES C CXX
70+
VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${BUILD_VERSION})
71+
72+
message("
73+
Generating build files for OpenShot
74+
Building ${PROJECT_NAME} (version ${PROJECT_VERSION})
75+
SO/API/ABI Version: ${SO_VERSION}
76+
")
6977

7078
#### Enable C++11 (for std::shared_ptr support)
71-
set(CMAKE_CXX_FLAGS "-std=c++11")
79+
set(CMAKE_CXX_STANDARD 11)
80+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
81+
set(CMAKE_CXX_EXTENSIONS OFF)
7282

7383
IF (WIN32)
7484
SET_PROPERTY(GLOBAL PROPERTY WIN32 "WIN32")

cmake/Modules/UseDoxygen.cmake

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
1-
# - Run Doxygen
1+
# Redistribution and use is allowed according to the terms of the New
2+
# BSD license:
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions
6+
# are met:
7+
#
8+
# 1. Redistributions of source code must retain the copyright
9+
# notice, this list of conditions and the following disclaimer.
10+
# 2. Redistributions in binary form must reproduce the copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# 3. The name of the author may not be used to endorse or promote products
14+
# derived from this software without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18+
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19+
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21+
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25+
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
# - Run Doxygen
228
#
329
# Adds a doxygen target that runs doxygen to generate the html
430
# and optionally the LaTeX API documentation.
@@ -48,7 +74,6 @@
4874
#
4975
# Redistribution and use is allowed according to the terms of the New
5076
# BSD license.
51-
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
5277
#
5378

5479
macro(usedoxygen_set_default name value type docstring)
@@ -134,7 +159,9 @@ if(DOXYGEN_FOUND AND DOXYFILE_IN_FOUND)
134159

135160
configure_file("${DOXYFILE_IN}" "${DOXYFILE}" @ONLY)
136161

137-
get_target_property(DOC_TARGET doc TYPE)
162+
if(TARGET doc)
163+
get_target_property(DOC_TARGET doc TYPE)
164+
endif()
138165
if(NOT DOC_TARGET)
139166
add_custom_target(doc)
140167
endif()

src/bindings/python/CMakeLists.txt

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#
77
# Copyright (c) 2008-2014 OpenShot Studios, LLC
88
# <http://www.openshotstudios.com/>. This file is part of
9-
# OpenShot Library (libopenshot), an open-source project dedicated to
10-
# delivering high quality video editing and animation solutions to the
9+
# OpenShot Library (libopenshot), an open-source project dedicated to
10+
# delivering high quality video editing and animation solutions to the
1111
# world. For more information visit <http://www.openshot.org/>.
1212
#
1313
# OpenShot Library (libopenshot) is free software: you can redistribute it
@@ -29,37 +29,60 @@
2929
FIND_PACKAGE(SWIG 2.0 REQUIRED)
3030
INCLUDE(${SWIG_USE_FILE})
3131

32+
### Enable some legacy SWIG behaviors, in newer CMAKEs
33+
if (CMAKE_VERSION VERSION_GREATER 3.13)
34+
cmake_policy(SET CMP0078 OLD)
35+
endif()
36+
if (CMAKE_VERSION VERSION_GREATER 3.14)
37+
cmake_policy(SET CMP0086 OLD)
38+
endif()
39+
3240
FIND_PACKAGE(PythonLibs 3)
3341
FIND_PACKAGE(PythonInterp 3)
34-
IF (PYTHONLIBS_FOUND)
35-
IF (PYTHONINTERP_FOUND)
42+
if (PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
43+
44+
### Include Python header files
45+
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
46+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
47+
48+
### Enable C++ support in SWIG
49+
set_property(SOURCE openshot.i PROPERTY CPLUSPLUS ON)
50+
set_property(SOURCE openshot.i PROPERTY SWIG_MODULE_NAME openshot)
51+
SET(CMAKE_SWIG_FLAGS "")
52+
53+
### Add the SWIG interface file (which defines all the SWIG methods)
54+
if (CMAKE_VERSION VERSION_LESS 3.8.0)
55+
swig_add_module(pyopenshot python openshot.i)
56+
else()
57+
swig_add_library(pyopenshot LANGUAGE python SOURCES openshot.i)
58+
endif()
59+
60+
### Set output name of target
61+
set_target_properties(${SWIG_MODULE_pyopenshot_REAL_NAME} PROPERTIES
62+
PREFIX "_" OUTPUT_NAME "openshot")
3663

37-
### Include Python header files
38-
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
39-
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
40-
41-
### Enable C++ support in SWIG
42-
SET_SOURCE_FILES_PROPERTIES(openshot.i PROPERTIES CPLUSPLUS ON)
43-
SET(CMAKE_SWIG_FLAGS "")
44-
45-
### Add the SWIG interface file (which defines all the SWIG methods)
46-
SWIG_ADD_MODULE(openshot python openshot.i)
64+
### Link the new python wrapper library with libopenshot
65+
target_link_libraries(${SWIG_MODULE_pyopenshot_REAL_NAME}
66+
${PYTHON_LIBRARIES} openshot)
4767

48-
### Link the new python wrapper library with libopenshot
49-
SWIG_LINK_LIBRARIES(openshot ${PYTHON_LIBRARIES} openshot)
68+
### FIND THE PYTHON INTERPRETER (AND THE SITE PACKAGES FOLDER)
69+
execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "\
70+
from distutils.sysconfig import get_python_lib; \
71+
print( get_python_lib( plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}' ) )"
72+
OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
73+
OUTPUT_STRIP_TRAILING_WHITESPACE )
5074

51-
### FIND THE PYTHON INTERPRETER (AND THE SITE PACKAGES FOLDER)
52-
EXECUTE_PROCESS ( COMMAND ${PYTHON_EXECUTABLE} -c "import site; print(site.getsitepackages()[0])"
53-
OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
54-
OUTPUT_STRIP_TRAILING_WHITESPACE )
55-
GET_FILENAME_COMPONENT(_ABS_PYTHON_MODULE_PATH "${_ABS_PYTHON_MODULE_PATH}" ABSOLUTE)
56-
FILE(RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH})
57-
SET(PYTHON_MODULE_PATH ${_REL_PYTHON_MODULE_PATH})
75+
GET_FILENAME_COMPONENT(_ABS_PYTHON_MODULE_PATH
76+
"${_ABS_PYTHON_MODULE_PATH}" ABSOLUTE)
77+
FILE(RELATIVE_PATH _REL_PYTHON_MODULE_PATH
78+
${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH})
79+
SET(PYTHON_MODULE_PATH ${_REL_PYTHON_MODULE_PATH})
5880

59-
############### INSTALL HEADERS & LIBRARY ################
60-
### Install Python bindings
61-
INSTALL(TARGETS _openshot DESTINATION ${PYTHON_MODULE_PATH} )
62-
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/openshot.py DESTINATION ${PYTHON_MODULE_PATH} )
81+
############### INSTALL HEADERS & LIBRARY ################
82+
### Install Python bindings
83+
INSTALL(TARGETS ${SWIG_MODULE_pyopenshot_REAL_NAME}
84+
LIBRARY DESTINATION ${PYTHON_MODULE_PATH} )
85+
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/openshot.py
86+
DESTINATION ${PYTHON_MODULE_PATH} )
6387

64-
ENDIF(PYTHONINTERP_FOUND)
65-
ENDIF (PYTHONLIBS_FOUND)
88+
endif ()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
####################### CMakeLists.txt (libopenshot) #########################
2+
# @brief CMake build file for libopenshot (used to generate Python SWIG bindings)
3+
# @author Jonathan Thomas <[email protected]>
4+
#
5+
# @section LICENSE
6+
#
7+
# Copyright (c) 2008-2014 OpenShot Studios, LLC
8+
# <http://www.openshotstudios.com/>. This file is part of
9+
# OpenShot Library (libopenshot), an open-source project dedicated to
10+
# delivering high quality video editing and animation solutions to the
11+
# world. For more information visit <http://www.openshot.org/>.
12+
#
13+
# OpenShot Library (libopenshot) is free software: you can redistribute it
14+
# and/or modify it under the terms of the GNU Lesser General Public License
15+
# as published by the Free Software Foundation, either version 3 of the
16+
# License, or (at your option) any later version.
17+
#
18+
# OpenShot Library (libopenshot) is distributed in the hope that it will be
19+
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
# GNU Lesser General Public License for more details.
22+
#
23+
# You should have received a copy of the GNU Lesser General Public License
24+
# along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
25+
################################################################################
26+
27+
28+
############### SWIG PYTHON BINDINGS ################
29+
FIND_PACKAGE(SWIG 2.0 REQUIRED)
30+
INCLUDE(${SWIG_USE_FILE})
31+
32+
FIND_PACKAGE(PythonLibs 3)
33+
FIND_PACKAGE(PythonInterp 3)
34+
if (PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
35+
36+
### Include Python header files
37+
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
38+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
39+
40+
### Enable C++ support in SWIG
41+
set_property(SOURCE openshot.i PROPERTY CPLUSPLUS ON)
42+
set_property(SOURCE openshot.i PROPERTY SWIG_MODULE_NAME openshot)
43+
SET(CMAKE_SWIG_FLAGS "")
44+
45+
### Add the SWIG interface file (which defines all the SWIG methods)
46+
swig_add_library(pyopenshot LANGUAGE python SOURCES openshot.i)
47+
48+
### Set output name of target
49+
set_target_properties(${SWIG_MODULE_pyopenshot_REAL_NAME} PROPERTIES
50+
PREFIX "_" OUTPUT_NAME "openshot")
51+
52+
### Link the new python wrapper library with libopenshot
53+
target_link_libraries(${SWIG_MODULE_pyopenshot_REAL_NAME} ${PYTHON_LIBRARIES} openshot)
54+
55+
### FIND THE PYTHON INTERPRETER (AND THE SITE PACKAGES FOLDER)
56+
execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c
57+
"from distutils.sysconfig import get_python_lib; print( get_python_lib( plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}' ) )"
58+
OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
59+
OUTPUT_STRIP_TRAILING_WHITESPACE )
60+
61+
GET_FILENAME_COMPONENT(_ABS_PYTHON_MODULE_PATH "${_ABS_PYTHON_MODULE_PATH}" ABSOLUTE)
62+
FILE(RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH})
63+
SET(PYTHON_MODULE_PATH ${_REL_PYTHON_MODULE_PATH})
64+
65+
############### INSTALL HEADERS & LIBRARY ################
66+
### Install Python bindings
67+
INSTALL(TARGETS ${SWIG_MODULE_pyopenshot_REAL_NAME}
68+
LIBRARY DESTINATION ${PYTHON_MODULE_PATH} )
69+
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/openshot.py
70+
DESTINATION ${PYTHON_MODULE_PATH} )
71+
72+
endif ()

src/bindings/ruby/CMakeLists.txt

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#
77
# Copyright (c) 2008-2014 OpenShot Studios, LLC
88
# <http://www.openshotstudios.com/>. This file is part of
9-
# OpenShot Library (libopenshot), an open-source project dedicated to
10-
# delivering high quality video editing and animation solutions to the
9+
# OpenShot Library (libopenshot), an open-source project dedicated to
10+
# delivering high quality video editing and animation solutions to the
1111
# world. For more information visit <http://www.openshot.org/>.
1212
#
1313
# OpenShot Library (libopenshot) is free software: you can redistribute it
@@ -29,35 +29,53 @@
2929
FIND_PACKAGE(SWIG 2.0 REQUIRED)
3030
INCLUDE(${SWIG_USE_FILE})
3131

32+
### Enable some legacy SWIG behaviors, in newer CMAKEs
33+
if (CMAKE_VERSION VERSION_GREATER 3.13)
34+
cmake_policy(SET CMP0078 OLD)
35+
endif()
36+
if (CMAKE_VERSION VERSION_GREATER 3.14)
37+
cmake_policy(SET CMP0086 OLD)
38+
endif()
39+
3240
FIND_PACKAGE(Ruby)
3341
IF (RUBY_FOUND)
3442

3543
### Include the Ruby header files
3644
INCLUDE_DIRECTORIES(${RUBY_INCLUDE_DIRS})
3745
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
38-
46+
3947
### Enable C++ in SWIG
40-
SET_SOURCE_FILES_PROPERTIES(openshot.i PROPERTIES CPLUSPLUS ON)
48+
set_property(SOURCE openshot.i PROPERTY CPLUSPLUS ON)
49+
set_property(SOURCE openshot.i PROPERTY SWIG_MODULE_NAME openshot)
50+
4151
SET(CMAKE_SWIG_FLAGS "")
4252

4353
### Add the SWIG interface file (which defines all the SWIG methods)
44-
SWIG_ADD_MODULE(rbopenshot ruby openshot.i)
45-
54+
if (CMAKE_VERSION VERSION_LESS 3.8.0)
55+
swig_add_module(rbopenshot ruby openshot.i)
56+
else()
57+
swig_add_library(rbopenshot LANGUAGE ruby SOURCES openshot.i)
58+
endif()
59+
4660
### Set name of target (with no prefix, since Ruby does not like that)
47-
SET_TARGET_PROPERTIES(rbopenshot PROPERTIES PREFIX "" OUTPUT_NAME "openshot")
61+
SET_TARGET_PROPERTIES(${SWIG_MODULE_rbopenshot_REAL_NAME} PROPERTIES
62+
PREFIX "" OUTPUT_NAME "openshot")
4863

4964
### Link the new Ruby wrapper library with libopenshot
50-
SWIG_LINK_LIBRARIES(rbopenshot ${RUBY_LIBRARY} openshot)
51-
65+
target_link_libraries(${SWIG_MODULE_rbopenshot_REAL_NAME}
66+
${RUBY_LIBRARY} openshot)
67+
5268
### FIND THE RUBY INTERPRETER (AND THE LOAD_PATH FOLDER)
53-
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['vendorarchdir']" OUTPUT_VARIABLE RUBY_VENDOR_ARCH_DIR)
69+
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE}
70+
-r rbconfig -e "print RbConfig::CONFIG['vendorarchdir']"
71+
OUTPUT_VARIABLE RUBY_VENDOR_ARCH_DIR)
5472
MESSAGE(STATUS "Ruby executable: ${RUBY_EXECUTABLE}")
5573
MESSAGE(STATUS "Ruby vendor arch dir: ${RUBY_VENDOR_ARCH_DIR}")
5674
MESSAGE(STATUS "Ruby include path: ${RUBY_INCLUDE_PATH}")
57-
5875

5976
############### INSTALL HEADERS & LIBRARY ################
6077
# Install Ruby bindings
61-
INSTALL(TARGETS rbopenshot LIBRARY DESTINATION ${RUBY_VENDOR_ARCH_DIR})
62-
78+
install(TARGETS ${SWIG_MODULE_rbopenshot_REAL_NAME}
79+
LIBRARY DESTINATION ${RUBY_VENDOR_ARCH_DIR} )
80+
6381
ENDIF (RUBY_FOUND)

0 commit comments

Comments
 (0)