Skip to content

Commit

Permalink
Build both C and C++ libraries every time
Browse files Browse the repository at this point in the history
  • Loading branch information
datalogics-staylor committed May 13, 2024
1 parent 786f926 commit 332dc26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 35 deletions.
21 changes: 9 additions & 12 deletions recipes/qr-code-generator/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
cmake_minimum_required(VERSION 3.15)
project(QR-Code-Generator)

include(src/files.cmake)

IF (COMPILE_AS_C)
set(SRC ${CMAKE_SOURCE_DIR}/src/c/qrcodegen.c)
set(CMAKE_C_STANDARD 99)
set(LIBRARY_NAME qrcodegenc)
set(HEADERS ${CMAKE_SOURCE_DIR}/src/c/qrcodegen.h)
set(INCLUDE_DIR qrcodegenc)
ELSE ()
set(INCLUDE_DIR qrcodegen)
ENDIF ()
set(SRC_C ${CMAKE_SOURCE_DIR}/src/c/qrcodegen.c)
set(LIBRARY_NAME_C qrcodegenc)
set(HEADERS_C ${CMAKE_SOURCE_DIR}/src/c/qrcodegen.h)

add_library(${LIBRARY_NAME} ${SRC})
add_library(${LIBRARY_NAME_C} ${SRC_C})
set_target_properties(${LIBRARY_NAME_C} PROPERTIES PUBLIC_HEADER "${HEADERS_C}")
install(TARGETS ${LIBRARY_NAME_C} RUNTIME LIBRARY ARCHIVE PUBLIC_HEADER DESTINATION include/qrcodegenc)

include(src/files.cmake)
add_library(${LIBRARY_NAME} ${SRC})
set_target_properties(${LIBRARY_NAME} PROPERTIES PUBLIC_HEADER "${HEADERS}")
install(TARGETS ${LIBRARY_NAME} RUNTIME LIBRARY ARCHIVE PUBLIC_HEADER DESTINATION include/${INCLUDE_DIR})
install(TARGETS ${LIBRARY_NAME} RUNTIME LIBRARY ARCHIVE PUBLIC_HEADER DESTINATION include/qrcodegen)
30 changes: 7 additions & 23 deletions recipes/qr-code-generator/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class QrCodeGeneratorConan(ConanFile):
options = {
"shared": [True, False],
"fPIC": [True, False],
"compile_as_c": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"compile_as_c": False,
}

@property
Expand All @@ -56,10 +54,6 @@ def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

if not self.options.compile_as_c:
self.options.rm_safe("compiler.libcxx")
self.options.rm_safe("compiler.cppstd")

def layout(self):
cmake_layout(self, src_folder="src")

Expand All @@ -77,13 +71,10 @@ def source(self):

def generate(self):
tc = CMakeToolchain(self)
tc.variables["COMPILE_AS_C"] = self.options.compile_as_c
if self.settings.os == "Windows" and self.options.shared:
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
if not valid_min_cppstd(self, self._min_cppstd):
tc.variables["CMAKE_CXX_STANDARD"] = self._min_cppstd
if not valid_min_cppstd(self, self._min_cppstd):
tc.variables["CMAKE_C_STANDARD"] = "11"
tc.generate()

def build(self):
Expand All @@ -93,14 +84,10 @@ def build(self):
cmake.build()

def _extract_license(self):
if self.options.compile_as_c:
header_name = ("qrcodegen.h")
header = load(self, os.path.join(self.source_folder, "c", header_name))
else:
header_name = (
"QrCode.hpp" if Version(self.version) < "1.7.0" else "qrcodegen.hpp"
)
header = load(self, os.path.join(self.source_folder, "cpp", header_name))
header_name = (
"QrCode.hpp" if Version(self.version) < "1.7.0" else "qrcodegen.hpp"
)
header = load(self, os.path.join(self.source_folder, "cpp", header_name))
license_contents = header[2 : header.find("*/", 1)]
return license_contents

Expand All @@ -114,12 +101,9 @@ def package(self):
cmake.install()

def package_info(self):
if self.options.compile_as_c:
self.cpp_info.libs = ["qrcodegen"]
else:
self.cpp_info.libs =[
"qrcodegen" if Version(self.version) < "1.7.0" else "qrcodegencpp"
]
self.cpp_info.libs = [
"qrcodegen" if Version(self.version) < "1.7.0" else "qrcodegencpp"
]

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")

0 comments on commit 332dc26

Please sign in to comment.