Skip to content

Commit

Permalink
Merge pull request #2604 from madebr/opus_cmake
Browse files Browse the repository at this point in the history
opus: fix cmake_find_package name
  • Loading branch information
SSE4 authored Aug 21, 2020
2 parents 530521c + c4801e5 commit 21642e6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 49 deletions.
6 changes: 3 additions & 3 deletions recipes/opus/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/opus/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ sources:
"1.3.1":
url: "https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz"
sha256: "65b58e1e25b2a114157014736a3d9dfeaad8d41be1c8179866f144a2fb44ff9d"
patches:
"1.3.1":
- patch_file: "patches/1.3.1-add-opus_buildtype-cmake.patch"
base_path: "source_subfolder"
49 changes: 29 additions & 20 deletions recipes/opus/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@ class OpusConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://opus-codec.org"
license = "BSD-3-Clause"
exports_sources = ["CMakeLists.txt","opus_buildtype.cmake"]
exports_sources = "CMakeLists.txt", "patches/**"
generators = "cmake"

settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False], "fixed_point": [True, False]}
default_options = {'shared': False, 'fPIC': True, 'fixed_point': False}
options = {
"shared": [True, False],
"fPIC": [True, False],
"fixed_point": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"fixed_point": False,
}

_source_subfolder = "source_subfolder"
@property
def _source_subfolder(self):
return "source_subfolder"

def configure(self):
del self.settings.compiler.libcxx
Expand All @@ -34,15 +44,9 @@ def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC


def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)

# They forgot to package that file into the tarball for 1.3.1
# See https://github.com/xiph/opus/issues/129
os.rename("opus_buildtype.cmake", os.path.join(self._source_subfolder , "opus_buildtype.cmake"))
os.rename("{}-{}".format(self.name, self.version), self._source_subfolder)

def _configure_cmake(self):
cmake = CMake(self)
Expand All @@ -51,22 +55,27 @@ def _configure_cmake(self):
return cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder, keep_path=False)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, 'lib', 'pkgconfig'))
tools.rmdir(os.path.join(self.package_folder, 'lib', 'cmake'))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.names['cmake_find_package'] = 'Opus'
self.cpp_info.names['cmake_find_package_multi'] = 'Opus'
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == 'Linux' or self.settings.os == "Android":
self.cpp_info.system_libs.append('m')
self.cpp_info.names["cmake_find_package"] = "Opus"
self.cpp_info.names["cmake_find_package_multi"] = "Opus"
self.cpp_info.components["libopus"].libs = ["opus"]
self.cpp_info.components["libopus"].includedirs.append(os.path.join("include", "opus"))
self.cpp_info.components["libopus"].names["cmake_find_package"] = "opus"
self.cpp_info.components["libopus"].names["cmake_find_package_multi"] = "opus"
self.cpp_info.components["libopus"].names["pkg_config"] = "opus"
if self.settings.os == "Linux" or self.settings.os == "Android":
self.cpp_info.components["libopus"].system_libs.append("m")
if self.settings.os == "Windows" and self.settings.compiler != "Visual Studio":
self.cpp_info.system_libs.append("ssp")
self.cpp_info.includedirs.append(os.path.join('include', 'opus'))
self.cpp_info.components["libopus"].system_libs.append("ssp")
23 changes: 0 additions & 23 deletions recipes/opus/all/opus_buildtype.cmake

This file was deleted.

30 changes: 30 additions & 0 deletions recipes/opus/all/patches/1.3.1-add-opus_buildtype-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# They forgot to package that file into the tarball for 1.3.1
# See https://github.com/xiph/opus/issues/129

new file mode 100755
--- /dev/null
+++ opus_buildtype.cmake
@@ -0,0 +1,23 @@
+# Set a default build type if none was specified
+
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ if(CMAKE_C_FLAGS)
+ message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
+ else()
+ set(default_build_type "Release")
+ message(
+ STATUS
+ "Setting build type to '${default_build_type}' as none was specified and no CFLAGS was exported."
+ )
+ set(CMAKE_BUILD_TYPE "${default_build_type}"
+ CACHE STRING "Choose the type of build."
+ FORCE)
+ # Set the possible values of build type for cmake-gui
+ set_property(CACHE CMAKE_BUILD_TYPE
+ PROPERTY STRINGS
+ "Debug"
+ "Release"
+ "MinSizeRel"
+ "RelWithDebInfo")
+ endif()
+endif()
4 changes: 1 addition & 3 deletions recipes/opus/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.1)
project(test_package)

set(CMAKE_VERBOSE_MAKEFILE TRUE)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

Expand Down

0 comments on commit 21642e6

Please sign in to comment.