Skip to content

Commit

Permalink
Merge pull request #2606 from madebr/flac_cmake
Browse files Browse the repository at this point in the history
flac: fix cmake_find_package name
  • Loading branch information
danimtb authored Aug 21, 2020
2 parents 601299c + 47b08cd commit 1a998dd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
10 changes: 3 additions & 7 deletions recipes/flac/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
else()
include(conanbuildinfo.cmake)
endif()
include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
add_subdirectory(source_subfolder)
37 changes: 26 additions & 11 deletions recipes/flac/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class FlacConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/xiph/flac"
license = ("BSD-3-Clause", "GPL-2.0-or-later", "LPGL-2.1-or-later", "GFDL-1.2")
requires = "ogg/1.3.4"
exports_sources = ['CMakeLists.txt', 'patches/*']
exports_sources = ["CMakeLists.txt", "patches/*"]

generators = "cmake",
settings = "os", "compiler", "build_type", "arch"
Expand All @@ -29,6 +28,9 @@ def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def requirements(self):
self.requires("ogg/1.3.4")

def build_requirements(self):
self.build_requires("nasm/2.14")

Expand All @@ -40,13 +42,13 @@ def source(self):
extracted_dir = "{}-{}".format(self.name, self.version)
os.rename(extracted_dir, self._source_subfolder)
tools.replace_in_file(
os.path.join(self._source_subfolder, 'src', 'libFLAC', 'CMakeLists.txt'),
'target_link_libraries(FLAC PRIVATE $<$<BOOL:${HAVE_LROUND}>:m>)',
'target_link_libraries(FLAC PUBLIC $<$<BOOL:${HAVE_LROUND}>:m>)')
os.path.join(self._source_subfolder, "src", "libFLAC", "CMakeLists.txt"),
"target_link_libraries(FLAC PRIVATE $<$<BOOL:${HAVE_LROUND}>:m>)",
"target_link_libraries(FLAC PUBLIC $<$<BOOL:${HAVE_LROUND}>:m>)")
tools.replace_in_file(
os.path.join(self._source_subfolder, 'CMakeLists.txt'),
'set(CMAKE_EXE_LINKER_FLAGS -no-pie)',
'#set(CMAKE_EXE_LINKER_FLAGS -no-pie)')
os.path.join(self._source_subfolder, "CMakeLists.txt"),
"set(CMAKE_EXE_LINKER_FLAGS -no-pie)",
"#set(CMAKE_EXE_LINKER_FLAGS -no-pie)")

def _configure_cmake(self):
if self._cmake:
Expand All @@ -72,8 +74,21 @@ def package(self):
tools.rmdir(os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs = ['FLAC++', 'FLAC']
self.cpp_info.filenames["cmake_find_package"] = "flac"
self.cpp_info.filenames["cmake_find_package_multi"] = "flac"
self.cpp_info.names["cmake_find_package"] = "FLAC"
self.cpp_info.names["cmake_find_package_multi"] = "FLAC"

self.cpp_info.components["libflac"].libs = ["FLAC"]
self.cpp_info.components["libflac"].names["cmake_find_package"] = "FLAC"
self.cpp_info.components["libflac"].names["cmake_find_package_multi"] = "FLAC"
self.cpp_info.components["libflac"].requires = ["ogg::ogg"]

self.cpp_info.components["libflac++"].libs = ["FLAC++"]
self.cpp_info.components["libflac++"].requires = ["libflac"]
self.cpp_info.components["libflac++"].names["cmake_find_package"] = "FLAC++"
self.cpp_info.components["libflac++"].names["cmake_find_package_multi"] = "FLAC++"
if not self.options.shared:
self.cpp_info.defines = ["FLAC__NO_DLL"]
self.cpp_info.components["libflac"].defines = ["FLAC__NO_DLL"]
if self.settings.os == "Linux":
self.cpp_info.system_libs += ["m"]
self.cpp_info.components["libflac"].system_libs += ["m"]
8 changes: 5 additions & 3 deletions recipes/flac/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 2.8.11)
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

find_package(flac REQUIRED COMPONENTS FLAC)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE FLAC::FLAC++)
2 changes: 1 addition & 1 deletion recipes/flac/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
generators = "cmake", "cmake_find_package"

def build(self):
cmake = CMake(self)
Expand Down

0 comments on commit 1a998dd

Please sign in to comment.