Skip to content

Commit

Permalink
Validate cmake macros
Browse files Browse the repository at this point in the history
Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries committed Nov 13, 2019
1 parent 209da0b commit d9dc437
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
8 changes: 6 additions & 2 deletions recipes/protoc/3.9.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def package(self):
cmake.install()
cmake_folder = os.path.join(self.package_folder, self._cmake_base_path)
os.unlink(os.path.join(cmake_folder, "protoc-config-version.cmake"))
os.unlink(os.path.join(cmake_folder, "protoc-targets-noconfig.cmake"))
# FIXME: To find protoc the cmake generator is required
cmake_path = os.path.join(cmake_folder, "protoc-targets-noconfig.cmake")
tools.replace_in_file(cmake_path, "${_IMPORT_PREFIX}/bin/", "${CONAN_BIN_DIRS_PROTOC}/")

def package_id(self):
del self.info.settings.compiler
Expand All @@ -71,11 +73,13 @@ def package_info(self):
# protoc-module.cmake: provides legacy functions, PROTOBUF_GENERATE_CPP PROTOBUF_GENERATE_PYTHON
# protoc-options.cmake: required by protoc-tools.cmake
# protoc-targets.cmake: required by protoc-tools.cmake
# protoc-targets-noconfig.cmake: declare protobuf:protoc as target
self.cpp_info.build_modules = [
os.path.join(self._cmake_base_path, "protoc-config.cmake"),
os.path.join(self._cmake_base_path, "protoc-module.cmake"),
os.path.join(self._cmake_base_path, "protoc-options.cmake"),
os.path.join(self._cmake_base_path, "protoc-targets.cmake")
os.path.join(self._cmake_base_path, "protoc-targets.cmake"),
os.path.join(self._cmake_base_path, "protoc-targets-noconfig.cmake")
]

protoc = "protoc.exe" if self.settings.os_build == "Windows" else "protoc"
Expand Down
20 changes: 12 additions & 8 deletions recipes/protoc/3.9.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
cmake_minimum_required(VERSION 2.8.12)
project(test_package CXX)

set(CMAKE_VERBOSE_MAKEFILE ON)

# Findprotoc.cmake generated by Conan does not give a hint where protoc is installed.
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_VERBOSE_MAKEFILE ON)
find_package(protoc)

find_package(protoc CONFIG REQUIRED)
if (NOT protobuf_MODULE_COMPATIBLE)
message(FATAL_ERROR "protobuf_MODULE_COMPATIBLE is mandatory")
endif()

message(STATUS "Using Protocol Buffers ${protobuf_VERSION}")
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS addressbook.proto)
message(STATUS "PROTO_SRCS: ${PROTO_SRCS}")
message(STATUS "PROTO_HDRS: ${PROTO_HDRS}")

if(protobuf_MODULE_COMPATIBLE)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS addressbook.proto)
message(STATUS "PROTO_SRCS: ${PROTO_SRCS}")
message(STATUS "PROTO_HDRS: ${PROTO_HDRS}")
endif(protobuf_MODULE_COMPATIBLE)
# Without a target, Protobuf will not generate sources and headers
add_executable(${CMAKE_PROJECT_NAME} "${PROTO_HDRS}" example.cpp)
7 changes: 6 additions & 1 deletion recipes/protoc/3.9.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from conans import ConanFile, CMake, tools


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

def build(self):
cmake = CMake(self)
cmake.definitions["protobuf_VERBOSE"] = True
Expand All @@ -14,3 +16,6 @@ def build(self):
def test(self):
if not tools.cross_building(self.settings):
self.run("protoc --version", run_environment=True)

assert os.path.isfile(os.path.join(self.build_folder, "addressbook.pb.cc"))
assert os.path.isfile(os.path.join(self.build_folder, "addressbook.pb.h"))

0 comments on commit d9dc437

Please sign in to comment.