diff --git a/recipes/flatcc/all/conandata.yml b/recipes/flatcc/all/conandata.yml index 66d44b5b9fb85..3c56d7f7208a6 100644 --- a/recipes/flatcc/all/conandata.yml +++ b/recipes/flatcc/all/conandata.yml @@ -2,3 +2,10 @@ sources: "0.6.0": sha256: a92da3566d11e19bb807a83554b1a2c644a5bd91c9d9b088514456bb56e1c666 url: https://github.com/dvidelabs/flatcc/archive/v0.6.0.tar.gz + "0.7.0pre": + url: https://github.com/madebr/flatcc/archive/cmake_dep.zip + sha256: 78522f33d35efe291896b8a5b69b1752eadcd126a259522543cbc7f527772471 +patches: + "0.7.0pre": + - patch_file: "patches/0001_workaround_no_exe_target_support_in_conan.patch" + base_path: "source_subfolder" diff --git a/recipes/flatcc/all/conanfile.py b/recipes/flatcc/all/conanfile.py index 4d708e4bbfd65..dfe6bb75b3eb3 100644 --- a/recipes/flatcc/all/conanfile.py +++ b/recipes/flatcc/all/conanfile.py @@ -1,4 +1,4 @@ -import os +import os, glob from conans import CMake, ConanFile, tools from conans.errors import ConanInvalidConfiguration @@ -35,7 +35,7 @@ class FlatccConan(ConanFile): } settings = "os", "arch", "compiler", "build_type" generators = "cmake" - exports_sources = ["CMakeLists.txt"] + exports_sources = ["CMakeLists.txt", "patches/**"] _cmake = None @@ -48,6 +48,10 @@ def _source_subfolder(self): def _build_subfolder(self): return "build_subfolder" + def _patch_sources(self): + for patch in self.conan_data.get("patches", {}).get(self.version, []): + tools.patch(**patch) + def config_options(self): if self.settings.os == "Windows": del self.options.fPIC @@ -64,8 +68,10 @@ def configure(self): def source(self): tools.get(**self.conan_data["sources"][self.version]) - extracted_dir = self.name + "-" + self.version - os.rename(extracted_dir, self._source_subfolder) + #TODO: restore extracted_dir when new release of flatcc is available + #extracted_dir = self.name + "-" + self.version + import glob + os.rename(glob.glob("flatcc-*")[0], self._source_subfolder) def _configure_cmake(self): if not self._cmake: @@ -86,10 +92,10 @@ def _configure_cmake(self): return self._cmake def build(self): + self._patch_sources() cmake = self._configure_cmake() cmake.build() - def package(self): cmake = self._configure_cmake() cmake.install() @@ -99,12 +105,39 @@ def package(self): os.path.join(self.package_folder, "bin", "flatcc")) # Copy license file self.copy("LICENSE", dst="licenses", src=self._source_subfolder) + # Remove cmake config files + tools.rmdir(os.path.join(self.package_folder, "lib", "cmake", "flatcc")) + tools.rmdir(os.path.join(self.package_folder, "lib", "cmake", "flatccruntime")) + os.remove(os.path.join(self.package_folder, "lib", "cmake", "flatcccli", "flatcccli-config.cmake")) + os.remove(os.path.join(self.package_folder, "lib", "cmake", "flatcccli", "flatcccli-config-version.cmake")) + tools.remove_files_by_mask(os.path.join(self.package_folder, "lib", "cmake", "flatcccli"), "flatcccli-targets*.cmake") def package_info(self): - bin_path = os.path.join(self.package_folder, "bin") - self.output.info('Appending PATH environment variable: %s' % bin_path) - self.env_info.PATH.append(bin_path) debug_suffix = "_d" if self.settings.build_type == "Debug" else "" + #flatcc package provides two components: the flatcc compiler binary and the runtime library if not self.options.runtime_lib_only: - self.cpp_info.libs.append("flatcc%s" % debug_suffix) - self.cpp_info.libs.append("flatccrt%s" % debug_suffix) + self.cpp_info.components["cli"].names["cmake_find_package"] = "cli" + self.cpp_info.components["cli"].libs = ["flatcc%s" % debug_suffix] + #FIXME: in the FlatccGenerateSources.cmake module the flatcc compiler exe is called via cmake target flatcc:cli. + #Currently this doesn't work when using Conan i.s.o. the (removed) flatcc cmake config files. + #We patch the FlatccGenerateSources.cmake module for this until Conan has support for executable targets. + #This workaround only succeeds when creating the package via 'conan create'. When calling 'conan install' + #and then manually build the flatcc package the FLATCC_CLI_EXE environment variable is not set (see below) and + #as a result the flatcc_generate_sources function in the FlatccGenerateSources.cmake module will fail. + + #Our FlatccGenerateSources.cmake should be found when using the cmake_find_package generator + self.cpp_info.components["cli"].builddirs.append(os.path.join(self.package_folder, "lib", "cmake", "flatcccli")) + bin_path = os.path.join(self.package_folder, "bin") + self.env_info.PATH.append(bin_path) + #When we are cross-compiling cmake needs to know the location of the flatbuffer compiler executable + #compiled for the build architecture. Provide it via environment variable flatccCli_ROOT that will be + #picked up by the find_package(flatcc ...) command. + settings_target = getattr(self, 'settings_target', None) + if settings_target != None: + self.env_info.flatccCli_ROOT = self.package_folder + #Temporarily also export flatcc cli executable location, see patch 0001_workaround_no_exe_target_support_in_conan.patch. + #Don't overwrite it if already set by build env_info (when cross compiling). + if not self.env_info.FLATCC_CLI_EXE: + self.env_info.FLATCC_CLI_EXE = os.path.join(self.package_folder, "bin", "flatcc") + self.cpp_info.components["runtime"].names["cmake_find_package"] = "runtime" + self.cpp_info.components["runtime"].libs = ["flatccrt%s" % debug_suffix] diff --git a/recipes/flatcc/all/patches/0001_workaround_no_exe_target_support_in_conan.patch b/recipes/flatcc/all/patches/0001_workaround_no_exe_target_support_in_conan.patch new file mode 100644 index 0000000000000..3bcabe88a6eb2 --- /dev/null +++ b/recipes/flatcc/all/patches/0001_workaround_no_exe_target_support_in_conan.patch @@ -0,0 +1,15 @@ +diff --git a/cmake/FlatccGenerateSources.cmake b/cmake/FlatccGenerateSources.cmake +index 0607449..e86c365 100644 +--- a/cmake/FlatccGenerateSources.cmake ++++ b/cmake/FlatccGenerateSources.cmake +@@ -324,8 +324,8 @@ function(flatcc_generate_sources) + + add_custom_command(OUTPUT ${OUTPUT_FILES} + COMMAND "${CMAKE_COMMAND}" -E make_directory "${FLATCC_OUTPUT_DIR}" +- COMMAND flatcc::cli ${FLATCC_ARGS} ${ABSOLUTE_SCHEMA_FILES} +- DEPENDS flatcc::cli ${ABSOLUTE_DEFINITIONS_DEPENDENCIES} ++ COMMAND $ENV{FLATCC_CLI_EXE} ${FLATCC_ARGS} ${ABSOLUTE_SCHEMA_FILES} ++ DEPENDS $ENV{FLATCC_CLI_EXE} ${ABSOLUTE_DEFINITIONS_DEPENDENCIES} + ) + + add_custom_target("flatcc_generated_${FLATCC_NAME}" diff --git a/recipes/flatcc/all/test_package/CMakeLists.txt b/recipes/flatcc/all/test_package/CMakeLists.txt index 6a7405fd83e3c..98949023c9cf8 100644 --- a/recipes/flatcc/all/test_package/CMakeLists.txt +++ b/recipes/flatcc/all/test_package/CMakeLists.txt @@ -1,32 +1,33 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) project(flatcc_example) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() -set(INC_DIR "${PROJECT_SOURCE_DIR}/include") -set(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") -set(FBS_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -include_directories("${GEN_DIR}" "${INC_DIR}") +set(FBS_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -add_executable(monster monster.c) #On MacOS System Integrity Protection (SIP) will clear the DYLD_LIBRARY_PATH variable. #As a result calling flatcc from cmake will currently not work if the flatcc executable # is linked shared. As a workaround we generate the flatbuffer C files in the Conan recipe # when on MacOS and flatcc option 'shared' is True. -if (NOT MACOS_SIP_WORKAROUND) - add_custom_target(gen_monster_fbs ALL) - add_custom_command ( - TARGET gen_monster_fbs - COMMAND cmake -E make_directory "${GEN_DIR}" - COMMAND flatcc -a -o "${GEN_DIR}" "${FBS_DIR}/monster.fbs" - DEPENDS flatcc "${FBS_DIR}/monster.fbs" +if (MACOS_SIP_WORKAROUND) + set(INC_DIR "${PROJECT_SOURCE_DIR}/include") + set(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") + include_directories("${GEN_DIR}" "${INC_DIR}") +else() + include(FlatccGenerateSources) + flatcc_generate_sources( + NAME monster_sample + SCHEMA_FILES monster.fbs + ALL + OUTPUT_DIR "${GEN_DIR}" ) - - add_dependencies(monster gen_monster_fbs) endif() +add_executable(monster monster.c) -target_link_libraries(monster ${CONAN_LIBS}) +target_link_libraries(monster ${CONAN_LIBS} + $<$>:flatcc_generated::monster_sample> +) diff --git a/recipes/flatcc/all/test_package/conanfile.py b/recipes/flatcc/all/test_package/conanfile.py index 41cc0f44916ca..cd86245b5e226 100644 --- a/recipes/flatcc/all/test_package/conanfile.py +++ b/recipes/flatcc/all/test_package/conanfile.py @@ -8,6 +8,13 @@ class FlatccTestConan(ConanFile): generators = "cmake" def build(self): + if tools.cross_building(self): + pass + #Note: if you want to build this test_package also when cross-compiling just add + # the same flatcc version that you are testing to build_requires of + # this test_package. Then the build environment flatcc cli executable location + # will be passed automatically to the flatcc_generate_sources cmake function. + env_build = RunEnvironment(self) with tools.environment_append(env_build.vars): cmake = CMake(self) diff --git a/recipes/flatcc/config.yml b/recipes/flatcc/config.yml index f471d193a0d97..6548d6f2ee8af 100644 --- a/recipes/flatcc/config.yml +++ b/recipes/flatcc/config.yml @@ -1,3 +1,5 @@ versions: 0.6.0: folder: all + 0.7.0pre: + folder: all