-
Notifications
You must be signed in to change notification settings - Fork 2.4k
#3907: add component info in conanfile.py, add cmake helper module, e… #3908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
170951c
7230038
0d2bed3
7b5e3ae
4fa8c6b
3421de3
e2c00ef
84f3b23
76a6068
6c630aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
|
|
||
| # Use the following function to generate C source files from flatbuffer definition files: | ||
| # | ||
| # flatcc_generate_sources(GENERATED_SOURCE_DIRECTORY <directory where to write source files> | ||
| # GENERATE_BUILDER | ||
| # GENERATE_VERIFIER | ||
| # EXPECTED_OUTPUT_FILES <list of files that flatcc is supposed to generate> | ||
| # DEFINITION_FILES <list of flatbuffer definition files (.fbs)> | ||
| # ) | ||
| # | ||
| # GENERATE_BUILDER and GENERATE_VERIFIER are boolean options. When specified they will instruct | ||
| # flatcc to generate builder / verifier source code. | ||
| # | ||
| # With cross-compiling you should provide the directory where the flatcc compiler executable is located | ||
| # in environment variable FLATCC_BUILD_BIN_PATH. If you use Conan and add flatcc as a build requirement | ||
| # this will be done automatically. | ||
|
|
||
|
|
||
| function(flatcc_generate_sources) | ||
|
|
||
| # parse function arguments | ||
| set(OUTPREFIX "FLATCC") #variables created by 'cmake_parse_arguments' will be prefixed with this | ||
| set(NO_VAL_ARGS GENERATE_BUILDER GENERATE_VERIFIER) | ||
| set(SINGLE_VAL_ARGS GENERATED_SOURCE_DIRECTORY) | ||
| set(MULTI_VAL_ARGS DEFINITION_FILES EXPECTED_OUTPUT_FILES CC_OPTIONS) | ||
|
|
||
| cmake_parse_arguments(${OUTPREFIX} | ||
| "${NO_VAL_ARGS}" | ||
| "${SINGLE_VAL_ARGS}" | ||
| "${MULTI_VAL_ARGS}" | ||
| ${ARGN} | ||
| ) | ||
| if (GENERATED_SOURCE_DIRECTORY IN_LIST FLATCC_KEYWORDS_MISSING_VALUES) | ||
| message(FATAL_ERROR "No directory provided after GENERATED_SOURCE_DIRECTORY keyword") | ||
| endif() | ||
| if (NOT FLATCC_GENERATED_SOURCE_DIRECTORY) | ||
| set(FLATCC_GENERATED_SOURCE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) | ||
| endif() | ||
| message(STATUS "Flatcc sources will be generated in directory ${FLATCC_GENERATED_SOURCE_DIRECTORY}") | ||
|
|
||
| if (FLATCC_GENERATE_BUILDER) | ||
| list(APPEND FLATCC_CC_OPTIONS --builder) | ||
| endif() | ||
| if (FLATCC_GENERATE_VERIFIER) | ||
| list(APPEND FLATCC_CC_OPTIONS --verifier) | ||
| endif() | ||
|
|
||
| if (FLATCC_DEFINITION_FILES) | ||
| if (NOT EXISTS ${FLATCC_GENERATED_SOURCE_DIRECTORY}) | ||
| file(MAKE_DIRECTORY ${FLATCC_GENERATED_SOURCE_DIRECTORY}) | ||
| endif() | ||
|
|
||
| message(VERBOSE "Executing command ${FLATCC_COMPILER} ${FLATCC_CC_OPTIONS} -o ${FLATCC_GENERATED_SOURCE_DIRECTORY} ${FLATCC_DEFINITION_FILES}") | ||
| add_custom_command(OUTPUT ${FLATCC_EXPECTED_OUTPUT_FILES} | ||
| COMMAND ${FLATCC_COMPILER} ${FLATCC_CC_OPTIONS} -o ${FLATCC_GENERATED_SOURCE_DIRECTORY} ${FLATCC_DEFINITION_FILES} | ||
| WORKING_DIRECTORY ${FLATCC_GENERATED_SOURCE_DIRECTORY}) | ||
| else() | ||
| message(WARNING "No flatbuffer definition files provided, no sources will be generated") | ||
| endif() | ||
|
|
||
| endfunction() | ||
|
|
||
|
|
||
| #### Main #### | ||
|
|
||
| #When cross-compiling user can provide location of the flatbuffers to C compiler in build arch via | ||
| #environment variable FLATCC_BUILD_BIN_PATH | ||
| set(FLATCC_BIN_PATH "$ENV{FLATCC_BUILD_BIN_PATH}") | ||
| if (FLATCC_BIN_PATH) | ||
| #user provided location where asn1c compiler executable is installed | ||
| find_program(FLATCC_COMPILER flatcc | ||
| PATHS ${FLATCC_BIN_PATH} | ||
| NO_DEFAULT_PATH | ||
| NO_SYSTEM_ENVIRONMENT_PATH | ||
| NO_CMAKE_SYSTEM_PATH | ||
| ) | ||
| else() | ||
| #Find compiler exe in current install location | ||
| find_program(FLATCC_COMPILER flatcc | ||
| NO_SYSTEM_ENVIRONMENT_PATH | ||
| NO_CMAKE_SYSTEM_PATH | ||
| ) | ||
| endif() | ||
|
|
||
|
|
||
| if (NOT FLATCC_COMPILER) | ||
| message(FATAL_ERROR "Could not locate the flatcc compiler executable") | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ class FlatccConan(ConanFile): | |
| } | ||
| settings = "os", "arch", "compiler", "build_type" | ||
| generators = "cmake" | ||
| exports_sources = ["CMakeLists.txt"] | ||
| exports_sources = ["CMakeLists.txt", "FlatccGenerateSources.cmake"] | ||
|
|
||
| _cmake = None | ||
|
|
||
|
|
@@ -89,7 +89,6 @@ def build(self): | |
| cmake = self._configure_cmake() | ||
| cmake.build() | ||
|
|
||
|
|
||
| def package(self): | ||
| cmake = self._configure_cmake() | ||
| cmake.install() | ||
|
|
@@ -99,12 +98,24 @@ def package(self): | |
| os.path.join(self.package_folder, "bin", "flatcc")) | ||
| # Copy license file | ||
| self.copy("LICENSE", dst="licenses", src=self._source_subfolder) | ||
| # Copy file with cmake functions for end user | ||
| self.copy("FlatccGenerateSources.cmake", dst="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["flatcc_exe"].names["cmake_find_package"] = "flatcc_exe" | ||
| self.cpp_info.components["flatcc_exe"].libs = ["flatcc%s" % debug_suffix] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I will add an extra component for the library that the compiler binary links to. |
||
| #Our FlatccGenerateSources.cmake should be included by the cmake_find_package generated file | ||
| self.cpp_info.components["flatcc_exe"].build_modules.append(os.path.join(self.package_folder, "cmake", "FlatccGenerateSources.cmake")) | ||
| 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. | ||
| settings_target = getattr(self, 'settings_target', None) | ||
| if settings_target != None: | ||
| self.env_info.FLATCC_BUILD_BIN_PATH = os.path.join(self.package_folder, "bin") | ||
| self.cpp_info.components["flatcc_rt"].names["cmake_find_package"] = "flatcc_rt" | ||
| self.cpp_info.components["flatcc_rt"].libs = ["flatccrt%s" % debug_suffix] | ||
| self.cpp_info.components["flatcc_rt"].includedirs.append(os.path.join("include", "flatcc", "reflection")) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please point me to the cmake script from the flatbuffers repo at https://github.com/dvidelabs/flatcc
containing these functions/macros?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote that cmake script because it simplifies using flatcc in cmake a lot. I am going to send it upstream as well.
Do you want me to add it to the flatcc package via the patches mechanism?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: PR for flatcc cmake module submitted: dvidelabs/flatcc#169
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do it as a patch, so when your pr gets accepted, this recipe can be adapted more easily.
In the mean time, maybe add a FIXME/TODO that this is experimental conan-only code?