├── .ci ├── jenkins │ └── Jenkinsfile └── run.py ├── .gitignore ├── LICENSE ├── README.md ├── features ├── __init__.py ├── cmake │ ├── __init__.py │ └── find_package │ │ ├── __init__.py │ │ ├── exported_targets_multiconfig │ │ ├── README.md │ │ ├── __init__.py │ │ ├── build.bat │ │ ├── build.sh │ │ ├── bye │ │ │ ├── __init__.py │ │ │ ├── conanfile.py │ │ │ └── src │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── bye.cpp │ │ │ │ ├── bye.h │ │ │ │ └── byeConfig.cmake │ │ ├── hello │ │ │ ├── __init__.py │ │ │ ├── conanfile.py │ │ │ └── src │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── hello.cpp │ │ │ │ ├── hello.h │ │ │ │ └── helloConfig.cmake │ │ └── project │ │ │ ├── CMakeLists.txt │ │ │ ├── conanfile.txt │ │ │ └── example.cpp │ │ └── find_cmake_multi_generator_targets │ │ ├── README.md │ │ ├── __init__.py │ │ ├── build.bat │ │ ├── build.sh │ │ ├── bye │ │ ├── __init__.py │ │ ├── conanfile.py │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── bye.cpp │ │ │ └── bye.h │ │ ├── hello │ │ ├── __init__.py │ │ ├── conanfile.py │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── hello.cpp │ │ │ └── hello.h │ │ └── project │ │ ├── CMakeLists.txt │ │ ├── conanfile.txt │ │ └── example.cpp ├── deployment │ ├── .gitignore │ ├── CMakeLists.txt │ ├── build.sh │ ├── conanfile.txt │ ├── deploy.py │ └── md5.cpp ├── editable │ └── cmake │ │ ├── .gitignore │ │ ├── build.bat │ │ ├── build.sh │ │ ├── hello │ │ ├── CMakeLists.txt │ │ ├── conanfile.txt │ │ └── src │ │ │ └── hello.cpp │ │ └── say │ │ ├── CMakeLists.txt │ │ ├── conanfile.py │ │ ├── include │ │ └── say.h │ │ └── src │ │ ├── original_say.cpp │ │ ├── say.cpp │ │ └── say2.cpp ├── emscripten │ ├── .gitignore │ ├── CMakeLists.txt │ ├── build.bat │ ├── build.sh │ ├── conanfile.py │ ├── conanfile.txt │ ├── emscripten.profile │ ├── main.cpp │ ├── run.cmd │ └── run.sh ├── integrate_build_system │ ├── build.bat │ ├── build.py │ ├── build.sh │ ├── mylib-consumer │ │ ├── conanfile.py │ │ ├── main.cpp │ │ └── wscript │ ├── waf-build-helper │ │ ├── conanfile.py │ │ └── waf_environment.py │ ├── waf-generator │ │ └── conanfile.py │ ├── waf-installer │ │ ├── LICENSE │ │ └── conanfile.py │ └── waf-mylib │ │ ├── conanfile.py │ │ ├── include │ │ └── mylib.hpp │ │ ├── src │ │ └── mylib.cpp │ │ └── wscript ├── lockfiles │ ├── build_order │ │ ├── app1 │ │ │ └── conanfile.py │ │ ├── app2 │ │ │ └── conanfile.py │ │ ├── build.bat │ │ ├── build.py │ │ ├── build.sh │ │ ├── liba │ │ │ └── conanfile.py │ │ ├── libb │ │ │ └── conanfile.py │ │ ├── libc │ │ │ └── conanfile.py │ │ └── libd │ │ │ └── conanfile.py │ ├── ci │ │ ├── .gitignore │ │ ├── app1 │ │ │ └── conanfile.py │ │ ├── app2 │ │ │ └── conanfile.py │ │ ├── build.bat │ │ ├── build.py │ │ ├── build.sh │ │ ├── liba │ │ │ └── conanfile.py │ │ ├── libb │ │ │ └── conanfile.py │ │ ├── libc │ │ │ └── conanfile.py │ │ └── libd │ │ │ └── conanfile.py │ └── intro │ │ ├── build.bat │ │ ├── build.py │ │ ├── build.sh │ │ ├── pkga │ │ ├── conanfile.py │ │ └── src │ │ │ └── helloa.h │ │ └── pkgb │ │ ├── conanfile.py │ │ └── src │ │ ├── CMakeLists.txt │ │ ├── greet.cpp │ │ ├── hello.cpp │ │ └── hellob.h ├── makefiles │ ├── build.bat │ ├── build.sh │ ├── helloapp │ │ ├── conanfile.py │ │ └── src │ │ │ ├── Makefile │ │ │ └── app.cpp │ └── hellolib │ │ ├── conanfile.py │ │ └── src │ │ ├── Makefile │ │ ├── hello.cpp │ │ └── hello.h ├── multi_config │ ├── CMakeLists.txt │ ├── build.bat │ ├── build.sh │ ├── conanfile.py │ ├── hello.cpp │ ├── hello.h │ └── test_package │ │ ├── CMakeLists.txt │ │ ├── conanfile.py │ │ └── example.cpp ├── package_development_flow │ ├── build.bat │ ├── build.sh │ ├── conanfile.py │ └── test_package │ │ ├── CMakeLists.txt │ │ ├── conanfile.py │ │ └── example.cpp ├── python_requires │ └── reuse_conanfile │ │ ├── build.bat │ │ ├── build.sh │ │ ├── consumer │ │ ├── conanfile.py │ │ └── src │ │ │ ├── hello.cpp │ │ │ └── hello.h │ │ └── pyreq │ │ ├── CMakeLists.txt │ │ ├── conanfile.py │ │ └── scm_utils.py └── workspace │ └── cmake │ ├── .gitignore │ ├── CMakeLists.txt │ ├── build.bat │ ├── build.sh │ ├── chat │ ├── conanfile.py │ └── src │ │ ├── CMakeLists.txt │ │ ├── app.cpp │ │ ├── chat.cpp │ │ └── chat.h │ ├── conanws_gcc.yml │ ├── conanws_vs.yml │ ├── hello │ ├── conanfile.py │ └── src │ │ ├── CMakeLists.txt │ │ ├── hello.cpp │ │ └── hello.h │ ├── layout_gcc │ ├── layout_vs │ └── say │ ├── conanfile.py │ └── src │ ├── CMakeLists.txt │ ├── say.cpp │ └── say.h ├── libraries ├── dear-imgui │ └── basic │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── assets │ │ ├── simple-shader.fs │ │ └── simple-shader.vs │ │ ├── build.bat │ │ ├── build.sh │ │ ├── conanfile.txt │ │ ├── file_manager.cpp │ │ ├── file_manager.h │ │ ├── main.cpp │ │ ├── opengl_shader.cpp │ │ └── opengl_shader.h ├── folly │ └── basic │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── build.bat │ │ ├── build.sh │ │ ├── conanfile.txt │ │ └── main.cpp ├── imgui-opencv-poco │ ├── .gitignore │ ├── CMakeLists.txt │ ├── README.md │ ├── app │ │ └── main.cpp │ ├── conanfile.py │ ├── data │ │ ├── bird.jpeg │ │ └── screen-capture.gif │ ├── include │ │ ├── downloader.h │ │ └── gui_renderer.hpp │ ├── msvc │ │ ├── msvc.sln │ │ ├── msvc.vcxproj │ │ └── msvc.vcxproj.filters │ └── src │ │ ├── downloader.cpp │ │ └── gui_renderer.cpp ├── poco │ └── md5 │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── build.bat │ │ ├── build.sh │ │ ├── conanfile.txt │ │ └── md5.cpp └── protobuf │ └── serialization │ ├── CMakeLists.txt │ ├── README.md │ ├── __init__.py │ ├── build.bat │ ├── build.sh │ ├── conanfile.txt │ ├── main.cc │ ├── main.py │ └── sensor.proto └── tox.ini /.ci/jenkins/Jenkinsfile: -------------------------------------------------------------------------------- 1 | void cancelPrevious() { 2 | stage('Cancelling previous') { 3 | def buildNumber = env.BUILD_NUMBER as int 4 | if (buildNumber > 1) milestone(buildNumber - 1) 5 | milestone(buildNumber) 6 | } 7 | } 8 | 9 | boolean isMaster = env.BRANCH_NAME == 'master' 10 | 11 | private Closure runTests(String nodeName) { 12 | def ret = { 13 | node(nodeName) { 14 | stage("${nodeName}") { 15 | try { 16 | checkout scm 17 | if (nodeName == 'Linux') { 18 | def dockerImage = 'conanio/ci-functional' 19 | docker.image(dockerImage).inside('--entrypoint=') { 20 | def sourcedir = '/home/conan/' 21 | def pyenvdir = "${sourcedir}.pyenv" 22 | sh(script: "cp -R ./ ${sourcedir}") 23 | sh(script: "chown -R conan ${sourcedir}") 24 | def command = "su - conan -c \"" \ 25 | + "export PYENV_ROOT=${pyenvdir} && " \ 26 | + "export PATH=\"${pyenvdir}/bin:\$PATH\" && " \ 27 | + "pyenv local \$PY38 \$PY39 && " \ 28 | + "python -m pip install tox tox-venv requests && " \ 29 | + "python -m tox --verbose\"" 30 | sh(script: command) 31 | } 32 | } 33 | else if (nodeName=='Macos') { 34 | def localDir = '/Users/jenkins' 35 | withEnv(['PY38=3.8.6', 'PY39=3.9.0', 36 | "PYENV_ROOT=${localDir}/.pyenv", 37 | "PATH+EXTRA=${localDir}/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"]) { 38 | def pythonLocation = "${localDir}/.pyenv/versions/\$PY38/bin/python" 39 | def launchCommand = "pyenv local \$PY38 \$PY39 && " \ 40 | + "${pythonLocation} -m tox" 41 | sh(script: launchCommand) 42 | } 43 | } 44 | else if (nodeName=='Windows') { 45 | withEnv(['CMAKE_GENERATOR=Visual Studio 15 2017', 'CMAKE_GENERATOR_PLATFORM=x64']) { 46 | def pythonLocation = "C:/Python38-64/python.exe" 47 | def launchCommand = "tox -vv" 48 | bat(script: launchCommand) 49 | } 50 | } 51 | } 52 | finally { 53 | cleanWs() 54 | } 55 | } 56 | } 57 | } 58 | return ret 59 | } 60 | 61 | try { 62 | cancelPrevious() 63 | 64 | def nodes = ['Windows', 'Macos', 'Linux'] 65 | def paralellRuns = [:] 66 | nodes.each { node -> 67 | paralellRuns["${node}"] = runTests(node) 68 | } 69 | parallel(paralellRuns) 70 | } 71 | catch (e) { 72 | if (isMaster) { 73 | def subject = "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" 74 | def summary = "${subject} (${env.BUILD_URL})" 75 | slackSend (color: '#FF0000', message: summary) 76 | } 77 | throw e 78 | } 79 | -------------------------------------------------------------------------------- /.ci/run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | import logging 5 | import os 6 | import platform 7 | import stat 8 | import subprocess 9 | import sys 10 | import tempfile 11 | import uuid 12 | from collections import OrderedDict 13 | from contextlib import contextmanager 14 | from packaging import version 15 | 16 | import colorama 17 | from conans.client.tools.scm import Git 18 | from tabulate import tabulate 19 | from conans import __version__ as conan_version 20 | 21 | 22 | FAIL_FAST = os.getenv("FAIL_FAST", "1").lower() in ["1", "y", "yes", "true"] 23 | LOGGING_LEVEL = int(os.getenv("CONAN_LOGGING_LEVEL", logging.INFO)) 24 | logging.basicConfig(format='%(asctime)s [%(levelname)s]: %(message)s', level=LOGGING_LEVEL) 25 | 26 | 27 | 28 | @contextmanager 29 | def chdir(dir_path): 30 | current = os.getcwd() 31 | os.chdir(dir_path) 32 | logging.debug("cd {}".format(dir_path)) 33 | try: 34 | yield 35 | finally: 36 | logging.debug("cd {}".format(current)) 37 | os.chdir(current) 38 | 39 | 40 | def writeln_console(message): 41 | sys.stderr.flush() 42 | sys.stdout.write(message) 43 | sys.stdout.write('\n') 44 | sys.stdout.flush() 45 | 46 | 47 | def get_examples_to_skip(current_version): 48 | skip = [] 49 | # Given the Conan version, some examples are skipped 50 | required_conan = { 51 | version.parse("1.29.0"): [ 52 | './libraries/dear-imgui/basic', # solved bug for system packages and components 53 | ], 54 | version.parse("1.49.99"): [ 55 | './features/editable/cmake', # Changed layout, so min 1.50.0 can be used 56 | ] 57 | } 58 | for v, examples in required_conan.items(): 59 | if current_version < v: 60 | skip.extend(examples) 61 | 62 | # Some binaries are not available # TODO: All the examples should have binaries available 63 | if platform.system() == "Windows": # Folly is not availble!! and appveyor_image() == "Visual Studio 2019": 64 | skip.extend(['./libraries/folly/basic', ]) 65 | skip.extend(['./features/makefiles', ]) 66 | skip.extend(['./features/emscripten', ]) # FIXME: building for windows fails 67 | # waf does not support Visual Studio 2019 for 2.0.19 68 | if os.environ["CMAKE_GENERATOR"] == "Visual Studio 2019": 69 | skip.extend(['./features/integrate_build_system', ]) 70 | if platform.system() == "Darwin": 71 | skip.extend(['./features/multi_config', ]) # FIXME: it fails randomly, need to investigate 72 | skip.extend(['./libraries/folly/basic', ]) 73 | 74 | return [os.path.normpath(it) for it in skip] 75 | 76 | 77 | def get_build_list(): 78 | skip_examples = get_examples_to_skip(current_version=version.parse(conan_version)) 79 | 80 | builds = [] 81 | script = "build.bat" if platform.system() == "Windows" else "build.sh" 82 | skip_folders = [os.path.normpath(it) for it in ['./.ci', './.git', './.tox', 'examples_venv', '.pyenv']] 83 | for root, dirs, files in os.walk('.'): 84 | root = os.path.normpath(root) 85 | if root in skip_folders: 86 | dirs[:] = [] 87 | continue 88 | if root in skip_examples: 89 | dirs[:] = [] 90 | sys.stdout.write("Skip {!r} example\n".format(root)) 91 | continue 92 | 93 | # Look for 'build' script, prefer 'build.py' over all of them 94 | build = [it for it in files if "build.py" in it] 95 | if not build: 96 | build = [it for it in files if os.path.basename(it) == script] 97 | 98 | if build: 99 | builds.append(os.path.join(root, build[0])) 100 | dirs[:] = [] 101 | continue 102 | return builds 103 | 104 | 105 | def chmod_x(script): 106 | logging.debug("chmod +x {}".format(script)) 107 | st = os.stat(script) 108 | os.chmod(script, st.st_mode | stat.S_IEXEC) 109 | 110 | 111 | def get_conan_env(script): 112 | temp_folder = os.path.join(tempfile.gettempdir(), str(uuid.uuid4())[:4]) 113 | os.environ["CONAN_USER_HOME"] = temp_folder 114 | logging.debug("CONAN_USER_HOME: {}".format(temp_folder)) 115 | return os.environ 116 | 117 | 118 | def configure_profile(env): 119 | subprocess.Popen(["conan", "profile", "new", "default", "--detect"], stderr=subprocess.STDOUT, env=env).communicate() 120 | if platform.system() == "Linux": 121 | subprocess.Popen(["conan", "profile", "update", "settings.compiler.libcxx=libstdc++11", "default"], 122 | stderr=subprocess.STDOUT, env=env).communicate() 123 | 124 | def configure_remotes(env): 125 | subprocess.Popen(["conan", "remote", "list"], stderr=subprocess.STDOUT, env=env).communicate() 126 | 127 | def print_build(script): 128 | dir_name = os.path.dirname(script) 129 | dir_name = dir_name[2:] if dir_name.startswith('.') else dir_name 130 | writeln_console("================================================================") 131 | writeln_console("* " + colorama.Style.BRIGHT + "{}".format(dir_name.upper())) 132 | writeln_console("================================================================") 133 | 134 | 135 | @contextmanager 136 | def ensure_cache_preserved(): 137 | cache_directory = os.environ["CONAN_USER_HOME"] 138 | 139 | git = Git(folder=cache_directory) 140 | with open(os.path.join(cache_directory, '.gitignore'), 'w') as gitignore: 141 | gitignore.write(".conan/data/") 142 | git.run("init .") 143 | git.run("add .") 144 | 145 | try: 146 | yield 147 | finally: 148 | r = git.run("diff") 149 | if r: 150 | writeln_console(">>> " + colorama.Fore.RED + "This is example modifies the cache!") 151 | writeln_console(r) 152 | raise Exception("Example modifies cache!") 153 | 154 | 155 | @contextmanager 156 | def ensure_python_environment_preserved(): 157 | freeze = subprocess.Popen(["{}".format(sys.executable), "-m", "pip", "freeze"], stdout=subprocess.PIPE).communicate()[0].decode() 158 | try: 159 | yield 160 | finally: 161 | freeze_after = subprocess.Popen(["{}".format(sys.executable), "-m", "pip", "freeze"], stdout=subprocess.PIPE).communicate()[0].decode() 162 | if freeze != freeze_after: 163 | writeln_console(">>> " + colorama.Fore.RED + "This example modifies the Python dependencies!") 164 | removed = set(freeze.splitlines()) - set(freeze_after.splitlines()) 165 | added = set(freeze_after.splitlines()) - set(freeze.splitlines()) 166 | for it in removed: 167 | writeln_console("- " + it) 168 | for it in added: 169 | writeln_console("+ " + it) 170 | raise Exception("Example modifies Python environment!") 171 | 172 | def run(cmd): 173 | result = subprocess.run([c for c in cmd.split()], stdout=subprocess.PIPE) 174 | print("running: '{}'".format(cmd)) 175 | result = result.stdout.decode('utf-8') 176 | print("result: '{}'".format(result)) 177 | return result.strip() 178 | 179 | def run_scripts(scripts): 180 | results = OrderedDict.fromkeys(scripts, '') 181 | base_dir = os.getcwd() 182 | for script in scripts: 183 | chmod_x(script) 184 | abspath = os.path.abspath(script) 185 | env = get_conan_env(script) 186 | configure_profile(env) 187 | configure_remotes(env) 188 | with chdir(os.path.dirname(script)): 189 | print_build(script) 190 | build_script = [sys.executable, abspath] if abspath.endswith(".py") else abspath 191 | with ensure_python_environment_preserved(): 192 | with ensure_cache_preserved(): 193 | result = subprocess.call(build_script, env=env) 194 | 195 | results[script] = result 196 | if result != 0 and FAIL_FAST: 197 | break 198 | return results 199 | 200 | 201 | def print_results(results): 202 | columns = [] 203 | for build, result in results.items(): 204 | build_name = os.path.dirname(build).upper() 205 | build_name = build_name[2:] if build_name.startswith(".") else build_name 206 | columns.append([build_name, get_result_message(result)]) 207 | writeln_console("\n") 208 | writeln_console(tabulate(columns, headers=["CONAN EXAMPLE", "RESULT"], tablefmt="grid")) 209 | 210 | 211 | def get_result_message(result): 212 | if result == 0: 213 | return colorama.Fore.GREEN + "SUCCESS" + colorama.Style.RESET_ALL 214 | return colorama.Fore.RED + "FAILURE" + colorama.Style.RESET_ALL 215 | 216 | 217 | def validate_results(results): 218 | for value in results.values(): 219 | if value != 0: 220 | sys.exit(value) 221 | 222 | 223 | if __name__ == "__main__": 224 | colorama.init(autoreset=True) 225 | scripts = get_build_list() 226 | results = run_scripts(scripts) 227 | print_results(results) 228 | validate_results(results) 229 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | **/test_package/build 3 | **/project*/build 4 | !*/build.sh 5 | .vscode/ 6 | 7 | # Compiled Object files 8 | *.slo 9 | *.lo 10 | *.o 11 | *.obj 12 | 13 | # Precompiled Headers 14 | *.gch 15 | *.pch 16 | 17 | # Compiled Dynamic libraries 18 | *.so 19 | *.dylib 20 | *.dll 21 | 22 | # Fortran module files 23 | *.mod 24 | *.smod 25 | 26 | # Compiled Static libraries 27 | *.lai 28 | *.la 29 | *.a 30 | *.lib 31 | 32 | # Executables 33 | *.exe 34 | *.out 35 | *.app 36 | 37 | # Cache 38 | __pycache__/* 39 | test_package/__pycache__/* 40 | test_package/build/* 41 | build/* 42 | *.pyc 43 | tmp/ 44 | features/package_development_flow/test_package/build/* 45 | features/workspace/build/* 46 | libraries/protobuf/serialization/build/* 47 | libraries/folly/basic/build/* 48 | libraries/poco/md5/build/* 49 | 50 | # IDE 51 | .idea/* 52 | .project 53 | .pydevproject 54 | .settings/* 55 | .ropeproject/* 56 | 57 | .tox 58 | **/cmake-build-release/** 59 | **/conan.lock 60 | **/environment.ps1.env 61 | **/environment.sh.env 62 | **/graph_info.json 63 | **/CMakeFiles/** 64 | **/deploy_manifest.txt 65 | features/makefiles/helloapp/bin/app 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2021 Conan.io 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://ci.conan.io/buildStatus/icon?job=Examples/master)](https://ci.conan.io/job/Examples/job/master/) 2 | 3 | > :warning: **Important**: These examples are for Conan 1.X. For the latest version of the 4 | > examples, compatible with Conan 2.X, please refer to the [new 5 | > repository](https://github.com/conan-io/examples2). 6 | 7 | # Conan 1.X Examples 8 | 9 | Several Conan 1.X examples to complement the documentation and blog. 10 | 11 | ## Examples 12 | 13 | ### [Getting started with Conan](libraries/poco/md5) 14 | 15 | Example how to use Conan to consume binaries. 16 | 17 | Documentation: https://docs.conan.io/en/latest/getting_started.html 18 | 19 | ### [Package development flow](features/package_development_flow) 20 | 21 | Example how to use Conan commands to develop a package recipe. 22 | 23 | Documentation: https://docs.conan.io/en/latest/developing_packages/package_dev_flow.html 24 | 25 | ### [Workspace](features/workspace) 26 | 27 | Example how to use Conan Workspaces. 28 | 29 | Documentation: https://docs.conan.io/en/latest/developing_packages/workspaces.html 30 | 31 | ### [Editable Packages](features/editable) 32 | 33 | Example how to use Conan Editable Packages. 34 | 35 | Documentation: https://docs.conan.io/en/latest/developing_packages/editable_packages.html 36 | 37 | ### [Serializing your data with Protobuf](libraries/protobuf/serialization) 38 | 39 | Demonstrate how to use Protobuf to serialize data between C++ and Python. 40 | 41 | Blog Post: https://blog.conan.io/2019/03/06/Serializing-your-data-with-Protobuf.html 42 | 43 | ### [Using Facebook Folly with Conan](libraries/folly/basic) 44 | 45 | Demonstrate how to use Folly to validate an URI using Futures, FBString, Executors, and Format. 46 | 47 | Blog Post: https://blog.conan.io/2018/12/03/Using-Facebook-Folly-with-Conan.html 48 | 49 | ### [An introduction to Dear ImGui and how to use with Conan](libraries/dear-imgui/basic) 50 | 51 | Demonstrate how to use Dear ImGui with Conan to add a GUI to an OpenGL3 application. 52 | 53 | ### [Exporting targets with CMake and reuse with find_package()](features/cmake/find_package/exported_targets_multiconfig) 54 | 55 | Use CMake to declare, export and install the targets of some libraries and using Conan to reuse them with 56 | ``find_package`` and the multi-configuration project. 57 | 58 | ### [Using the cmake_find_package_multi generator](features/cmake/find_package/find_cmake_multi_generator_targets) 59 | 60 | Demonstrate how to use the ``cmake_find_package_multi`` generator to integrate seamlessly CMake with Conan 61 | using ``find_package`` in a multi-configuration project. 62 | 63 | 64 | ### [Multi-configuration package (N configs -> 1 package)](features/multi_config) 65 | 66 | Example on how to create multi-configuration debug/release packages covering the N configs -> 1 package use case: 67 | 68 | - Remove the ``build_type`` from settings. 69 | - Have a CMake script that differentiate debug and release artifacts (``set_target_properties(hello PROPERTIES DEBUG_POSTFIX _d)``). 70 | - Have a ``build()`` that builds both configs. 71 | - Have a ``package_info()`` method that accounts for both configs ``self.cpp_info.debug.libs``, etc. 72 | 73 | Documentation: https://docs.conan.io/en/latest/creating_packages/package_approaches.html#n-configs-1-package 74 | 75 | 76 | ### Lockfiles 77 | 78 | #### [Using lockfiles in CI to rebuild a whole project](features/lockfiles/ci) 79 | 80 | When a package in a dependency graph is modified and a new version or revision is created, it 81 | is sometimes desired to test if that new version works well within a larger product or project, 82 | that is, when that package is part of a larger dependency graph. The packages that depend on 83 | the modified one might need to be rebuilt, but if something else changed, it is impossible to 84 | achieve reproducible builds. 85 | 86 | Using lockfiles can enforce the same upstream dependencies, to ensure reproducible builds and to re-build and test such scenarios. 87 | 88 | Documentation: https://docs.conan.io/en/latest/versioning/lockfiles.html#how-to-use-lockfiles-in-ci 89 | 90 | ### [Integrate a build system in Conan](features/integrate_build_system) 91 | 92 | Shows how to integrate a build-system in Conan using an *installer*, a *build-helper* and a *custom generator*. 93 | 94 | ### [Deployment](features/deployment) 95 | 96 | Shows how to use conan ``json`` generator with custom script to automate the creation of deployable artifact ([makeself.io](https://makeself.io)) 97 | 98 | Documentation: https://docs.conan.io/en/laters/integrations/deployment.html 99 | 100 | ## How can I reproduce the build steps? 101 | 102 | All our examples can be built on Windows, Linux and Mac. If you are interested to reproduce 103 | the examples in your environment, please check the scripts inside every example folder. 104 | 105 | ## LICENSE 106 | [MIT](LICENSE) 107 | -------------------------------------------------------------------------------- /features/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/features/__init__.py -------------------------------------------------------------------------------- /features/cmake/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/features/cmake/__init__.py -------------------------------------------------------------------------------- /features/cmake/find_package/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/features/cmake/find_package/__init__.py -------------------------------------------------------------------------------- /features/cmake/find_package/exported_targets_multiconfig/README.md: -------------------------------------------------------------------------------- 1 | Using non-intrusive multi-config CMake with exported targets & find_package 2 | =========================================================================== 3 | 4 | In this example 5 | --------------- 6 | 7 | We are using CMake to declare, export and install the targets of a `bye` library that depends on a `hello` library. 8 | Then using Conan to manage the packages and using these libraries in a project. 9 | 10 | **NOTE**: *This is not* the recommended way to use Conan based on ``find_package`` (look at the "cons") but indeed a possibility. 11 | 12 | Everything is based on the ``find_package`` feature and working with multi-config packages (Release/Debug) to avoid 13 | installing the dependencies every time we change from Debug to Release in the Visual Studio IDE. 14 | 15 | - We have a "hello" library consumed by a "bye" library and a "project" that uses the "bye" function. 16 | - The "hello" library exports its own ``helloTargets.cmake`` files, everything is pure CMake, every time we call 17 | CMake with a different build type CMake exports a ``helloTargets-{build_type}.cmake`` script. 18 | - The conan recipe uses the same binary package for any ``build_type``, by removing the ``build_type`` setting. 19 | - The conan recipe at the ``build`` method invokes CMake both for Release and Debug, generating for the same package. 20 | - The same for the "bye" library. 21 | 22 | 23 | Some useful details of this example 24 | ------------------------------------ 25 | 26 | - The ``CMakeLists.txt`` of the consumer project (at folder project) calls only ``find_package`` to manage 27 | the dependencies transparently (both with ``bye`` and ``hello``): 28 | 29 | ``` 30 | cmake_minimum_required(VERSION 3.0) 31 | project(PackageTest CXX) 32 | 33 | find_package(bye CONFIG) 34 | add_executable(example example.cpp) 35 | target_link_libraries(example bye::bye) 36 | ``` 37 | 38 | - The ``CMakeLists.txt`` files for ``bye`` and ``hello`` are quite similar, the same code except the library name and 39 | dependencies are changed in the first part. So you could use a similar ``CMakeLists.txt`` if you want to follow this 40 | approach. 41 | - It is important to add the ``CONFIG`` option to ``find_package`` so that *module mode* is explicitly skipped by CMake. This helps to 42 | solve issues when there is for example a ``Findbye.cmake`` file in CMake's default modules directory that maybe is loaded instead of the 43 | ``byeConfig.cmake`` generated by Conan. 44 | - The ``helloConfig.cmake`` and ``byeConfig.cmake`` are not auto-generated. They have to manually call `find_dependency` 45 | for all the dependencies and then include the targets. In this case, the ``bye`` library needs to find the ``hello``: 46 | 47 | ``` 48 | include(CMakeFindDependencyMacro) 49 | find_dependency(hello) 50 | 51 | include("${CMAKE_CURRENT_LIST_DIR}/byeTargets.cmake") 52 | ``` 53 | 54 | - The recipes are not even using ``package_info()`` method for the consumers 55 | 56 | Pros 57 | ---- 58 | 59 | - If you are going to consume your packages only with CMake, this is a totally non-intrusive and decoupled mechanism. 60 | - You don't need to change anything in the ``CMakeLists.txt`` related to Conan. 61 | - The multi-config mechanism works good, it is very comfortable, only one ``conan install`` for the dependencies. 62 | 63 | 64 | Cons 65 | ---- 66 | 67 | - You cannot consume Conan packages with other mechanism than ``CMake find_package``, no ``package_info`` method has been 68 | declared. The logic for the consumer lives exclusively in the ``.cmake`` files installed by CMake, so if I want to use 69 | any package with other build system like ``Autotools`` I won't be able to do it. 70 | 71 | - Any other information about the libraries that a classic ``self.cppinfo`` object might have (like a compilation flag or definition), 72 | won't be applied to the targets automatically. 73 | 74 | - You need to build packages containing all the build_types in the same Conan binary package. The ``find_package`` 75 | mechanism will find only one ``XXXConfig.cmake`` file, so all the ```XXXTarget-{build_type}``` have to be together. 76 | 77 | - The targets are transitive but you need to "model" the dependencies in the ``XXXConfig.cmake`` files, by calling ``find_dependency``, so you are 78 | duplicating information that Conan already knows (dependency graph). 79 | 80 | 81 | How to try it 82 | ------------- 83 | 84 | - Open the "build.bat" or "build.sh" to see the steps of the example. If you run it, it will create the packages for "hello" and "bye" 85 | and will build the "project" changing the build_type and verifying that the linked dependencies are correct for the selected build_type. -------------------------------------------------------------------------------- /features/cmake/find_package/exported_targets_multiconfig/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/features/cmake/find_package/exported_targets_multiconfig/__init__.py -------------------------------------------------------------------------------- /features/cmake/find_package/exported_targets_multiconfig/build.bat: -------------------------------------------------------------------------------- 1 | pushd hello 2 | conan create . user/channel 3 | popd 4 | 5 | pushd bye 6 | conan create . user/channel 7 | popd 8 | 9 | pushd project 10 | rd /s /q "build" 11 | mkdir build 12 | pushd build 13 | 14 | conan install .. 15 | cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_paths.cmake 16 | cmake --build . --config Debug 17 | cmake --build . --config Release 18 | 19 | Debug\example 20 | Release\example 21 | 22 | popd 23 | popd 24 | -------------------------------------------------------------------------------- /features/cmake/find_package/exported_targets_multiconfig/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | pushd hello 5 | conan create . user/channel 6 | popd 7 | 8 | pushd bye 9 | conan create . user/channel 10 | popd 11 | 12 | pushd project 13 | rm -rf "build" 14 | mkdir build 15 | pushd build 16 | 17 | conan install .. 18 | cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_paths.cmake -DCMAKE_BUILD_TYPE=Debug 19 | cmake --build . 20 | ./example 21 | 22 | cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_paths.cmake -DCMAKE_BUILD_TYPE=Release 23 | cmake --build . 24 | ./example 25 | 26 | popd 27 | popd 28 | -------------------------------------------------------------------------------- /features/cmake/find_package/exported_targets_multiconfig/bye/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/features/cmake/find_package/exported_targets_multiconfig/bye/__init__.py -------------------------------------------------------------------------------- /features/cmake/find_package/exported_targets_multiconfig/bye/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake 2 | 3 | 4 | class ByeConan(ConanFile): 5 | name = "bye" 6 | version = "1.0" 7 | settings = "os", "compiler", "arch" 8 | options = {"shared": [True, False]} 9 | default_options = "shared=False" 10 | generators = "cmake_paths" 11 | exports_sources = "src/*" 12 | requires = "hello/1.0@user/channel" 13 | 14 | def build(self): 15 | for bt in ("Debug", "Release"): 16 | cmake = CMake(self, build_type=bt) 17 | cmake.definitions["CMAKE_TOOLCHAIN_FILE"] = "conan_paths.cmake" 18 | cmake.definitions["CMAKE_FIND_DEBUG_MODE"] = "ON" 19 | 20 | cmake.configure(source_folder="src") 21 | cmake.build() 22 | cmake.install() 23 | -------------------------------------------------------------------------------- /features/cmake/find_package/exported_targets_multiconfig/bye/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # CHANGE PROJECT NAME, SOURCES AND DEPENDANT TARGETS 4 | project(bye CXX) 5 | 6 | set(TARGET_NAME ${PROJECT_NAME}) 7 | set(${TARGET_NAME}_SRC bye.cpp) 8 | set(${TARGET_NAME}_HEADERS bye.h) 9 | set(TARGETS_TO_FIND hello) 10 | set(DEBUG_LIBRARY_SUFFIX "d") 11 | 12 | 13 | # GENERIC PART 14 | add_library(${TARGET_NAME} ${${TARGET_NAME}_SRC} ${${TARGET_NAME}_HEADERS}) 15 | set_target_properties(${TARGET_NAME} PROPERTIES 16 | PUBLIC_HEADER "${${TARGET_NAME}_HEADERS}" 17 | OUTPUT_NAME "${TARGET_NAME}$<$:${DEBUG_LIBRARY_SUFFIX}>") 18 | 19 | target_include_directories(${TARGET_NAME} PUBLIC 20 | "$" 21 | "$/${CMAKE_INSTALL_INCLUDEDIR}>") 22 | 23 | foreach(dep ${TARGETS_TO_FIND}) 24 | find_package(${dep} CONFIG) 25 | message("BUILD TYPE: ${CMAKE_BUILD_TYPE}") 26 | target_link_libraries(${TARGET_NAME} ${dep}::${dep}) 27 | endforeach() 28 | 29 | 30 | # Write the library and headers 31 | install(TARGETS ${TARGET_NAME} EXPORT ${TARGET_NAME}Targets 32 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 33 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 34 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 35 | PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") 36 | 37 | # Export the target to be used by other projects 38 | export(EXPORT ${TARGET_NAME}Targets 39 | FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}/${TARGET_NAME}Targets.cmake" 40 | NAMESPACE ${TARGET_NAME}:: 41 | ) 42 | 43 | set(ConfigPackageLocation lib/cmake/${TARGET_NAME}) 44 | 45 | # Install the exported target 46 | install(EXPORT ${TARGET_NAME}Targets 47 | FILE ${TARGET_NAME}Targets.cmake 48 | NAMESPACE ${TARGET_NAME}:: 49 | DESTINATION ${ConfigPackageLocation} 50 | ) 51 | 52 | # Install the XXXConfig.cmake file 53 | install( 54 | FILES 55 | ${TARGET_NAME}Config.cmake 56 | DESTINATION 57 | ${ConfigPackageLocation} 58 | ) 59 | -------------------------------------------------------------------------------- /features/cmake/find_package/exported_targets_multiconfig/bye/src/bye.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "bye.h" 3 | #include "hello.h" 4 | 5 | void bye(){ 6 | 7 | hello(); 8 | 9 | #ifdef NDEBUG 10 | std::cout << "bye World Release!" <:${DEBUG_LIBRARY_SUFFIX}>") 19 | 20 | target_include_directories(${TARGET_NAME} PUBLIC 21 | "$" 22 | "$/${CMAKE_INSTALL_INCLUDEDIR}>") 23 | 24 | foreach(dep ${TARGETS_TO_FIND}) 25 | find_package(${dep} CONFIG) 26 | target_link_libraries(${TARGET_NAME} ${dep}::${dep}) 27 | endforeach() 28 | 29 | 30 | # Write the library and headers 31 | install(TARGETS ${TARGET_NAME} EXPORT ${TARGET_NAME}Targets 32 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 33 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 34 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 35 | PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") 36 | 37 | # Export the target to be used by other projects 38 | export(EXPORT ${TARGET_NAME}Targets 39 | FILE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}/${TARGET_NAME}Targets.cmake" 40 | NAMESPACE ${TARGET_NAME}:: 41 | ) 42 | 43 | set(ConfigPackageLocation lib/cmake/${TARGET_NAME}) 44 | 45 | # Install the exported target 46 | install(EXPORT ${TARGET_NAME}Targets 47 | FILE ${TARGET_NAME}Targets.cmake 48 | NAMESPACE ${TARGET_NAME}:: 49 | DESTINATION ${ConfigPackageLocation} 50 | ) 51 | 52 | # Install the XXXConfig.cmake file 53 | install( 54 | FILES 55 | ${TARGET_NAME}Config.cmake 56 | DESTINATION 57 | ${ConfigPackageLocation} 58 | ) 59 | -------------------------------------------------------------------------------- /features/cmake/find_package/exported_targets_multiconfig/hello/src/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hello.h" 3 | 4 | void hello(){ 5 | #ifdef NDEBUG 6 | std::cout << "Hello World Release!" < 2 | #include "bye.h" 3 | 4 | int main() { 5 | bye(); 6 | } 7 | -------------------------------------------------------------------------------- /features/cmake/find_package/find_cmake_multi_generator_targets/README.md: -------------------------------------------------------------------------------- 1 | Using non-intrusive multi-config CMake with cmake_find_package_generator_multi 2 | ============================================================================== 3 | 4 | In this example 5 | --------------- 6 | 7 | We are using Conan to create for us the necessary ``XXXConfig.cmake`` scripts both for Release and Debug. 8 | Everything is based on the ``find_package`` feature and working with multi-config packages (Release/Debug) to avoid 9 | installing the dependencies every time we change from Debug to Release in the Visual Studio IDE. 10 | 11 | - We have a "hello" library consumed by a "bye" library and a project that uses the "bye" function. 12 | - The "hello" library has a ``package_info()`` method declaring the "hello" library name for the consumers. 13 | - The conan recipe uses a different binary package for any ``build_type``, one package for Debug and other for Release. 14 | - The same for the "bye" library. 15 | - There is a project using targets (CMake 3.x) and linking with "bye" (and hello because of the transitivity) 16 | 17 | Some useful details of this example 18 | ------------------------------------ 19 | 20 | - The ``CMakeLists.txt`` files for ``bye`` and ``hello`` are very simple, we are not installing nor exporting anything. 21 | - It is important to add the ``CONFIG`` option to ``find_package`` so that *module mode* is explicitly skipped by CMake. This helps to 22 | solve issues when there is for example a ``FindXXXX.cmake`` file in CMake's default modules directory that maybe is loaded instead of the 23 | ``XXXXConfig.cmake`` generated by Conan. 24 | 25 | This is the one for ``bye``: 26 | ```cmake 27 | find_package(hello CONFIG) 28 | add_library(bye bye.cpp) 29 | target_link_libraries(bye hello::hello) 30 | ``` 31 | 32 | - The recipes are using ``package_info()`` method for the consumers 33 | - The recipes are using ``package()`` method to extract the libraries and headers, instead of using cmake install. 34 | 35 | Pros 36 | ---- 37 | 38 | - You can consume the conan packages for ``hello`` and ``bye`` from any build system only specifying the generator 39 | that matches your needs. 40 | - You don't need to change anything in the ``CMakeLists.txt`` related to Conan. 41 | - The multi-config mechanism works good, it is very comfortable, You call ``conan install`` for debug and other for Release 42 | and you are done. 43 | - The generated targets are **completely transitive** and contain all the information about the dependencies. So you need 44 | call ``find_package`` for your direct dependency packages. With the classic CMake targets, you typically need to specify one ``find_package`` 45 | for each dependency that you need, directly or indirectly. 46 | 47 | 48 | Cons 49 | ---- 50 | 51 | - You have to assume that the cmake scripts created by this generator **ARE NOT** the same as the `CMake` installation modules files and they 52 | are not replaceable in most cases: 53 | 54 | - Because of the transitivity of the targets (you will need to change your CMakeLists if you were calling ``find_package`` for all the transitive deps) 55 | - The name of the targets and the library name to be used at `find_package(NAME)` might be different for the "official" one. 56 | 57 | 58 | How to try it 59 | ------------- 60 | 61 | - Open the "build.bat" or "build.sh" to see the steps of the example. If you run it, it will create the packages for "hello" and "bye" 62 | and will build the "project" changing the build_type and verifying that the linked dependencies are correct for the selected build_type. 63 | - If you are using Linux or Mac you can use almost the same steps in the run.bat adapted to your OSS -------------------------------------------------------------------------------- /features/cmake/find_package/find_cmake_multi_generator_targets/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/features/cmake/find_package/find_cmake_multi_generator_targets/__init__.py -------------------------------------------------------------------------------- /features/cmake/find_package/find_cmake_multi_generator_targets/build.bat: -------------------------------------------------------------------------------- 1 | pushd hello 2 | conan create . user/channel -s build_type=Debug 3 | conan create . user/channel -s build_type=Release 4 | popd 5 | 6 | pushd bye 7 | conan create . user/channel -s build_type=Debug 8 | conan create . user/channel -s build_type=Release 9 | popd 10 | 11 | pushd project 12 | 13 | rd /s /q "build" 14 | mkdir build 15 | pushd BUILD 16 | conan install .. -s build_type=Debug 17 | conan install .. -s build_type=Release 18 | cmake .. 19 | cmake --build . --config Debug 20 | cmake --build . --config Release 21 | Debug\example.exe 22 | Release\example.exe 23 | 24 | popd 25 | popd 26 | -------------------------------------------------------------------------------- /features/cmake/find_package/find_cmake_multi_generator_targets/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | pushd hello 5 | conan create . user/channel -s build_type=Debug 6 | conan create . user/channel -s build_type=Release 7 | popd 8 | 9 | pushd bye 10 | conan create . user/channel -s build_type=Debug 11 | conan create . user/channel -s build_type=Release 12 | popd 13 | 14 | pushd project 15 | 16 | rm -rf "build" 17 | mkdir build 18 | pushd build 19 | 20 | conan install .. -s build_type=Debug 21 | conan install .. -s build_type=Release 22 | 23 | cmake .. -DCMAKE_BUILD_TYPE=Debug 24 | cmake --build . 25 | ./example 26 | 27 | cmake .. -DCMAKE_BUILD_TYPE=Release 28 | cmake --build . 29 | ./example 30 | 31 | popd 32 | popd 33 | -------------------------------------------------------------------------------- /features/cmake/find_package/find_cmake_multi_generator_targets/bye/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/features/cmake/find_package/find_cmake_multi_generator_targets/bye/__init__.py -------------------------------------------------------------------------------- /features/cmake/find_package/find_cmake_multi_generator_targets/bye/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake 2 | 3 | 4 | class ByeConan(ConanFile): 5 | name = "bye" 6 | version = "1.0" 7 | settings = "os", "compiler", "arch", "build_type" 8 | options = {"shared": [True, False]} 9 | default_options = "shared=False" 10 | generators = "cmake_find_package_multi" 11 | exports_sources = "src/*" 12 | requires = "hello/1.0@user/channel" 13 | 14 | def build(self): 15 | cmake = CMake(self) 16 | cmake.configure(source_folder="src") 17 | cmake.build() 18 | 19 | def package(self): 20 | self.copy("*.h", dst="include", keep_path=False) 21 | self.copy("*.lib", dst="lib", keep_path=False) 22 | self.copy("*.dll", dst="bin", keep_path=False) 23 | self.copy("*.so", dst="lib", keep_path=False) 24 | self.copy("*.dylib", dst="lib", keep_path=False) 25 | self.copy("*.a", dst="lib", keep_path=False) 26 | 27 | def package_info(self): 28 | self.cpp_info.libs.append("bye") 29 | -------------------------------------------------------------------------------- /features/cmake/find_package/find_cmake_multi_generator_targets/bye/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(PackageTest CXX) 3 | 4 | find_package(hello CONFIG) 5 | add_library(bye bye.cpp) 6 | target_link_libraries(bye hello::hello) 7 | -------------------------------------------------------------------------------- /features/cmake/find_package/find_cmake_multi_generator_targets/bye/src/bye.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "bye.h" 3 | #include "hello.h" 4 | 5 | void bye(){ 6 | 7 | hello(); 8 | 9 | #ifdef NDEBUG 10 | std::cout << "bye World Release!" < 2 | #include "hello.h" 3 | 4 | void hello(){ 5 | #ifdef NDEBUG 6 | std::cout << "Hello World Release!" < 2 | #include "bye.h" 3 | 4 | int main() { 5 | bye(); 6 | } 7 | -------------------------------------------------------------------------------- /features/deployment/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | install 3 | md5.run 4 | -------------------------------------------------------------------------------- /features/deployment/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(MD5Encrypter) 3 | 4 | find_package(Poco CONFIG REQUIRED) 5 | 6 | add_executable(md5 md5.cpp) 7 | target_link_libraries(md5 Poco::Poco) 8 | 9 | install(TARGETS md5 10 | RUNTIME DESTINATION bin 11 | ARCHIVE DESTINATION lib 12 | LIBRARY DESTINATION lib) 13 | 14 | -------------------------------------------------------------------------------- /features/deployment/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | 5 | ROOT=${PWD} 6 | PREFIX=${PWD}/install 7 | 8 | mkdir -p build 9 | pushd build 10 | 11 | conan install .. -s build_type=Release --build missing 12 | cmake .. \ 13 | -DCMAKE_PREFIX_PATH=${PWD} \ 14 | -DCMAKE_BUILD_TYPE=Release \ 15 | -DCMAKE_INSTALL_PREFIX=${PREFIX} 16 | cmake --build . --target install 17 | 18 | TMPDIR=`dirname $(mktemp -u -t tmp.XXXXXXXXXX)` 19 | curl "https://github.com/megastep/makeself/releases/download/release-2.4.0/makeself-2.4.0.run" --output $TMPDIR/makeself.run -L 20 | chmod +x $TMPDIR/makeself.run 21 | $TMPDIR/makeself.run --target $TMPDIR/makeself 22 | 23 | python ${ROOT}/deploy.py $PREFIX 24 | 25 | $TMPDIR/makeself/makeself.sh $PREFIX ${ROOT}/md5.run "conan-generated makeself.sh" "./conan-entrypoint.sh" 26 | 27 | popd 28 | 29 | -------------------------------------------------------------------------------- /features/deployment/conanfile.txt: -------------------------------------------------------------------------------- 1 | [generators] 2 | cmake_find_package_multi 3 | json 4 | 5 | [requires] 6 | poco/1.9.4 7 | 8 | [options] 9 | *:shared=True 10 | -------------------------------------------------------------------------------- /features/deployment/deploy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 4 | 5 | from __future__ import print_function 6 | import os 7 | import json 8 | import sys 9 | from distutils.dir_util import copy_tree 10 | 11 | def get_dirs(): 12 | data = json.load(open("conanbuildinfo.json")) 13 | dep_lib_dirs = dict() 14 | dep_bin_dirs = dict() 15 | for dep in data["dependencies"]: 16 | root = dep["rootpath"] 17 | lib_paths = dep["lib_paths"] 18 | bin_paths = dep["bin_paths"] 19 | for lib_path in lib_paths: 20 | if os.listdir(lib_path): 21 | lib_dir = os.path.relpath(lib_path, root) 22 | dep_lib_dirs[lib_path] = lib_dir 23 | for bin_path in bin_paths: 24 | if os.listdir(bin_path): 25 | bin_dir = os.path.relpath(bin_path, root) 26 | dep_bin_dirs[bin_path] = bin_dir 27 | return dep_lib_dirs, dep_bin_dirs 28 | 29 | def chmod_plus_x(name): 30 | if os.name == 'posix': 31 | os.chmod(name, os.stat(name).st_mode | 0o111) 32 | 33 | def create_entry_point(destdir, dep_lib_dirs, dep_bin_dirs): 34 | executable = "md5" 35 | varname = "$PWD" 36 | def _format_dirs(dirs): 37 | return ":".join(["%s/%s" % (varname, d) for d in dirs]) 38 | path = _format_dirs(set(dep_bin_dirs.values())) 39 | ld_library_path = _format_dirs(set(dep_lib_dirs.values())) 40 | exe = varname + "/" + executable 41 | content = """#!/usr/bin/env bash 42 | set -ex 43 | export PATH=$PATH:{path} 44 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{ld_library_path} 45 | pushd $(dirname {exe}) 46 | $(basename {exe}) 47 | popd 48 | """.format(path=path, 49 | ld_library_path=ld_library_path, 50 | exe=exe) 51 | entrypoint = os.path.join(destdir, "conan-entrypoint.sh") 52 | with open(entrypoint, "w") as f: 53 | f.write(content) 54 | chmod_plus_x(entrypoint) 55 | 56 | def copy_files(destdir, dep_lib_dirs, dep_bin_dirs): 57 | for src_lib_dir, dst_lib_dir in dep_lib_dirs.items(): 58 | copy_tree(src_lib_dir, os.path.join(destdir, dst_lib_dir)) 59 | for src_bin_dir, dst_bin_dir in dep_bin_dirs.items(): 60 | copy_tree(src_bin_dir, os.path.join(destdir, dst_bin_dir)) 61 | 62 | def main(argv): 63 | dep_lib_dirs, dep_bin_dirs = get_dirs() 64 | print(dep_lib_dirs, dep_bin_dirs) 65 | copy_files(argv[1], dep_lib_dirs, dep_bin_dirs) 66 | create_entry_point(argv[1], dep_lib_dirs, dep_bin_dirs) 67 | 68 | if __name__ == '__main__': 69 | main(sys.argv) 70 | -------------------------------------------------------------------------------- /features/deployment/md5.cpp: -------------------------------------------------------------------------------- 1 | #include "Poco/MD5Engine.h" 2 | #include "Poco/DigestStream.h" 3 | 4 | #include 5 | 6 | int main(int argc, char** argv) 7 | { 8 | Poco::MD5Engine md5; 9 | std::string s = "abcdefghijklmnopqrstuvwxyz"; 10 | Poco::DigestOutputStream ds(md5); 11 | ds << s; 12 | ds.close(); 13 | std::cout << "MD5 of \"" << s << "\":" << std::endl; 14 | std::cout << Poco::DigestEngine::digestToHex(md5.digest()) << std::endl; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /features/editable/cmake/.gitignore: -------------------------------------------------------------------------------- 1 | hello/build 2 | say/build 3 | conanbuildinfo.txt 4 | conaninfo.txt 5 | graph_info.json 6 | conan.lock 7 | say/CMakeUserPresets.json 8 | hello/CMakeUserPresets.json 9 | -------------------------------------------------------------------------------- /features/editable/cmake/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO ON 2 | 3 | RMDIR /Q /S say\build 4 | RMDIR /Q /S hello\build 5 | 6 | REM Put say package in editable mode, and build it 7 | conan editable add say/ say/0.1@user/channel 8 | 9 | PUSHD "say" 10 | REM It is very important to install 2 configurations, if you are building later the 2 configs, so the toolchain is multi-config (runtime libs) 11 | REM There is a bug in 1.40, this needs to be done in the root folder 12 | conan install . -s build_type=Release 13 | conan install . -s build_type=Debug 14 | MKDIR "build" 15 | PUSHD "build" 16 | cmake .. -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake 17 | cmake --build . --config Release 18 | cmake --build . --config Debug 19 | POPD 20 | POPD 21 | 22 | REM Build hello consumer 23 | MKDIR "hello/build" 24 | PUSHD "hello/build" 25 | conan install .. -s build_type=Release 26 | conan install .. -s build_type=Debug 27 | cmake .. -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake 28 | cmake --build . --config Release 29 | cmake --build . --config Debug 30 | "Release/hello.exe" 31 | "Debug/hello.exe" 32 | POPD 33 | 34 | REM Do a modification in the source code of the editable say 35 | PUSHD "say/build" 36 | COPY ..\src\say2.cpp ..\src\say.cpp /Y 37 | TOUCH ..\src\say.cpp 38 | cmake --build . --config Release 39 | cmake --build . --config Debug 40 | POPD 41 | 42 | REM Build and execute the consumer depending on the editable 43 | PUSHD "hello/build" 44 | cmake --build . --config Release 45 | cmake --build . --config Debug 46 | "Release/hello.exe" 47 | "Debug/hello.exe" 48 | POPD 49 | 50 | 51 | conan editable remove say/0.1@user/channel 52 | 53 | # Restore the say.cpp file to keep the repo unchanged 54 | COPY say\src\original_say.cpp say\src\say.cpp /Y 55 | -------------------------------------------------------------------------------- /features/editable/cmake/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | rm -rf say/build/ 7 | rm -rf hello/build/ 8 | 9 | 10 | conan editable add say/ say/0.1@user/channel 11 | 12 | pushd say 13 | conan install . 14 | mkdir -p build/Release 15 | pushd build/Release 16 | cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake 17 | cmake --build . 18 | popd 19 | popd 20 | 21 | mkdir -p hello/build/Release 22 | pushd hello/build/Release 23 | conan install ../.. 24 | cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake 25 | cmake --build . 26 | ./hello 27 | popd 28 | 29 | # Modification to code (Changes the message 'hello' with 'bye') 30 | pushd say/build/Release 31 | cp ../../src/say2.cpp ../../src/say.cpp 32 | cmake --build . 33 | popd 34 | 35 | # build consumer again 36 | pushd hello/build/Release 37 | cmake --build . 38 | # This should print 'bye' instead of 'hello' 39 | ./hello 40 | popd 41 | 42 | conan editable remove say/0.1@user/channel 43 | 44 | # Restore the say.cpp file to keep the repo unchanged 45 | cp say/src/original_say.cpp say/src/say.cpp 46 | -------------------------------------------------------------------------------- /features/editable/cmake/hello/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(Hello) 4 | 5 | find_package(say REQUIRED) 6 | 7 | add_executable(hello src/hello.cpp) 8 | target_link_libraries(hello say::say) -------------------------------------------------------------------------------- /features/editable/cmake/hello/conanfile.txt: -------------------------------------------------------------------------------- 1 | [requires] 2 | say/0.1@user/channel 3 | 4 | [generators] 5 | CMakeToolchain 6 | CMakeDeps 7 | 8 | [layout] 9 | cmake_layout -------------------------------------------------------------------------------- /features/editable/cmake/hello/src/hello.cpp: -------------------------------------------------------------------------------- 1 | #include "say.h" 2 | 3 | int main() { 4 | say(); 5 | } -------------------------------------------------------------------------------- /features/editable/cmake/say/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(say CXX) 3 | 4 | add_library(say src/say.cpp) 5 | target_include_directories(say PUBLIC include) 6 | 7 | set_target_properties(say PROPERTIES PUBLIC_HEADER "include/say.h") 8 | install(TARGETS say) 9 | -------------------------------------------------------------------------------- /features/editable/cmake/say/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile 2 | from conan.tools.cmake import CMakeToolchain, CMake 3 | from conan.tools.layout import cmake_layout 4 | 5 | 6 | class SayConan(ConanFile): 7 | name = "say" 8 | version = "0.1" 9 | 10 | # Optional metadata 11 | license = "" 12 | author = " " 13 | url = "" 14 | description = "" 15 | topics = ("", "", "") 16 | 17 | # Binary configuration 18 | settings = "os", "compiler", "build_type", "arch" 19 | options = {"shared": [True, False], "fPIC": [True, False]} 20 | default_options = {"shared": False, "fPIC": True} 21 | 22 | # Sources are located in the same place as this recipe, copy them to the recipe 23 | exports_sources = "CMakeLists.txt", "src/*", "include/*" 24 | 25 | def config_options(self): 26 | if self.settings.os == "Windows": 27 | del self.options.fPIC 28 | 29 | def layout(self): 30 | cmake_layout(self) 31 | 32 | def generate(self): 33 | tc = CMakeToolchain(self) 34 | tc.generate() 35 | 36 | def build(self): 37 | cmake = CMake(self) 38 | cmake.configure() 39 | cmake.build() 40 | 41 | def package(self): 42 | cmake = CMake(self) 43 | cmake.install() 44 | 45 | def package_info(self): 46 | self.cpp_info.libs = ["say"] 47 | -------------------------------------------------------------------------------- /features/editable/cmake/say/include/say.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef WIN32 4 | #define say_EXPORT __declspec(dllexport) 5 | #else 6 | #define say_EXPORT 7 | #endif 8 | 9 | say_EXPORT void say(); 10 | -------------------------------------------------------------------------------- /features/editable/cmake/say/src/original_say.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "say.h" 3 | 4 | void say(){ 5 | #ifdef NDEBUG 6 | std::cout << "say/0.1: Hello World Release!\n"; 7 | #else 8 | std::cout << "say/0.1: Hello World Debug!\n"; 9 | #endif 10 | 11 | // ARCHITECTURES 12 | #ifdef _M_X64 13 | std::cout << " say/0.1: _M_X64 defined\n"; 14 | #endif 15 | 16 | #ifdef _M_IX86 17 | std::cout << " say/0.1: _M_IX86 defined\n"; 18 | #endif 19 | 20 | #if __i386__ 21 | std::cout << " say/0.1: __i386__ defined\n"; 22 | #endif 23 | 24 | #if __x86_64__ 25 | std::cout << " say/0.1: __x86_64__ defined\n"; 26 | #endif 27 | 28 | // Libstdc++ 29 | #if defined _GLIBCXX_USE_CXX11_ABI 30 | std::cout << " say/0.1: _GLIBCXX_USE_CXX11_ABI "<< _GLIBCXX_USE_CXX11_ABI << "\n"; 31 | #endif 32 | 33 | // COMPILER VERSIONS 34 | #if _MSC_VER 35 | std::cout << " say/0.1: _MSC_VER" << _MSC_VER<< "\n"; 36 | #endif 37 | 38 | #if _MSVC_LANG 39 | std::cout << " say/0.1: _MSVC_LANG" << _MSVC_LANG<< "\n"; 40 | #endif 41 | 42 | #if __cplusplus 43 | std::cout << " say/0.1: __cplusplus" << __cplusplus<< "\n"; 44 | #endif 45 | 46 | #if __INTEL_COMPILER 47 | std::cout << " say/0.1: __INTEL_COMPILER" << __INTEL_COMPILER<< "\n"; 48 | #endif 49 | 50 | #if __GNUC__ 51 | std::cout << " say/0.1: __GNUC__" << __GNUC__<< "\n"; 52 | #endif 53 | 54 | #if __GNUC_MINOR__ 55 | std::cout << " say/0.1: __GNUC_MINOR__" << __GNUC_MINOR__<< "\n"; 56 | #endif 57 | 58 | #if __clang_major__ 59 | std::cout << " say/0.1: __clang_major__" << __clang_major__<< "\n"; 60 | #endif 61 | 62 | #if __clang_minor__ 63 | std::cout << " say/0.1: __clang_minor__" << __clang_minor__<< "\n"; 64 | #endif 65 | 66 | #if __apple_build_version__ 67 | std::cout << " say/0.1: __apple_build_version__" << __apple_build_version__<< "\n"; 68 | #endif 69 | 70 | // SUBSYSTEMS 71 | 72 | #if __MSYS__ 73 | std::cout << " say/0.1: __MSYS__" << __MSYS__<< "\n"; 74 | #endif 75 | 76 | #if __MINGW32__ 77 | std::cout << " say/0.1: __MINGW32__" << __MINGW32__<< "\n"; 78 | #endif 79 | 80 | #if __MINGW64__ 81 | std::cout << " say/0.1: __MINGW64__" << __MINGW64__<< "\n"; 82 | #endif 83 | 84 | #if __CYGWIN__ 85 | std::cout << " say/0.1: __CYGWIN__" << __CYGWIN__<< "\n"; 86 | #endif 87 | } 88 | -------------------------------------------------------------------------------- /features/editable/cmake/say/src/say.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "say.h" 3 | 4 | void say(){ 5 | #ifdef NDEBUG 6 | std::cout << "say/0.1: Hello World Release!\n"; 7 | #else 8 | std::cout << "say/0.1: Hello World Debug!\n"; 9 | #endif 10 | 11 | // ARCHITECTURES 12 | #ifdef _M_X64 13 | std::cout << " say/0.1: _M_X64 defined\n"; 14 | #endif 15 | 16 | #ifdef _M_IX86 17 | std::cout << " say/0.1: _M_IX86 defined\n"; 18 | #endif 19 | 20 | #if __i386__ 21 | std::cout << " say/0.1: __i386__ defined\n"; 22 | #endif 23 | 24 | #if __x86_64__ 25 | std::cout << " say/0.1: __x86_64__ defined\n"; 26 | #endif 27 | 28 | // Libstdc++ 29 | #if defined _GLIBCXX_USE_CXX11_ABI 30 | std::cout << " say/0.1: _GLIBCXX_USE_CXX11_ABI "<< _GLIBCXX_USE_CXX11_ABI << "\n"; 31 | #endif 32 | 33 | // COMPILER VERSIONS 34 | #if _MSC_VER 35 | std::cout << " say/0.1: _MSC_VER" << _MSC_VER<< "\n"; 36 | #endif 37 | 38 | #if _MSVC_LANG 39 | std::cout << " say/0.1: _MSVC_LANG" << _MSVC_LANG<< "\n"; 40 | #endif 41 | 42 | #if __cplusplus 43 | std::cout << " say/0.1: __cplusplus" << __cplusplus<< "\n"; 44 | #endif 45 | 46 | #if __INTEL_COMPILER 47 | std::cout << " say/0.1: __INTEL_COMPILER" << __INTEL_COMPILER<< "\n"; 48 | #endif 49 | 50 | #if __GNUC__ 51 | std::cout << " say/0.1: __GNUC__" << __GNUC__<< "\n"; 52 | #endif 53 | 54 | #if __GNUC_MINOR__ 55 | std::cout << " say/0.1: __GNUC_MINOR__" << __GNUC_MINOR__<< "\n"; 56 | #endif 57 | 58 | #if __clang_major__ 59 | std::cout << " say/0.1: __clang_major__" << __clang_major__<< "\n"; 60 | #endif 61 | 62 | #if __clang_minor__ 63 | std::cout << " say/0.1: __clang_minor__" << __clang_minor__<< "\n"; 64 | #endif 65 | 66 | #if __apple_build_version__ 67 | std::cout << " say/0.1: __apple_build_version__" << __apple_build_version__<< "\n"; 68 | #endif 69 | 70 | // SUBSYSTEMS 71 | 72 | #if __MSYS__ 73 | std::cout << " say/0.1: __MSYS__" << __MSYS__<< "\n"; 74 | #endif 75 | 76 | #if __MINGW32__ 77 | std::cout << " say/0.1: __MINGW32__" << __MINGW32__<< "\n"; 78 | #endif 79 | 80 | #if __MINGW64__ 81 | std::cout << " say/0.1: __MINGW64__" << __MINGW64__<< "\n"; 82 | #endif 83 | 84 | #if __CYGWIN__ 85 | std::cout << " say/0.1: __CYGWIN__" << __CYGWIN__<< "\n"; 86 | #endif 87 | } 88 | -------------------------------------------------------------------------------- /features/editable/cmake/say/src/say2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "say.h" 3 | 4 | void say(){ 5 | #ifdef NDEBUG 6 | std::cout << "say/0.1: Bye World Release!\n"; 7 | #else 8 | std::cout << "say/0.1: Bye World Debug!\n"; 9 | #endif 10 | 11 | // ARCHITECTURES 12 | #ifdef _M_X64 13 | std::cout << " say/0.1: _M_X64 defined\n"; 14 | #endif 15 | 16 | #ifdef _M_IX86 17 | std::cout << " say/0.1: _M_IX86 defined\n"; 18 | #endif 19 | 20 | #if __i386__ 21 | std::cout << " say/0.1: __i386__ defined\n"; 22 | #endif 23 | 24 | #if __x86_64__ 25 | std::cout << " say/0.1: __x86_64__ defined\n"; 26 | #endif 27 | 28 | // Libstdc++ 29 | #if defined _GLIBCXX_USE_CXX11_ABI 30 | std::cout << " say/0.1: _GLIBCXX_USE_CXX11_ABI "<< _GLIBCXX_USE_CXX11_ABI << "\n"; 31 | #endif 32 | 33 | // COMPILER VERSIONS 34 | #if _MSC_VER 35 | std::cout << " say/0.1: _MSC_VER" << _MSC_VER<< "\n"; 36 | #endif 37 | 38 | #if _MSVC_LANG 39 | std::cout << " say/0.1: _MSVC_LANG" << _MSVC_LANG<< "\n"; 40 | #endif 41 | 42 | #if __cplusplus 43 | std::cout << " say/0.1: __cplusplus" << __cplusplus<< "\n"; 44 | #endif 45 | 46 | #if __INTEL_COMPILER 47 | std::cout << " say/0.1: __INTEL_COMPILER" << __INTEL_COMPILER<< "\n"; 48 | #endif 49 | 50 | #if __GNUC__ 51 | std::cout << " say/0.1: __GNUC__" << __GNUC__<< "\n"; 52 | #endif 53 | 54 | #if __GNUC_MINOR__ 55 | std::cout << " say/0.1: __GNUC_MINOR__" << __GNUC_MINOR__<< "\n"; 56 | #endif 57 | 58 | #if __clang_major__ 59 | std::cout << " say/0.1: __clang_major__" << __clang_major__<< "\n"; 60 | #endif 61 | 62 | #if __clang_minor__ 63 | std::cout << " say/0.1: __clang_minor__" << __clang_minor__<< "\n"; 64 | #endif 65 | 66 | #if __apple_build_version__ 67 | std::cout << " say/0.1: __apple_build_version__" << __apple_build_version__<< "\n"; 68 | #endif 69 | 70 | // SUBSYSTEMS 71 | 72 | #if __MSYS__ 73 | std::cout << " say/0.1: __MSYS__" << __MSYS__<< "\n"; 74 | #endif 75 | 76 | #if __MINGW32__ 77 | std::cout << " say/0.1: __MINGW32__" << __MINGW32__<< "\n"; 78 | #endif 79 | 80 | #if __MINGW64__ 81 | std::cout << " say/0.1: __MINGW64__" << __MINGW64__<< "\n"; 82 | #endif 83 | 84 | #if __CYGWIN__ 85 | std::cout << " say/0.1: __CYGWIN__" << __CYGWIN__<< "\n"; 86 | #endif 87 | } 88 | -------------------------------------------------------------------------------- /features/emscripten/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | conaninfo.txt 3 | conanbuildinfo.txt 4 | conan_imports_manifest.txt 5 | activate.ps1 6 | activate.bat 7 | activate.sh 8 | deactivate.ps1 9 | deactivate.bat 10 | deactivate.sh 11 | -------------------------------------------------------------------------------- /features/emscripten/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(conan-hello-emscripten) 4 | 5 | include(conanbuildinfo.cmake) 6 | conan_basic_setup() 7 | 8 | add_executable(${PROJECT_NAME} main.cpp) 9 | 10 | target_include_directories(${PROJECT_NAME} PRIVATE ${CONAN_INCLUDE_DIRS}) 11 | target_link_libraries(${PROJECT_NAME} PRIVATE ${CONAN_LIBS}) 12 | 13 | set_target_properties(${PROJECT_NAME} PROPERTIES 14 | SUFFIX ".html" 15 | LINK_FLAGS "--emrun") 16 | 17 | install(TARGETS ${PROJECT_NAME} 18 | RUNTIME DESTINATION bin 19 | LIBRARY DESTINATION lib 20 | ARCHIVE DESTINATION lib) 21 | 22 | install(FILES 23 | ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.js 24 | ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.wasm 25 | DESTINATION bin) 26 | -------------------------------------------------------------------------------- /features/emscripten/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | conan remove conan-hello-emscripten/* -f 4 | conan create . conan/testing --profile:host=emscripten.profile --profile:build=default --build missing 5 | conan install conanfile.txt --profile:host=emscripten.profile --profile:build=default --build missing 6 | -------------------------------------------------------------------------------- /features/emscripten/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | 5 | conan remove conan-hello-emscripten/* -f 6 | conan create . conan/testing --profile:host=emscripten.profile --profile:build=default --build missing 7 | conan install conanfile.txt --profile:host=emscripten.profile --profile:build=default 8 | -------------------------------------------------------------------------------- /features/emscripten/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake 2 | 3 | 4 | class ConanHelloEmscripten(ConanFile): 5 | name = "conan-hello-emscripten" 6 | version = "1.0" 7 | description = "hello-world example of conan usage with Emscripten" 8 | topics = ("conan", "hello", "emscripten", "js", "javascript") 9 | license = "MIT" 10 | url = "https://github.com/conan-io/examples" 11 | homepage = "https://github.com/conan-io/examples" 12 | settings = {"os": ["Emscripten"]} 13 | requires = "zlib/1.2.11" 14 | exports_sources = ["CMakeLists.txt", "main.cpp"] 15 | generators = ["cmake"] 16 | 17 | def _configure_cmake(self): 18 | cmake = CMake(self) 19 | cmake.configure() 20 | return cmake 21 | 22 | def build(self): 23 | cmake = self._configure_cmake() 24 | cmake.build() 25 | 26 | def package(self): 27 | cmake = self._configure_cmake() 28 | cmake.install() 29 | -------------------------------------------------------------------------------- /features/emscripten/conanfile.txt: -------------------------------------------------------------------------------- 1 | [requires] 2 | conan-hello-emscripten/1.0@conan/testing 3 | [generators] 4 | virtualenv 5 | [imports] 6 | bin, *.html -> ./bin 7 | bin, *.wasm -> ./bin 8 | bin, *.js -> ./bin 9 | -------------------------------------------------------------------------------- /features/emscripten/emscripten.profile: -------------------------------------------------------------------------------- 1 | [settings] 2 | os=Emscripten 3 | arch=wasm 4 | compiler=clang 5 | compiler.version=14 6 | build_type=Release 7 | 8 | [build_requires] 9 | emsdk/2.0.30 10 | -------------------------------------------------------------------------------- /features/emscripten/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | std::cout << "Using zlib version: " << zlibVersion() << std::endl; 7 | } 8 | -------------------------------------------------------------------------------- /features/emscripten/run.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | call activate.bat 3 | emrun bin\conan-hello-emscripten.html 4 | -------------------------------------------------------------------------------- /features/emscripten/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | source activate.sh 4 | emrun ./bin/conan-hello-emscripten.html 5 | -------------------------------------------------------------------------------- /features/integrate_build_system/build.bat: -------------------------------------------------------------------------------- 1 | python build.py -------------------------------------------------------------------------------- /features/integrate_build_system/build.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | 4 | 5 | def run(cmd): 6 | ret = os.system(cmd) 7 | if ret != 0: 8 | raise Exception("Failed command: %s" % cmd) 9 | 10 | 11 | def main(): 12 | run("conan create waf-generator user/channel") 13 | run("conan create waf-installer user/channel") 14 | run("conan create waf-build-helper user/channel") 15 | run("conan create waf-mylib user/channel -s compiler.cppstd=14") 16 | run("conan create mylib-consumer waf-consumer/1.0@user/channel -s compiler.cppstd=14") 17 | 18 | 19 | if __name__ == '__main__': 20 | main() 21 | -------------------------------------------------------------------------------- /features/integrate_build_system/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | python build.py -------------------------------------------------------------------------------- /features/integrate_build_system/mylib-consumer/conanfile.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from conans import ConanFile, python_requires 4 | 5 | waf_import = python_requires("waf-build-helper/0.1@user/channel") 6 | 7 | 8 | class TestWafConan(ConanFile): 9 | settings = "os", "compiler", "build_type", "arch" 10 | name = "waf-consumer" 11 | generators = "Waf" 12 | requires = "mylib-waf/1.0@user/channel" 13 | build_requires = "WafGen/0.1@user/channel", "waf/2.0.19@user/channel" 14 | exports_sources = "wscript", "main.cpp" 15 | 16 | def build(self): 17 | waf = waf_import.WafBuildEnvironment(self) 18 | waf.configure() 19 | waf.build() 20 | -------------------------------------------------------------------------------- /features/integrate_build_system/mylib-consumer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | MyLib mylib; 5 | mylib.PrintMessage("HELLO CONAN-WAF TEST!"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /features/integrate_build_system/mylib-consumer/wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | 4 | top = '.' 5 | out = 'build' 6 | 7 | 8 | def options(opt): 9 | opt.load('compiler_cxx') 10 | 11 | 12 | def configure(conf): 13 | conf.load('compiler_cxx') 14 | conf.load('waf_conan_libs_info', tooldir='.') 15 | conf.load('waf_conan_toolchain', tooldir='.') 16 | 17 | 18 | def build(bld): 19 | bld.program(source='main.cpp', target='app', use=bld.env.CONAN_LIBS) 20 | -------------------------------------------------------------------------------- /features/integrate_build_system/waf-build-helper/conanfile.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | from conans import ConanFile, tools 4 | from waf_environment import WafBuildEnvironment 5 | 6 | 7 | class PythonRequires(ConanFile): 8 | name = "waf-build-helper" 9 | version = "0.1" 10 | exports = "waf_environment.py" 11 | -------------------------------------------------------------------------------- /features/integrate_build_system/waf-build-helper/waf_environment.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | from conans import ConanFile, tools, __version__ as conan_version 4 | from conans.client.build.compiler_flags import libcxx_flag, libcxx_define, format_defines 5 | from conans.model.version import Version 6 | from conans.errors import ConanException 7 | 8 | 9 | class WafBuildEnvironment(object): 10 | def __init__(self, conanfile): 11 | self._conanfile = conanfile 12 | self._settings = self._conanfile.settings 13 | self._arch = self._ss("arch") 14 | self._os = self._ss("os") 15 | self._compiler = self._ss("compiler") 16 | self._compiler_version = self._ss("compiler.version") 17 | self._compiler_libcxx = self._ss("compiler.libcxx") 18 | self._compiler_cppstd = self._ss("compiler.cppstd") 19 | self._build_type = self._ss("build_type") 20 | self._compiler_runtime = self._ss("compiler.runtime") 21 | self._arch_conan2waf = {'x86': 'x86', 'x86_64': 'x64'} 22 | 23 | def _gcc_ver_conan2waf(self, conan_version): 24 | version = [v for v in conan_version.split('.', 3)] 25 | while len(version) < 3: 26 | version.append('0') 27 | return "('{}', '{}', '{}')".format(version[0], version[1], version[2]) 28 | 29 | def _libcxx_flags(self, compiler, libcxx): 30 | lib_flags = [] 31 | if libcxx: 32 | if conan_version >= Version("1.26"): 33 | stdlib_define = libcxx_define(self._settings) 34 | cxxf = libcxx_flag(self._settings) 35 | else: 36 | stdlib_define = libcxx_define(compiler=compiler, libcxx=libcxx) 37 | cxxf = libcxx_flag(compiler=compiler, libcxx=libcxx) 38 | 39 | lib_flags.extend(format_defines([stdlib_define])) 40 | if cxxf: 41 | lib_flags.append(cxxf) 42 | 43 | return lib_flags 44 | 45 | def _cppstd_flag(self): 46 | if conan_version >= Version("1.24"): 47 | return tools.cppstd_flag(self._settings) 48 | else: 49 | from conans.client.build.cppstd_flags import cppstd_flag, cppstd_from_settings 50 | compiler = self._settings.get_safe("compiler") 51 | compiler_version = self._settings.get_safe("compiler.version") 52 | cppstd = cppstd_from_settings(self._settings) 53 | return cppstd_flag(compiler, compiler_version, cppstd) 54 | 55 | 56 | def _toolchain_content(self): 57 | sections = [] 58 | sections.append("def configure(conf):") 59 | sections.append(" if not conf.env.CXXFLAGS:") 60 | sections.append(" conf.env.CXXFLAGS = []") 61 | sections.append(" if not conf.env.LINKFLAGS:") 62 | sections.append(" conf.env.LINKFLAGS = []") 63 | if "Visual Studio" in self._compiler: 64 | # first we set the options for the compiler, then load 65 | if self._compiler_version: 66 | sections.append(" conf.env.MSVC_VERSION = '{}.0'".format( 67 | self._compiler_version)) 68 | try: 69 | sections.append(" conf.env.MSVC_TARGETS = '{}'".format( 70 | self._arch_conan2waf[self._arch])) 71 | except KeyError: 72 | raise ConanException( 73 | "Architecture '%s' not supported" % self._arch) 74 | 75 | sections.append(" conf.env.CXXFLAGS.append('/{}')".format( 76 | self._compiler_runtime)) 77 | 78 | sections.append(" conf.env.CXXFLAGS.extend(['/EHsc'])") 79 | if self._build_type == "Debug": 80 | sections.append(" conf.env.CXXFLAGS.extend(['/Zi', '/FS'])") 81 | sections.append(" conf.env.LINKFLAGS.extend(['/DEBUG'])") 82 | elif self._build_type == "Release": 83 | sections.append( 84 | " conf.env.CXXFLAGS.extend(['/O2', '/Ob1', '/DNDEBUG'])") 85 | else: 86 | sections.append(" conf.env.CC_VERSION = {}".format( 87 | self._gcc_ver_conan2waf(self._compiler_version))) 88 | 89 | cxxf = self._libcxx_flags( 90 | compiler=self._compiler, libcxx=self._compiler_libcxx) 91 | cxxf.append(self._cppstd_flag()) 92 | for flag in cxxf: 93 | sections.append( 94 | " conf.env.CXXFLAGS.append('{}')".format(flag)) 95 | 96 | if self._build_type == "Debug": 97 | sections.append(" conf.env.CXXFLAGS.extend(['-g'])") 98 | elif self._build_type == "Release": 99 | sections.append(" conf.env.CXXFLAGS.extend(['-O3'])") 100 | sections.append("\n") 101 | return "\n".join(sections) 102 | 103 | def _save_toolchain_file(self): 104 | filename = "waf_conan_toolchain.py" 105 | content = self._toolchain_content() 106 | output_path = self._conanfile.build_folder 107 | with open(os.path.join(output_path, filename), 'w') as output_file: 108 | output_file.write(content) 109 | self._conanfile.output.info("Waf Toolchain File created: %s" % (filename)) 110 | 111 | def configure(self, args=None): 112 | self._save_toolchain_file() 113 | args = args or [] 114 | command = "waf configure " + " ".join(arg for arg in args) 115 | if self._compiler_version and "Visual Studio" in self._compiler: 116 | command = command + \ 117 | '--msvc_version="msvc {}.0"'.format(self._compiler_version) 118 | with tools.vcvars(self._settings): 119 | self._run(command) 120 | 121 | def build(self, args=None): 122 | args = args or [] 123 | command = "waf build " + " ".join(arg for arg in args) 124 | with tools.vcvars(self._settings): 125 | self._run(command) 126 | 127 | def _run(self, command): 128 | try: 129 | self._conanfile.run(command) 130 | except Exception as e: 131 | raise ConanException("Error running: {} ({})".format(command, str(e))) 132 | 133 | def _ss(self, setname): 134 | """safe setting""" 135 | return self._settings.get_safe(setname) 136 | 137 | def _so(self, setname): 138 | """safe option""" 139 | return self._conanfile.options.get_safe(setname) 140 | -------------------------------------------------------------------------------- /features/integrate_build_system/waf-generator/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans.model import Generator 2 | from conans import ConanFile 3 | 4 | 5 | class Waf(Generator): 6 | def _remove_lib_extension(self, libs): 7 | return [lib[0:-4] if lib.endswith(".lib") else lib for lib in libs] 8 | 9 | @property 10 | def filename(self): 11 | return "waf_conan_libs_info.py" 12 | 13 | @property 14 | def content(self): 15 | sections = [] 16 | sections.append("def configure(ctx):") 17 | conan_libs = [] 18 | for dep_name, info in self.deps_build_info.dependencies: 19 | if dep_name not in self.conanfile.build_requires: 20 | dep_name = dep_name.replace("-", "_") 21 | sections.append(" ctx.env.INCLUDES_{} = {}".format( 22 | dep_name, info.include_paths)) 23 | sections.append(" ctx.env.LIBPATH_{} = {}".format( 24 | dep_name, info.lib_paths)) 25 | sections.append(" ctx.env.LIB_{} = {}".format( 26 | dep_name, self._remove_lib_extension(info.libs))) 27 | conan_libs.append(dep_name) 28 | sections.append(" ctx.env.CONAN_LIBS = {}".format(conan_libs)) 29 | sections.append("") 30 | return "\n".join(sections) 31 | 32 | 33 | class WafGeneratorPackage(ConanFile): 34 | name = "WafGen" 35 | version = "0.1" 36 | license = "MIT" 37 | -------------------------------------------------------------------------------- /features/integrate_build_system/waf-installer/LICENSE: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 8 | 2. Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | 12 | 3. The name of the author may not be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 16 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 19 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /features/integrate_build_system/waf-installer/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, tools 2 | import os 3 | 4 | 5 | class WAFInstallerConan(ConanFile): 6 | name = "waf" 7 | version = "2.0.19" 8 | description = "Waf is a Python-based build system" 9 | settings = "os_build" 10 | homepage = "https://gitlab.com/ita1024/waf" 11 | license = "BSD" 12 | exports_sources = ["LICENSE"] 13 | 14 | def build(self): 15 | source_url = "https://waf.io/waf-%s" % (self.version) 16 | self.output.warn("Downloading Waf build system: %s" % (source_url)) 17 | tools.download(source_url, "waf") 18 | if self.settings.os_build == "Windows": 19 | tools.download( 20 | "https://gitlab.com/ita1024/waf/raw/waf-{}/utils/waf.bat".format(self.version), "waf.bat") 21 | elif self.settings.os_build == "Linux" or self.settings.os_build == "Macos": 22 | self.run("chmod 755 waf") 23 | 24 | def package(self): 25 | self.copy(pattern="LICENSE", src='.', dst="licenses") 26 | self.copy('waf', src='.', dst="bin", keep_path=False) 27 | self.copy('waf.bat', src='.', dst="bin", keep_path=False) 28 | 29 | def package_info(self): 30 | self.output.info("Using Waf %s version" % self.version) 31 | self.env_info.PATH.append(os.path.join(self.package_folder, "bin")) 32 | -------------------------------------------------------------------------------- /features/integrate_build_system/waf-mylib/conanfile.py: -------------------------------------------------------------------------------- 1 | import os 2 | from conans import ConanFile, python_requires 3 | 4 | 5 | class MyLibConan(ConanFile): 6 | python_requires("waf-build-helper/0.1@user/channel") 7 | settings = "os", "compiler", "build_type", "arch" 8 | name = "mylib-waf" 9 | version = "1.0" 10 | license = "MIT" 11 | author = "Conan Team" 12 | description = "Just a simple example of using Conan to package a Waf lib" 13 | topics = ("conan", "libs", "Waf") 14 | exports = "LICENSE" 15 | exports_sources = "wscript", "src/mylib.cpp", "include/mylib.hpp" 16 | build_requires = "waf/2.0.19@user/channel" 17 | 18 | def build(self): 19 | waf = self.python_requires["waf-build-helper"].module.WafBuildEnvironment(self) 20 | waf.configure() 21 | waf.build() 22 | 23 | def package(self): 24 | self.copy("*.hpp", dst="include", src="include", keep_path=False) 25 | self.copy("*.lib", dst="lib", src="build", keep_path=False) 26 | self.copy("*.dll", dst="bin", keep_path=False) 27 | self.copy("*.dylib*", dst="lib", src="build", keep_path=False) 28 | self.copy("*.so", dst="lib", src="build", keep_path=False) 29 | self.copy("*.a", dst="lib", src="build", keep_path=False) 30 | self.copy("LICENSE", dst="licenses", src=".", keep_path=False) 31 | 32 | def package_info(self): 33 | self.cpp_info.libs = ["mylib"] 34 | -------------------------------------------------------------------------------- /features/integrate_build_system/waf-mylib/include/mylib.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class MyLib 6 | { 7 | public: 8 | MyLib() = default; 9 | ~MyLib () = default; 10 | void PrintMessage(const std::string& message); 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /features/integrate_build_system/waf-mylib/src/mylib.cpp: -------------------------------------------------------------------------------- 1 | #include "../include/mylib.hpp" 2 | 3 | #include 4 | 5 | void MyLib::PrintMessage(const std::string & message) 6 | { 7 | std::cout << message << std::endl; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /features/integrate_build_system/waf-mylib/wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | 4 | top = '.' 5 | out = 'build' 6 | 7 | 8 | def options(opt): 9 | opt.load('compiler_cxx') 10 | 11 | 12 | def configure(conf): 13 | conf.load('compiler_cxx') 14 | conf.load('waf_conan_toolchain', tooldir='.') 15 | 16 | 17 | def build(bld): 18 | bld.stlib(target='mylib', source='./src/mylib.cpp') 19 | -------------------------------------------------------------------------------- /features/lockfiles/build_order/app1/conanfile.py: -------------------------------------------------------------------------------- 1 | 2 | from conans import ConanFile 3 | 4 | required_conan_version = ">=1.28" 5 | 6 | class App1Conan(ConanFile): 7 | requires = "libd/[>0.0 <1.0]@user/testing" 8 | -------------------------------------------------------------------------------- /features/lockfiles/build_order/app2/conanfile.py: -------------------------------------------------------------------------------- 1 | 2 | from conans import ConanFile 3 | 4 | required_conan_version = ">=1.28" 5 | 6 | class App2Conan(ConanFile): 7 | requires = "libc/[>0.0 <1.0]@user/testing" 8 | -------------------------------------------------------------------------------- /features/lockfiles/build_order/build.bat: -------------------------------------------------------------------------------- 1 | python build.py -------------------------------------------------------------------------------- /features/lockfiles/build_order/build.py: -------------------------------------------------------------------------------- 1 | import os, json, shutil 2 | import subprocess 3 | from contextlib import contextmanager 4 | 5 | 6 | def run(cmd, assert_error=False): 7 | print("*********** Running: %s" % cmd) 8 | ret = os.system(cmd) 9 | if ret == 0 and assert_error: 10 | raise Exception("Command unexpectedly succedeed: %s" % cmd) 11 | if ret != 0 and not assert_error: 12 | raise Exception("Failed command: %s" % cmd) 13 | 14 | def load(filename): 15 | with open(filename, "r") as f: 16 | return f.read() 17 | 18 | def rm(path): 19 | if os.path.isfile(path): 20 | os.remove(path) 21 | elif os.path.isdir(path): 22 | shutil.rmtree(path) 23 | 24 | @contextmanager 25 | def chdir(path): 26 | current_path = os.getcwd() 27 | try: 28 | os.chdir(path) 29 | yield 30 | finally: 31 | os.chdir(current_path) 32 | 33 | @contextmanager 34 | def setenv(key, value): 35 | old_value = os.environ.get(key) 36 | os.environ[key] = value 37 | try: 38 | yield 39 | finally: 40 | if old_value is not None: 41 | os.environ[key] = old_value 42 | 43 | 44 | def clean(): 45 | rm("tmp") 46 | rm("app1.lock") 47 | rm("app2.lock") 48 | rm("build_order.json") 49 | rm("build_order2.json") 50 | 51 | 52 | def build_order(): 53 | clean() 54 | 55 | run("conan config set general.default_package_id_mode=full_version_mode") 56 | run("conan export liba liba/0.1@user/testing") 57 | run("conan export libb libb/0.1@user/testing") 58 | run("conan export libc libc/0.1@user/testing") 59 | run("conan export libd libd/0.1@user/testing") 60 | run("conan export app1 app1/0.1@user/testing") 61 | run("conan export app2 app2/0.1@user/testing") 62 | 63 | run("conan lock create --reference=app1/0.1@user/testing --lockfile-out=app1.lock") 64 | print(load("app1.lock")) 65 | run("conan lock build-order app1.lock --json=build_order.json") 66 | print(load("build_order.json")) 67 | 68 | run("conan install app1/0.1@user/testing --build=missing") 69 | run("conan install app2/0.1@user/testing --build=missing") 70 | 71 | run("conan lock create --reference=app1/0.1@user/testing --lockfile-out=app1.lock") 72 | print(load("app1.lock")) 73 | run("conan lock build-order app1.lock --json=build_order.json") 74 | print(load("build_order.json")) # Empty [] 75 | 76 | run("conan lock create --reference=app1/0.1@user/testing --lockfile-out=app1.lock --build") 77 | print(load("app1.lock")) 78 | run("conan lock build-order app1.lock --json=build_order.json") 79 | print(load("build_order.json")) # All deps 80 | 81 | # Modifying libb outside the version range 82 | run("conan create libb libb/2.0@user/testing") 83 | run("conan lock create --reference=app1/0.1@user/testing --lockfile-out=app1.lock") 84 | print(load("app1.lock")) 85 | run("conan lock build-order app1.lock --json=build_order.json") 86 | print(load("build_order.json")) 87 | 88 | # Modifying libb, what needs to be built? 89 | run("conan create libb libb/0.2@user/testing") 90 | run("conan lock create --reference=app1/0.1@user/testing --lockfile-out=app1.lock") 91 | print(load("app1.lock")) 92 | run("conan lock build-order app1.lock --json=build_order.json") 93 | print(load("build_order.json")) 94 | run("conan lock create --reference=app2/0.1@user/testing --lockfile-out=app2.lock") 95 | print(load("app2.lock")) 96 | run("conan lock build-order app2.lock --json=build_order2.json") 97 | print(load("build_order2.json")) 98 | 99 | 100 | 101 | clean() 102 | 103 | 104 | if __name__ == '__main__': 105 | home = os.path.abspath(os.path.join(os.path.dirname(__file__), "tmp")) 106 | with setenv("CONAN_USER_HOME", home): 107 | build_order() 108 | 109 | -------------------------------------------------------------------------------- /features/lockfiles/build_order/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | python build.py -------------------------------------------------------------------------------- /features/lockfiles/build_order/liba/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, tools 2 | 3 | required_conan_version = ">=1.28" 4 | 5 | class PkgaConan(ConanFile): 6 | pass 7 | -------------------------------------------------------------------------------- /features/lockfiles/build_order/libb/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile 2 | 3 | required_conan_version = ">=1.28" 4 | 5 | class LibBConan(ConanFile): 6 | requires = "liba/[>0.0 <1.0]@user/testing" 7 | -------------------------------------------------------------------------------- /features/lockfiles/build_order/libc/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile 2 | 3 | required_conan_version = ">=1.28" 4 | 5 | class LibCConan(ConanFile): 6 | requires = "liba/[>0.0 <1.0]@user/testing" 7 | -------------------------------------------------------------------------------- /features/lockfiles/build_order/libd/conanfile.py: -------------------------------------------------------------------------------- 1 | 2 | from conans import ConanFile 3 | 4 | required_conan_version = ">=1.28" 5 | 6 | class LibDConan(ConanFile): 7 | requires = "libb/[>0.0 <1.0]@user/testing", "libc/[>0.0 <1.0]@user/testing" 8 | -------------------------------------------------------------------------------- /features/lockfiles/ci/.gitignore: -------------------------------------------------------------------------------- 1 | release/ 2 | bo.json -------------------------------------------------------------------------------- /features/lockfiles/ci/app1/conanfile.py: -------------------------------------------------------------------------------- 1 | 2 | from conans import ConanFile 3 | 4 | required_conan_version = ">=1.28" 5 | 6 | class App1Conan(ConanFile): 7 | settings = "build_type" 8 | requires = "libd/[>0.0 <1.0]@user/testing" 9 | -------------------------------------------------------------------------------- /features/lockfiles/ci/app2/conanfile.py: -------------------------------------------------------------------------------- 1 | 2 | from conans import ConanFile 3 | 4 | required_conan_version = ">=1.28" 5 | 6 | class App2Conan(ConanFile): 7 | settings = "build_type" 8 | requires = "libc/[>0.0 <1.0]@user/testing" 9 | -------------------------------------------------------------------------------- /features/lockfiles/ci/build.bat: -------------------------------------------------------------------------------- 1 | python build.py -------------------------------------------------------------------------------- /features/lockfiles/ci/build.py: -------------------------------------------------------------------------------- 1 | import os, json, shutil 2 | import subprocess 3 | from contextlib import contextmanager 4 | 5 | 6 | def run(cmd, assert_error=False): 7 | print("*********** Running: %s" % cmd) 8 | ret = os.system(cmd) 9 | if ret == 0 and assert_error: 10 | raise Exception("Command unexpectedly succedeed: %s" % cmd) 11 | if ret != 0 and not assert_error: 12 | raise Exception("Failed command: %s" % cmd) 13 | 14 | def load(filename): 15 | with open(filename, "r") as f: 16 | return f.read() 17 | 18 | def save(filename, content): 19 | with open(filename, "w") as f: 20 | return f.write(content) 21 | 22 | 23 | def rm(path): 24 | if os.path.isfile(path): 25 | os.remove(path) 26 | elif os.path.isdir(path): 27 | shutil.rmtree(path) 28 | 29 | @contextmanager 30 | def chdir(path): 31 | current_path = os.getcwd() 32 | try: 33 | os.chdir(path) 34 | yield 35 | finally: 36 | os.chdir(current_path) 37 | 38 | @contextmanager 39 | def setenv(key, value): 40 | old_value = os.environ.get(key) 41 | os.environ[key] = value 42 | try: 43 | yield 44 | finally: 45 | if old_value is not None: 46 | os.environ[key] = old_value 47 | 48 | 49 | def clean(): 50 | rm("tmp") 51 | rm("locks") 52 | rm("bo_release.json") 53 | rm("bo_debug.json") 54 | 55 | 56 | def ci_pipeline(): 57 | clean() 58 | run("conan config set general.default_package_id_mode=full_version_mode") 59 | for config in ("Release", "Debug"): 60 | run("conan create liba liba/0.1@user/testing -s build_type=%s" % config) 61 | run("conan create libb libb/0.1@user/testing -s build_type=%s" % config) 62 | run("conan create libc libc/0.1@user/testing -s build_type=%s" % config) 63 | run("conan create libd libd/0.1@user/testing -s build_type=%s" % config) 64 | run("conan create app1 app1/0.1@user/testing -s build_type=%s" % config) 65 | run("conan create app2 app2/0.1@user/testing -s build_type=%s" % config) 66 | 67 | # A developer does some change to the libb 68 | with chdir("libb"): 69 | libb = load("conanfile.py") 70 | libb = libb + "# Some changes" 71 | save("conanfile.py", libb) 72 | 73 | run("conan lock create conanfile.py --name=libb --version=0.2 " 74 | "--user=user --channel=testing --lockfile-out=../locks/libb_deps_base.lock --base") 75 | 76 | # Even if liba gets a new 0.2 version, the lockfile will avoid it 77 | run("conan create liba liba/0.2@user/testing") 78 | with chdir("libb"): 79 | # This will be useful to capture the revision 80 | run("conan export . libb/0.2@user/testing --lockfile=../locks/libb_deps_base.lock " 81 | "--lockfile-out=../locks/libb_base.lock") 82 | print(load("../locks/libb_base.lock")) 83 | # Capture the configuration lockfiles, one per configuration 84 | run("conan lock create conanfile.py --name=libb --version=0.2 " 85 | "--user=user --channel=testing --lockfile=../locks/libb_base.lock --lockfile-out=../locks/libb_deps_debug.lock -s build_type=Debug") 86 | run("conan lock create conanfile.py --name=libb --version=0.2 " 87 | "--user=user --channel=testing --lockfile=../locks/libb_base.lock --lockfile-out=../locks/libb_deps_release.lock") 88 | # Now build libb 89 | run("conan create . libb/0.2@user/testing --lockfile=../locks/libb_deps_release.lock") 90 | run("conan create . libb/0.2@user/testing --lockfile=../locks/libb_deps_debug.lock") 91 | 92 | # Capture the app1 base lockfile 93 | run("conan lock create --reference=app1/0.1@user/testing --lockfile=locks/libb_base.lock " 94 | "--lockfile-out=locks/app1_base.lock --base") 95 | # And one lockfile per configuration 96 | run("conan lock create --reference=app1/0.1@user/testing --lockfile=locks/app1_base.lock " 97 | "--lockfile-out=locks/app1_release.lock") 98 | run("conan lock create --reference=app1/0.1@user/testing --lockfile=locks/app1_base.lock " 99 | "--lockfile-out=locks/app1_debug.lock -s build_type=Debug") 100 | 101 | run("conan lock build-order locks/app1_release.lock --json=bo_release.json") 102 | run("conan lock build-order locks/app1_debug.lock --json=bo_debug.json") 103 | build_order_release = json.loads(load("bo_release.json")) 104 | build_order_debug = json.loads(load("bo_debug.json")) 105 | 106 | for level in build_order_release: 107 | for item in level: 108 | ref, pid, context, id_ = item 109 | print(item) 110 | run("conan install %s --build=%s --lockfile=locks/app1_release.lock " 111 | "--lockfile-out=locks/app1_release_updated.lock" % (ref, ref)) 112 | run("conan lock update locks/app1_release.lock locks/app1_release_updated.lock") 113 | 114 | print(load("locks/app1_release.lock")) 115 | clean() 116 | 117 | if __name__ == '__main__': 118 | home = os.path.abspath(os.path.join(os.path.dirname(__file__), "tmp")) 119 | with setenv("CONAN_USER_HOME", home): 120 | ci_pipeline() 121 | -------------------------------------------------------------------------------- /features/lockfiles/ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | python build.py 6 | -------------------------------------------------------------------------------- /features/lockfiles/ci/liba/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, tools 2 | 3 | required_conan_version = ">=1.28.0" 4 | 5 | class PkgaConan(ConanFile): 6 | settings = "build_type" 7 | -------------------------------------------------------------------------------- /features/lockfiles/ci/libb/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile 2 | 3 | required_conan_version = ">=1.28" 4 | 5 | class LibBConan(ConanFile): 6 | settings = "build_type" 7 | requires = "liba/[>0.0 <1.0]@user/testing" 8 | -------------------------------------------------------------------------------- /features/lockfiles/ci/libc/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile 2 | 3 | required_conan_version = ">=1.28" 4 | 5 | class LibCConan(ConanFile): 6 | settings = "build_type" 7 | requires = "liba/[>0.0 <1.0]@user/testing" 8 | -------------------------------------------------------------------------------- /features/lockfiles/ci/libd/conanfile.py: -------------------------------------------------------------------------------- 1 | 2 | from conans import ConanFile 3 | 4 | required_conan_version = ">=1.28" 5 | 6 | class LibDConan(ConanFile): 7 | settings = "build_type" 8 | requires = "libb/[>0.0 <1.0]@user/testing", "libc/[>0.0 <1.0]@user/testing" 9 | -------------------------------------------------------------------------------- /features/lockfiles/intro/build.bat: -------------------------------------------------------------------------------- 1 | python build.py -------------------------------------------------------------------------------- /features/lockfiles/intro/build.py: -------------------------------------------------------------------------------- 1 | import os, json, shutil, sys 2 | import platform 3 | import subprocess 4 | from contextlib import contextmanager 5 | 6 | 7 | def run(cmd, assert_error=False): 8 | print("*********** Running: %s" % cmd) 9 | ret = os.system(cmd) 10 | if ret == 0 and assert_error: 11 | raise Exception("Command unexpectedly succedeed: %s" % cmd) 12 | if ret != 0 and not assert_error: 13 | raise Exception("Failed command: %s" % cmd) 14 | 15 | def load(filename): 16 | with open(filename, "r") as f: 17 | return f.read() 18 | 19 | def rm(path): 20 | if os.path.isfile(path): 21 | os.remove(path) 22 | elif os.path.isdir(path): 23 | shutil.rmtree(path) 24 | 25 | @contextmanager 26 | def chdir(path): 27 | current_path = os.getcwd() 28 | try: 29 | os.chdir(path) 30 | yield 31 | finally: 32 | os.chdir(current_path) 33 | 34 | @contextmanager 35 | def setenv(key, value): 36 | old_value = os.environ.get(key) 37 | os.environ[key] = value 38 | try: 39 | yield 40 | finally: 41 | if old_value is not None: 42 | os.environ[key] = old_value 43 | 44 | 45 | def clean(): 46 | rm("tmp") 47 | rm("pkgb/build") 48 | rm("pkgb/locks") 49 | rm("consume") 50 | run("conan remove '*' -f") 51 | 52 | def single_config(): 53 | clean() 54 | 55 | run("conan config set general.default_package_id_mode=full_version_mode") 56 | run("conan create pkga pkga/0.1@user/testing") 57 | 58 | with chdir("pkgb"): 59 | run("conan lock create conanfile.py --user=user --channel=testing --lockfile-out=locks/pkgb_deps.lock") 60 | print(load("locks/pkgb_deps.lock")) 61 | 62 | run("conan create pkga pkga/0.2@user/testing") 63 | 64 | os.makedirs("pkgb/build") 65 | with chdir("pkgb/build"): 66 | run("conan install ..") 67 | if platform.system() == "Windows": 68 | run('cmake ../src -G "{}"'.format(os.getenv("CMAKE_GENERATOR"))) 69 | else: 70 | run("cmake ../src -DCMAKE_BUILD_TYPE=Release") 71 | run("cmake --build . --config Release") 72 | run(os.sep.join(["bin", "greet"])) 73 | 74 | run("conan install .. --lockfile=../locks/pkgb_deps.lock") 75 | run("cmake --build . --config Release") 76 | run(os.sep.join(["bin", "greet"])) 77 | 78 | run("conan install .. --lockfile=../locks/pkgb_deps.lock --build=pkga", assert_error=True) 79 | 80 | with chdir("pkgb"): 81 | run("conan create . user/stable --lockfile=locks/pkgb_deps.lock", assert_error=True) 82 | run("conan create . user/testing --lockfile=locks/pkgb_deps.lock --lockfile-out=locks/pkgb.lock") 83 | print(load("locks/pkgb.lock")) 84 | run("conan create . user/testing --lockfile=locks/pkgb.lock", assert_error=True) 85 | run("conan create . user/testing --lockfile=locks/pkgb_deps.lock") 86 | 87 | os.makedirs("consume") 88 | with chdir("consume"): 89 | run("conan install pkgb/0.1@user/testing --lockfile=../pkgb/locks/pkgb.lock") 90 | run(os.sep.join(["bin", "greet"])) 91 | 92 | clean() 93 | 94 | def multi_config(): 95 | # Multi-configuration 96 | clean() 97 | 98 | run("conan create pkga pkga/0.1@user/testing") 99 | run("conan create pkga pkga/0.1@user/testing -s build_type=Debug") 100 | 101 | with chdir("pkgb"): 102 | run("conan lock create conanfile.py --user=user --channel=testing --lockfile-out=locks/pkgb_release.lock") 103 | run("conan lock create conanfile.py --user=user --channel=testing --lockfile-out=locks/pkgb_debug.lock -s build_type=Debug") 104 | rm("locks") 105 | run("conan lock create conanfile.py --user=user --channel=testing --lockfile-out=locks/pkgb_base.lock --base") 106 | run("conan lock create conanfile.py --user=user --channel=testing --lockfile=locks/pkgb_base.lock --lockfile-out=locks/pkgb_deps_debug.lock -s build_type=Debug") 107 | run("conan lock create conanfile.py --user=user --channel=testing --lockfile=locks/pkgb_base.lock --lockfile-out=locks/pkgb_deps_release.lock") 108 | print(load("locks/pkgb_base.lock")) 109 | print(load("locks/pkgb_deps_release.lock")) 110 | print(load("locks/pkgb_deps_debug.lock")) 111 | 112 | run("conan create pkga pkga/0.2@user/testing") 113 | run("conan create pkga pkga/0.2@user/testing -s build_type=Debug") 114 | 115 | os.makedirs("pkgb/build") 116 | with chdir("pkgb/build"): 117 | for config in ("Release", "Debug"): 118 | run("conan install .. --lockfile=../locks/pkgb_deps_%s.lock -s build_type=%s" % (config.lower(), config), assert_error=True) 119 | run("conan install .. --lockfile=../locks/pkgb_deps_%s.lock" % config.lower()) 120 | if platform.system() == "Windows": 121 | run('cmake ../src -G "{}"'.format(os.getenv("CMAKE_GENERATOR"))) 122 | else: 123 | run("cmake ../src -DCMAKE_BUILD_TYPE=%s" % config) 124 | run("cmake --build . --config %s" % config) 125 | run(os.sep.join(["bin", "greet"])) 126 | run("conan install .. -s build_type=%s" % config) 127 | run("cmake --build . --config %s" % config) 128 | run(os.sep.join(["bin", "greet"])) 129 | 130 | run("conan install .. --lockfile=../locks/pkgb_deps_%s.lock --build=pkga" % config.lower(), assert_error=True) 131 | 132 | 133 | with chdir("pkgb"): 134 | for config in ("Release", "Debug"): 135 | run("conan create . user/stable --lockfile=locks/pkgb_deps_%s.lock" % config.lower(), assert_error=True) 136 | run("conan create . user/testing --lockfile=locks/pkgb_deps_%s.lock --lockfile-out=locks/pkgb_%s.lock" % (config.lower(), config.lower())) 137 | print(load("locks/pkgb_%s.lock" % config.lower())) 138 | run("conan create . user/testing --lockfile=locks/pkgb_%s.lock" % config.lower(), assert_error=True) 139 | 140 | os.makedirs("consume") 141 | with chdir("consume"): 142 | for config in ("Release", "Debug"): 143 | run("conan install pkgb/0.1@user/testing --lockfile=../pkgb/locks/pkgb_%s.lock" % config.lower()) 144 | run(os.sep.join(["bin", "greet"])) 145 | 146 | clean() 147 | 148 | 149 | if __name__ == '__main__': 150 | home = os.path.abspath(os.path.join(os.path.dirname(__file__), "tmp")) 151 | with setenv("CONAN_USER_HOME", home): 152 | if platform.system() == "Windows": 153 | if not os.getenv("CMAKE_GENERATOR"): 154 | print("CMAKE_GENERATOR environment variable not defined. " 155 | "Please define the CMake generator in the CMAKE_GENERATOR environment variable.") 156 | sys.exit() 157 | single_config() 158 | multi_config() 159 | -------------------------------------------------------------------------------- /features/lockfiles/intro/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | python build.py -------------------------------------------------------------------------------- /features/lockfiles/intro/pkga/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, tools 2 | 3 | required_conan_version = ">=1.28" 4 | 5 | class PkgaConan(ConanFile): 6 | settings = "build_type" 7 | exports_sources = "src/*" 8 | 9 | def build(self): 10 | tools.replace_in_file("src/helloa.h", "%V%", self.version) 11 | tools.replace_in_file("src/helloa.h", "%BT%", str(self.settings.build_type)) 12 | 13 | def package(self): 14 | self.copy("*.h", dst="include", src="src") 15 | -------------------------------------------------------------------------------- /features/lockfiles/intro/pkga/src/helloa.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | inline void helloA(){ 5 | std::cout << "HelloA %V% %BT%\n"; 6 | } 7 | -------------------------------------------------------------------------------- /features/lockfiles/intro/pkgb/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake 2 | 3 | required_conan_version = ">=1.28" 4 | 5 | class PkgbConan(ConanFile): 6 | name = "pkgb" 7 | version = "0.1" 8 | settings = "os", "compiler", "build_type", "arch" 9 | options = {"shared": [True, False]} 10 | default_options = {"shared": False} 11 | generators = "cmake" 12 | exports_sources = "src/*" 13 | requires = "pkga/[>0.0]@user/testing" 14 | 15 | def build(self): 16 | cmake = CMake(self) 17 | cmake.configure(source_folder="src") 18 | cmake.build() 19 | 20 | def package(self): 21 | self.copy("*.h", dst="include", src="src") 22 | self.copy("*.lib", dst="lib", keep_path=False) 23 | self.copy("*.dll", dst="bin", keep_path=False) 24 | self.copy("*.dylib*", dst="lib", keep_path=False) 25 | self.copy("*.so", dst="lib", keep_path=False) 26 | self.copy("*.a", dst="lib", keep_path=False) 27 | self.copy("greet*", dst="bin", src="bin", keep_path=False) 28 | 29 | def deploy(self): 30 | self.copy("*", dst="bin", src="bin", keep_path=False) 31 | self.copy_deps("*", dst="bin", src="bin", keep_path=False) 32 | 33 | def package_info(self): 34 | self.cpp_info.libs = ["pkgb"] 35 | -------------------------------------------------------------------------------- /features/lockfiles/intro/pkgb/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(MyHello CXX) 3 | 4 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 5 | conan_basic_setup() 6 | 7 | add_library(pkgb hello.cpp) 8 | 9 | add_executable(greet greet.cpp) 10 | target_link_libraries(greet PRIVATE pkgb) 11 | -------------------------------------------------------------------------------- /features/lockfiles/intro/pkgb/src/greet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hellob.h" 3 | 4 | int main(){ 5 | helloB(); 6 | #ifdef NDEBUG 7 | std::cout << "Greetings Release!" < 2 | #include "hellob.h" 3 | #include "helloa.h" 4 | 5 | void helloB(){ 6 | helloA(); 7 | #ifdef NDEBUG 8 | std::cout << "HelloB Release!" < 2 | #include "hello.h" 3 | 4 | void hello(){ 5 | #ifdef NDEBUG 6 | std::cout << "Hello World Release!" < 2 | #include "hello.h" 3 | 4 | void hello(){ 5 | #if !defined NDEBUG 6 | std::cout << "Hello World Debug!" << std::endl; 7 | #else 8 | std::cout << "Hello World Release!" << std::endl; 9 | #endif 10 | } 11 | -------------------------------------------------------------------------------- /features/multi_config/hello.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef WIN32 4 | #define HELLO_EXPORT __declspec(dllexport) 5 | #else 6 | #define HELLO_EXPORT 7 | #endif 8 | 9 | HELLO_EXPORT void hello(); 10 | -------------------------------------------------------------------------------- /features/multi_config/test_package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(PackageTest CXX) 3 | 4 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 5 | conan_basic_setup() 6 | 7 | add_executable(example example.cpp) 8 | if (CONAN_SETTINGS_BUILD_TYPE STREQUAL "Debug") 9 | message("CONAN_LIBS_DEBUG: ${CONAN_LIBS_DEBUG}") 10 | target_link_libraries(example ${CONAN_LIBS_DEBUG}) 11 | else() 12 | message("CONAN_LIBS_RELEASE: ${CONAN_LIBS_RELEASE}") 13 | target_link_libraries(example ${CONAN_LIBS_RELEASE}) 14 | endif() 15 | -------------------------------------------------------------------------------- /features/multi_config/test_package/conanfile.py: -------------------------------------------------------------------------------- 1 | import os 2 | from six import StringIO 3 | from conans import ConanFile, CMake 4 | 5 | 6 | class HelloTestConan(ConanFile): 7 | settings = "os", "compiler", "build_type", "arch" 8 | generators = "cmake" 9 | 10 | def build(self): 11 | cmake = CMake(self) 12 | cmake.configure() 13 | cmake.build() 14 | 15 | def test(self): 16 | os.chdir("bin") 17 | output = StringIO() 18 | self.run(".%sexample" % os.sep, run_environment=True, output=output) 19 | assert ("Hello World {}!".format(str(self.settings.build_type)) in output.getvalue()), output.getvalue() 20 | -------------------------------------------------------------------------------- /features/multi_config/test_package/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hello.h" 3 | 4 | int main() { 5 | hello(); 6 | } 7 | -------------------------------------------------------------------------------- /features/package_development_flow/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO ON 2 | 3 | RMDIR /Q /S tmp 4 | 5 | conan source . --source-folder=tmp/source 6 | conan install . --install-folder=tmp/build 7 | conan build . --source-folder=tmp/source --build-folder=tmp/build 8 | conan package . --source-folder=tmp/source --build-folder=tmp/build --package-folder=tmp/package 9 | 10 | REM NOTE: Use --force to prevent ERROR: Package already exists 11 | conan export-pkg . user/testing --source-folder=tmp/source --build-folder=tmp/build --force 12 | 13 | REM You can also test the package that was just exported 14 | conan test test_package Hello/1.0@user/testing 15 | 16 | REM Finally, run a full create, does all of the above + test_package 17 | conan create . user/testing 18 | -------------------------------------------------------------------------------- /features/package_development_flow/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | rm -rf tmp 7 | 8 | conan source . --source-folder=tmp/source 9 | conan install . --install-folder=tmp/build 10 | conan build . --source-folder=tmp/source --build-folder=tmp/build 11 | conan package . --source-folder=tmp/source --build-folder=tmp/build --package-folder=tmp/package 12 | 13 | # NOTE: Use --force to prevent ERROR: Package already exists 14 | conan export-pkg . user/testing --source-folder=tmp/source --build-folder=tmp/build --force 15 | 16 | # You can also test the package that was just exported 17 | conan test test_package Hello/1.0@user/testing 18 | 19 | # Finally, run a full create, does all of the above + test_package 20 | conan create . user/testing 21 | -------------------------------------------------------------------------------- /features/package_development_flow/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake, tools 2 | 3 | 4 | class HelloConan(ConanFile): 5 | name = "Hello" 6 | version = "1.0" 7 | license = "" 8 | author = " " 9 | url = "" 10 | description = "" 11 | topics = ("", "", "") 12 | settings = "os", "compiler", "build_type", "arch" 13 | options = {"shared": [True, False]} 14 | default_options = "shared=False" 15 | generators = "cmake" 16 | 17 | def source(self): 18 | self.run("git clone https://github.com/conan-io/hello.git") 19 | self.run("cd hello") 20 | # This small hack might be useful to guarantee proper /MT /MD linkage 21 | # in MSVC if the packaged project doesn't have variables to set it 22 | # properly 23 | tools.replace_in_file("hello/CMakeLists.txt", "PROJECT(HelloWorld)", 24 | '''PROJECT(HelloWorld) 25 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 26 | conan_basic_setup()''') 27 | 28 | def build(self): 29 | cmake = CMake(self) 30 | cmake.configure(source_folder="hello") 31 | cmake.build() 32 | 33 | # Explicit way: 34 | # self.run('cmake %s/hello %s' 35 | # % (self.source_folder, cmake.command_line)) 36 | # self.run("cmake --build . %s" % cmake.build_config) 37 | 38 | def package(self): 39 | self.copy("*.h", dst="include", src="hello") 40 | self.copy("*hello.lib", dst="lib", keep_path=False) 41 | self.copy("*.dll", dst="bin", keep_path=False) 42 | self.copy("*.so", dst="lib", keep_path=False) 43 | self.copy("*.dylib", dst="lib", keep_path=False) 44 | self.copy("*.a", dst="lib", keep_path=False) 45 | 46 | def package_info(self): 47 | self.cpp_info.libs = ["hello"] 48 | 49 | -------------------------------------------------------------------------------- /features/package_development_flow/test_package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(PackageTest CXX) 3 | 4 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 5 | conan_basic_setup() 6 | 7 | add_executable(example example.cpp) 8 | target_link_libraries(example ${CONAN_LIBS}) 9 | 10 | # CTest is a testing tool that can be used to test your project. 11 | # enable_testing() 12 | # add_test(NAME example 13 | # WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin 14 | # COMMAND example) 15 | -------------------------------------------------------------------------------- /features/package_development_flow/test_package/conanfile.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from conans import ConanFile, CMake, tools 4 | 5 | 6 | class HelloTestConan(ConanFile): 7 | settings = "os", "compiler", "build_type", "arch" 8 | generators = "cmake" 9 | 10 | def build(self): 11 | cmake = CMake(self) 12 | # Current dir is "test_package/build/" and CMakeLists.txt is 13 | # in "test_package" 14 | cmake.configure() 15 | cmake.build() 16 | 17 | def imports(self): 18 | self.copy("*.dll", dst="bin", src="bin") 19 | self.copy("*.dylib*", dst="bin", src="lib") 20 | self.copy('*.so*', dst='bin', src='lib') 21 | 22 | def test(self): 23 | if not tools.cross_building(self.settings): 24 | os.chdir("bin") 25 | self.run(".%sexample" % os.sep) 26 | -------------------------------------------------------------------------------- /features/package_development_flow/test_package/example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hello.h" 3 | 4 | int main() { 5 | hello(); 6 | } 7 | -------------------------------------------------------------------------------- /features/python_requires/reuse_conanfile/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO ON 2 | 3 | conan create pyreq user/channel 4 | conan create consumer user/channel 5 | -------------------------------------------------------------------------------- /features/python_requires/reuse_conanfile/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | conan create pyreq user/channel 4 | conan create consumer user/channel 5 | -------------------------------------------------------------------------------- /features/python_requires/reuse_conanfile/consumer/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake, python_requires 2 | 3 | 4 | base = python_requires("pyreq/version@user/channel") 5 | 6 | class ConsumerConan(base.get_conanfile()): 7 | name = "consumer" 8 | version = base.get_version() 9 | 10 | # All the recipe attributes and methods are defined in 11 | # the python_requires imported source, it is a very 12 | # easy way to share all the business logic across 13 | # all the recipes in the same company 14 | -------------------------------------------------------------------------------- /features/python_requires/reuse_conanfile/consumer/src/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hello.h" 3 | 4 | void hello(){ 5 | #ifdef NDEBUG 6 | std::cout << "Hello World Release!" < 2 | #include 3 | #include "say.h" 4 | 5 | void say(std::string msg){ 6 | #ifdef NDEBUG 7 | std::cout << "Release: " << msg < 3 | 4 | void say(std::string msg); -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/.gitignore: -------------------------------------------------------------------------------- 1 | bindings/ 2 | build/ -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(dear-imgui-conan CXX) 3 | 4 | set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}) 5 | set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) 6 | 7 | # CONFIG option is important so that CMake doesnt search for modules into the default modules directory 8 | find_package(imgui CONFIG) 9 | find_package(glfw3 CONFIG) 10 | find_package(glew CONFIG) 11 | 12 | add_executable( dear-imgui-conan 13 | main.cpp 14 | opengl_shader.cpp 15 | file_manager.cpp 16 | opengl_shader.h 17 | file_manager.h 18 | bindings/imgui_impl_glfw.cpp 19 | bindings/imgui_impl_opengl3.cpp 20 | bindings/imgui_impl_glfw.h 21 | bindings/imgui_impl_opengl3.h 22 | assets/simple-shader.vs 23 | assets/simple-shader.fs ) 24 | 25 | add_custom_command(TARGET dear-imgui-conan 26 | POST_BUILD 27 | COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/assets/simple-shader.vs ${PROJECT_BINARY_DIR} 28 | COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/assets/simple-shader.fs ${PROJECT_BINARY_DIR} 29 | ) 30 | 31 | target_compile_definitions(dear-imgui-conan PUBLIC IMGUI_IMPL_OPENGL_LOADER_GLEW) 32 | target_link_libraries(dear-imgui-conan imgui::imgui GLEW::glew_s glfw::glfw) 33 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/README.md: -------------------------------------------------------------------------------- 1 | ## Conan Dear ImGui example 2 | 3 | 1. Install conan: https://docs.conan.io/en/latest/installation.html 4 | 2. Clone this repo: `git clone https://github.com/conan-io/examples.git` 5 | 3. Install dependencies, compile and run 6 | 7 | ## Windows with Visual Studio: 8 | 9 | ```bash 10 | cd examples/libraries/dear-imgui/basic 11 | mkdir build 12 | cd build 13 | conan install .. -s build_type=Release 14 | conan install .. -s build_type=Debug 15 | cmake .. -G "Visual Studio 16 2019" -A "x64" 16 | cmake --build . --config Release 17 | cd Release 18 | dear-imgui-conan 19 | ``` 20 | 21 | ## Linux: 22 | 23 | ```bash 24 | cd examples/libraries/dear-imgui/basic 25 | mkdir build 26 | cd build 27 | conan install .. -s build_type=Release 28 | cmake .. -DCMAKE_BUILD_TYPE=Release 29 | cmake --build . 30 | ./dear-imgui-conan 31 | ``` 32 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/assets/simple-shader.fs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | out vec4 FragColor; 4 | 5 | in vec3 vertexColor; 6 | uniform vec3 color; 7 | 8 | void main() 9 | { 10 | FragColor = vec4(color*vertexColor,1.0); 11 | } 12 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/assets/simple-shader.vs: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec3 position; 4 | layout (location = 1) in vec3 color; 5 | 6 | out vec3 vertexColor; 7 | 8 | uniform float rotation; 9 | uniform vec2 translation; 10 | 11 | void main() 12 | { 13 | vec2 rotated_pos; 14 | rotated_pos.x = translation.x + position.x*cos(rotation) - position.y*sin(rotation); 15 | rotated_pos.y = translation.y + position.x*sin(rotation) + position.y*cos(rotation); 16 | gl_Position = vec4(rotated_pos.x, rotated_pos.y, position.z, 1.0); 17 | vertexColor = color; 18 | } 19 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/build.bat: -------------------------------------------------------------------------------- 1 | if "%CMAKE_GENERATOR%"=="" ( 2 | ECHO CMAKE_GENERATOR environment variable not defined. Please define the CMake generator in the CMAKE_GENERATOR environment variable. 3 | ) else ( 4 | @ECHO ON 5 | 6 | RMDIR /Q /S build 7 | MKDIR build 8 | PUSHD build 9 | 10 | conan install .. 11 | cmake .. -G "%CMAKE_GENERATOR%" -A "%CMAKE_GENERATOR_PLATFORM%" 12 | cmake --build . --config Release 13 | ) 14 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | rm -rf build 7 | mkdir build 8 | pushd build 9 | 10 | export CONAN_SYSREQUIRES_MODE=enabled 11 | conan install .. --build=missing -c tools.system.package_manager:mode=install -c tools.system.package_manager:sudo=True 12 | cmake .. -DCMAKE_BUILD_TYPE=Release 13 | cmake --build . 14 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/conanfile.txt: -------------------------------------------------------------------------------- 1 | [requires] 2 | imgui/1.74 3 | glfw/3.3.6 4 | glew/2.2.0 5 | 6 | [generators] 7 | cmake_find_package_multi 8 | 9 | [options] 10 | glew:shared=False 11 | 12 | [imports] 13 | ./res/bindings, imgui_impl_glfw.cpp -> ../bindings 14 | ./res/bindings, imgui_impl_opengl3.cpp -> ../bindings 15 | ./res/bindings, imgui_impl_glfw.h -> ../bindings 16 | ./res/bindings, imgui_impl_opengl3.h -> ../bindings -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/file_manager.cpp: -------------------------------------------------------------------------------- 1 | #include "file_manager.h" 2 | 3 | FileManager::FileManager() 4 | { 5 | } 6 | 7 | FileManager::~FileManager() 8 | { 9 | } 10 | 11 | std::string FileManager::read(const std::string& filename) { 12 | std::ifstream file; 13 | file.exceptions (std::ifstream::failbit | std::ifstream::badbit); 14 | std::stringstream file_stream; 15 | try { 16 | file.open(filename.c_str()); 17 | file_stream << file.rdbuf(); 18 | file.close(); 19 | } 20 | catch (std::ifstream::failure e) { 21 | std::cout << "Error reading Shader File!" << std::endl; 22 | } 23 | return file_stream.str(); 24 | } 25 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/file_manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class FileManager 9 | { 10 | public: 11 | FileManager(); 12 | ~FileManager(); 13 | static std::string read(const std::string& filename); 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/main.cpp: -------------------------------------------------------------------------------- 1 | #include "imgui.h" 2 | #include "bindings/imgui_impl_glfw.h" 3 | #include "bindings/imgui_impl_opengl3.h" 4 | #include "opengl_shader.h" 5 | #include "file_manager.h" 6 | #include 7 | #include 8 | #include 9 | 10 | #include // Initialize with glewInit() 11 | 12 | // Include glfw3.h after our OpenGL definitions 13 | #include 14 | 15 | #define PI 3.14159265358979323846 16 | 17 | static void glfw_error_callback(int error, const char *description) 18 | { 19 | fprintf(stderr, "Glfw Error %d: %s\n", error, description); 20 | } 21 | 22 | void render_conan_logo() 23 | { 24 | ImDrawList *draw_list = ImGui::GetWindowDrawList(); 25 | float sz = 300.0f; 26 | static ImVec4 col1 = ImVec4(68.0 / 255.0, 83.0 / 255.0, 89.0 / 255.0, 1.0f); 27 | static ImVec4 col2 = ImVec4(40.0 / 255.0, 60.0 / 255.0, 80.0 / 255.0, 1.0f); 28 | static ImVec4 col3 = ImVec4(50.0 / 255.0, 65.0 / 255.0, 82.0 / 255.0, 1.0f); 29 | static ImVec4 col4 = ImVec4(20.0 / 255.0, 40.0 / 255.0, 60.0 / 255.0, 1.0f); 30 | const ImVec2 p = ImGui::GetCursorScreenPos(); 31 | float x = p.x + 4.0f, y = p.y + 4.0f; 32 | draw_list->AddQuadFilled(ImVec2(x, y + 0.25 * sz), ImVec2(x + 0.5 * sz, y + 0.5 * sz), ImVec2(x + sz, y + 0.25 * sz), ImVec2(x + 0.5 * sz, y), ImColor(col1)); 33 | draw_list->AddQuadFilled(ImVec2(x, y + 0.25 * sz), ImVec2(x + 0.5 * sz, y + 0.5 * sz), ImVec2(x + 0.5 * sz, y + 1.0 * sz), ImVec2(x, y + 0.75 * sz), ImColor(col2)); 34 | draw_list->AddQuadFilled(ImVec2(x + 0.5 * sz, y + 0.5 * sz), ImVec2(x + sz, y + 0.25 * sz), ImVec2(x + sz, y + 0.75 * sz), ImVec2(x + 0.5 * sz, y + 1.0 * sz), ImColor(col3)); 35 | draw_list->AddLine(ImVec2(x + 0.75 * sz, y + 0.375 * sz), ImVec2(x + 0.75 * sz, y + 0.875 * sz), ImColor(col4)); 36 | draw_list->AddBezierCurve(ImVec2(x + 0.72 * sz, y + 0.24 * sz), ImVec2(x + 0.68 * sz, y + 0.15 * sz), ImVec2(x + 0.48 * sz, y + 0.13 * sz), ImVec2(x + 0.39 * sz, y + 0.17 * sz), ImColor(col4), 10, 18); 37 | draw_list->AddBezierCurve(ImVec2(x + 0.39 * sz, y + 0.17 * sz), ImVec2(x + 0.2 * sz, y + 0.25 * sz), ImVec2(x + 0.3 * sz, y + 0.35 * sz), ImVec2(x + 0.49 * sz, y + 0.38 * sz), ImColor(col4), 10, 18); 38 | } 39 | 40 | void create_triangle(unsigned int &vbo, unsigned int &vao, unsigned int &ebo) 41 | { 42 | 43 | // create the triangle 44 | float triangle_vertices[] = { 45 | 0.0f, 0.25f, 0.0f, // position vertex 1 46 | 1.0f, 0.0f, 0.0f, // color vertex 1 47 | 0.25f, -0.25f, 0.0f, // position vertex 1 48 | 0.0f, 1.0f, 0.0f, // color vertex 1 49 | -0.25f, -0.25f, 0.0f, // position vertex 1 50 | 0.0f, 0.0f, 1.0f, // color vertex 1 51 | }; 52 | unsigned int triangle_indices[] = { 53 | 0, 1, 2}; 54 | glGenVertexArrays(1, &vao); 55 | glGenBuffers(1, &vbo); 56 | glGenBuffers(1, &ebo); 57 | glBindVertexArray(vao); 58 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 59 | glBufferData(GL_ARRAY_BUFFER, sizeof(triangle_vertices), triangle_vertices, GL_STATIC_DRAW); 60 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); 61 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(triangle_indices), triangle_indices, GL_STATIC_DRAW); 62 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *)0); 63 | glEnableVertexAttribArray(0); 64 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *)(3 * sizeof(float))); 65 | glEnableVertexAttribArray(1); 66 | glBindBuffer(GL_ARRAY_BUFFER, 0); 67 | glBindVertexArray(0); 68 | } 69 | 70 | int main(int, char **) 71 | { 72 | // Setup window 73 | glfwSetErrorCallback(glfw_error_callback); 74 | if (!glfwInit()) 75 | return 1; 76 | 77 | // Decide GL+GLSL versions 78 | #if __APPLE__ 79 | // GL 3.2 + GLSL 150 80 | const char *glsl_version = "#version 150"; 81 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 82 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 83 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 84 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac 85 | #else 86 | // GL 3.0 + GLSL 130 87 | const char *glsl_version = "#version 130"; 88 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 89 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 90 | //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 91 | //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only 92 | #endif 93 | 94 | // Create window with graphics context 95 | GLFWwindow *window = glfwCreateWindow(1280, 720, "Dear ImGui - Conan", NULL, NULL); 96 | if (window == NULL) 97 | return 1; 98 | glfwMakeContextCurrent(window); 99 | glfwSwapInterval(1); // Enable vsync 100 | 101 | bool err = glewInit() != GLEW_OK; 102 | 103 | if (err) 104 | { 105 | fprintf(stderr, "Failed to initialize OpenGL loader!\n"); 106 | return 1; 107 | } 108 | 109 | int screen_width, screen_height; 110 | glfwGetFramebufferSize(window, &screen_width, &screen_height); 111 | glViewport(0, 0, screen_width, screen_height); 112 | 113 | // create our geometries 114 | unsigned int vbo, vao, ebo; 115 | create_triangle(vbo, vao, ebo); 116 | 117 | // init shader 118 | Shader triangle_shader; 119 | triangle_shader.init(FileManager::read("simple-shader.vs"), FileManager::read("simple-shader.fs")); 120 | 121 | // Setup Dear ImGui context 122 | IMGUI_CHECKVERSION(); 123 | ImGui::CreateContext(); 124 | ImGuiIO &io = ImGui::GetIO(); 125 | // Setup Platform/Renderer bindings 126 | ImGui_ImplGlfw_InitForOpenGL(window, true); 127 | ImGui_ImplOpenGL3_Init(glsl_version); 128 | // Setup Dear ImGui style 129 | ImGui::StyleColorsDark(); 130 | 131 | while (!glfwWindowShouldClose(window)) 132 | { 133 | glfwPollEvents(); 134 | glClearColor(0.45f, 0.55f, 0.60f, 1.00f); 135 | glClear(GL_COLOR_BUFFER_BIT); 136 | 137 | // feed inputs to dear imgui, start new frame 138 | ImGui_ImplOpenGL3_NewFrame(); 139 | ImGui_ImplGlfw_NewFrame(); 140 | ImGui::NewFrame(); 141 | 142 | // rendering our geometries 143 | triangle_shader.use(); 144 | glBindVertexArray(vao); 145 | glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0); 146 | glBindVertexArray(0); 147 | 148 | // render your GUI 149 | ImGui::Begin("Triangle Position/Color"); 150 | static float rotation = 0.0; 151 | ImGui::SliderFloat("rotation", &rotation, 0, 2 * PI); 152 | static float translation[] = {0.0, 0.0}; 153 | ImGui::SliderFloat2("position", translation, -1.0, 1.0); 154 | static float color[4] = { 1.0f,1.0f,1.0f,1.0f }; 155 | // pass the parameters to the shader 156 | triangle_shader.setUniform("rotation", rotation); 157 | triangle_shader.setUniform("translation", translation[0], translation[1]); 158 | // color picker 159 | ImGui::ColorEdit3("color", color); 160 | // multiply triangle's color with this color 161 | triangle_shader.setUniform("color", color[0], color[1], color[2]); 162 | ImGui::End(); 163 | 164 | ImGui::Begin("Conan logo"); 165 | render_conan_logo(); 166 | ImGui::End(); 167 | // Render dear imgui into screen 168 | ImGui::Render(); 169 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 170 | 171 | int display_w, display_h; 172 | glfwGetFramebufferSize(window, &display_w, &display_h); 173 | glViewport(0, 0, display_w, display_h); 174 | glfwSwapBuffers(window); 175 | } 176 | 177 | // Cleanup 178 | ImGui_ImplOpenGL3_Shutdown(); 179 | ImGui_ImplGlfw_Shutdown(); 180 | ImGui::DestroyContext(); 181 | 182 | glfwDestroyWindow(window); 183 | glfwTerminate(); 184 | 185 | return 0; 186 | } 187 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/opengl_shader.cpp: -------------------------------------------------------------------------------- 1 | #include "opengl_shader.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | Shader::Shader() { 10 | } 11 | 12 | void Shader::init(const std::string& vertex_code, const std::string& fragment_code) { 13 | vertex_code_ = vertex_code; 14 | fragment_code_ = fragment_code; 15 | compile(); 16 | link(); 17 | } 18 | 19 | void Shader::compile() { 20 | const char* vcode = vertex_code_.c_str(); 21 | vertex_id_ = glCreateShader(GL_VERTEX_SHADER); 22 | glShaderSource(vertex_id_, 1, &vcode, NULL); 23 | glCompileShader(vertex_id_); 24 | 25 | const char* fcode = fragment_code_.c_str(); 26 | fragment_id_ = glCreateShader(GL_FRAGMENT_SHADER); 27 | glShaderSource(fragment_id_, 1, &fcode, NULL); 28 | glCompileShader(fragment_id_); 29 | checkCompileErr(); 30 | } 31 | 32 | void Shader::link() { 33 | id_ = glCreateProgram(); 34 | glAttachShader(id_, vertex_id_); 35 | glAttachShader(id_, fragment_id_); 36 | glLinkProgram(id_); 37 | checkLinkingErr(); 38 | glDeleteShader(vertex_id_); 39 | glDeleteShader(fragment_id_); 40 | } 41 | 42 | void Shader::use() { 43 | glUseProgram(id_); 44 | } 45 | 46 | template<> 47 | void Shader::setUniform(const std::string& name, int val) { 48 | glUniform1i(glGetUniformLocation(id_, name.c_str()), val); 49 | } 50 | 51 | template<> 52 | void Shader::setUniform(const std::string& name, bool val) { 53 | glUniform1i(glGetUniformLocation(id_, name.c_str()), val); 54 | } 55 | 56 | template<> 57 | void Shader::setUniform(const std::string& name, float val) { 58 | glUniform1f(glGetUniformLocation(id_, name.c_str()), val); 59 | } 60 | 61 | template<> 62 | void Shader::setUniform(const std::string& name, float val1, float val2) { 63 | glUniform2f(glGetUniformLocation(id_, name.c_str()), val1, val2); 64 | } 65 | 66 | template<> 67 | void Shader::setUniform(const std::string& name, float val1, float val2, float val3) { 68 | glUniform3f(glGetUniformLocation(id_, name.c_str()), val1, val2, val3); 69 | } 70 | 71 | template<> 72 | void Shader::setUniform(const std::string& name, float* val) { 73 | glUniformMatrix4fv(glGetUniformLocation(id_, name.c_str()), 1, GL_FALSE, val); 74 | } 75 | 76 | void Shader::checkCompileErr() { 77 | int success; 78 | char infoLog[1024]; 79 | glGetShaderiv(vertex_id_, GL_COMPILE_STATUS, &success); 80 | if (!success) { 81 | glGetShaderInfoLog(vertex_id_, 1024, NULL, infoLog); 82 | std::cout << "Error compiling Vertex Shader:\n" << infoLog << std::endl; 83 | } 84 | glGetShaderiv(fragment_id_, GL_COMPILE_STATUS, &success); 85 | if (!success) { 86 | glGetShaderInfoLog(fragment_id_, 1024, NULL, infoLog); 87 | std::cout << "Error compiling Fragment Shader:\n" << infoLog << std::endl; 88 | } 89 | } 90 | 91 | void Shader::checkLinkingErr() { 92 | int success; 93 | char infoLog[1024]; 94 | glGetProgramiv(id_, GL_LINK_STATUS, &success); 95 | if (!success) { 96 | glGetProgramInfoLog(id_, 1024, NULL, infoLog); 97 | std::cout << "Error Linking Shader Program:\n" << infoLog << std::endl; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /libraries/dear-imgui/basic/opengl_shader.h: -------------------------------------------------------------------------------- 1 | #ifndef opengl_shader_hpp 2 | #define opengl_shader_hpp 3 | 4 | #include 5 | #include 6 | 7 | class Shader 8 | { 9 | public: 10 | Shader(); 11 | void init(const std::string& vertex_code, const std::string& fragment_code); 12 | void use(); 13 | template void setUniform(const std::string& name, T val); 14 | template void setUniform(const std::string& name, T val1, T val2); 15 | template void setUniform(const std::string& name, T val1, T val2, T val3); 16 | 17 | private: 18 | void checkCompileErr(); 19 | void checkLinkingErr(); 20 | void compile(); 21 | void link(); 22 | unsigned int vertex_id_, fragment_id_, id_; 23 | std::string vertex_code_; 24 | std::string fragment_code_; 25 | }; 26 | 27 | #endif /* opengl_shader_hpp */ 28 | -------------------------------------------------------------------------------- /libraries/folly/basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1.3) 2 | project(folly_example CXX) 3 | 4 | set(CMAKE_VERBOSE_MAKEFILE ON) 5 | 6 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 7 | conan_basic_setup(TARGETS) 8 | 9 | add_executable(${PROJECT_NAME} main.cpp) 10 | target_link_libraries(${PROJECT_NAME} CONAN_PKG::folly) 11 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14) -------------------------------------------------------------------------------- /libraries/folly/basic/README.md: -------------------------------------------------------------------------------- 1 | # Conan Folly Example 2 | 3 | ## Folly example using Conan for blog post 4 | 5 | - Conan.io blog: https://blog.conan.io 6 | - Blog post about Folly: https://blog.conan.io/2018/11/19/Using-Facebook-Folly-with-Conan.html 7 | 8 | #### How to build 9 | To build this project using cmake: 10 | 11 | git clone https://github.com/conan-io/examples.git conan-examples 12 | cd conan-examples/libraries/folly/basic 13 | mkdir build && cd build 14 | conan install .. 15 | cmake .. 16 | cmake --build . 17 | bin/folly_example 18 | 19 | #### Requirements 20 | - CMake >=3.1.3 21 | - C++ compiler with C++14 support (Folly requirement) 22 | - Conan >=1.9.1 23 | -------------------------------------------------------------------------------- /libraries/folly/basic/build.bat: -------------------------------------------------------------------------------- 1 | if "%CMAKE_GENERATOR%"=="" ( 2 | ECHO CMAKE_GENERATOR environment variable not defined. Please define the CMake generator in the CMAKE_GENERATOR environment variable. 3 | ) else ( 4 | @ECHO ON 5 | 6 | RMDIR /Q /S build 7 | MKDIR build 8 | PUSHD build 9 | 10 | conan install .. 11 | cmake .. -G "%CMAKE_GENERATOR%" -A "%CMAKE_GENERATOR_PLATFORM%" 12 | cmake --build . --config Release 13 | 14 | bin\folly_example.exe 15 | ) 16 | -------------------------------------------------------------------------------- /libraries/folly/basic/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | rm -rf build 7 | mkdir build 8 | pushd build 9 | 10 | conan install .. --build=missing 11 | cmake .. -DCMAKE_BUILD_TYPE=Release 12 | cmake --build . 13 | 14 | bin/folly_example 15 | -------------------------------------------------------------------------------- /libraries/folly/basic/conanfile.txt: -------------------------------------------------------------------------------- 1 | [requires] 2 | folly/2020.08.10.00 3 | openssl/1.1.1k 4 | 5 | [generators] 6 | cmake -------------------------------------------------------------------------------- /libraries/folly/basic/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static void print_uri(const folly::fbstring& value) { 11 | const folly::Uri uri(value); 12 | const auto authority = folly::format("The authority from {} is {}", uri.fbstr(), uri.authority()); 13 | std::cout << authority << std::endl; 14 | } 15 | 16 | int main() { 17 | folly::ThreadedExecutor executor; 18 | folly::Promise promise; 19 | folly::Future future = promise.getSemiFuture().via(&executor); 20 | folly::Future unit = std::move(future).thenValue(print_uri); 21 | promise.setValue("https://conan.io/"); 22 | std::move(unit).get(); 23 | return EXIT_SUCCESS; 24 | } 25 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | .vscode/ 7 | build/ 8 | CMakeLists.txt.user 9 | CMakeCache.txt 10 | CMakeFiles 11 | CMakeScripts 12 | Testing 13 | Makefile 14 | cmake_install.cmake 15 | install_manifest.txt 16 | compile_commands.json 17 | CTestTestfile.cmake 18 | _deps 19 | 20 | # User-specific files 21 | *.rsuser 22 | *.suo 23 | *.user 24 | *.userosscache 25 | *.sln.docstates 26 | 27 | # User-specific files (MonoDevelop/Xamarin Studio) 28 | *.userprefs 29 | 30 | # Mono auto generated files 31 | mono_crash.* 32 | 33 | # Build results 34 | [Dd]ebug/ 35 | [Dd]ebugPublic/ 36 | [Rr]elease/ 37 | [Rr]eleases/ 38 | x64/ 39 | x86/ 40 | [Aa][Rr][Mm]/ 41 | [Aa][Rr][Mm]64/ 42 | bld/ 43 | [Bb]in/ 44 | [Oo]bj/ 45 | [Ll]og/ 46 | 47 | # Visual Studio 2015/2017 cache/options directory 48 | .vs/ 49 | # Uncomment if you have tasks that create the project's static files in wwwroot 50 | #wwwroot/ 51 | 52 | # Visual Studio 2017 auto generated files 53 | Generated\ Files/ 54 | 55 | # MSTest test Results 56 | [Tt]est[Rr]esult*/ 57 | [Bb]uild[Ll]og.* 58 | 59 | # NUnit 60 | *.VisualState.xml 61 | TestResult.xml 62 | nunit-*.xml 63 | 64 | # Build Results of an ATL Project 65 | [Dd]ebugPS/ 66 | [Rr]eleasePS/ 67 | dlldata.c 68 | 69 | # Benchmark Results 70 | BenchmarkDotNet.Artifacts/ 71 | 72 | # .NET Core 73 | project.lock.json 74 | project.fragment.lock.json 75 | artifacts/ 76 | 77 | # StyleCop 78 | StyleCopReport.xml 79 | 80 | # Files built by Visual Studio 81 | *_i.c 82 | *_p.c 83 | *_h.h 84 | *.ilk 85 | *.meta 86 | *.obj 87 | *.iobj 88 | *.pch 89 | *.pdb 90 | *.ipdb 91 | *.pgc 92 | *.pgd 93 | *.rsp 94 | *.sbr 95 | *.tlb 96 | *.tli 97 | *.tlh 98 | *.tmp 99 | *.tmp_proj 100 | *_wpftmp.csproj 101 | *.log 102 | *.vspscc 103 | *.vssscc 104 | .builds 105 | *.pidb 106 | *.svclog 107 | *.scc 108 | 109 | # Chutzpah Test files 110 | _Chutzpah* 111 | 112 | # Visual C++ cache files 113 | ipch/ 114 | *.aps 115 | *.ncb 116 | *.opendb 117 | *.opensdf 118 | *.sdf 119 | *.cachefile 120 | *.VC.db 121 | *.VC.VC.opendb 122 | 123 | # Visual Studio profiler 124 | *.psess 125 | *.vsp 126 | *.vspx 127 | *.sap 128 | 129 | # Visual Studio Trace Files 130 | *.e2e 131 | 132 | # TFS 2012 Local Workspace 133 | $tf/ 134 | 135 | # Guidance Automation Toolkit 136 | *.gpState 137 | 138 | # ReSharper is a .NET coding add-in 139 | _ReSharper*/ 140 | *.[Rr]e[Ss]harper 141 | *.DotSettings.user 142 | 143 | # JustCode is a .NET coding add-in 144 | .JustCode 145 | 146 | # TeamCity is a build add-in 147 | _TeamCity* 148 | 149 | # DotCover is a Code Coverage Tool 150 | *.dotCover 151 | 152 | # AxoCover is a Code Coverage Tool 153 | .axoCover/* 154 | !.axoCover/settings.json 155 | 156 | # Visual Studio code coverage results 157 | *.coverage 158 | *.coveragexml 159 | 160 | # NCrunch 161 | _NCrunch_* 162 | .*crunch*.local.xml 163 | nCrunchTemp_* 164 | 165 | # MightyMoose 166 | *.mm.* 167 | AutoTest.Net/ 168 | 169 | # Web workbench (sass) 170 | .sass-cache/ 171 | 172 | # Installshield output folder 173 | [Ee]xpress/ 174 | 175 | # DocProject is a documentation generator add-in 176 | DocProject/buildhelp/ 177 | DocProject/Help/*.HxT 178 | DocProject/Help/*.HxC 179 | DocProject/Help/*.hhc 180 | DocProject/Help/*.hhk 181 | DocProject/Help/*.hhp 182 | DocProject/Help/Html2 183 | DocProject/Help/html 184 | 185 | # Click-Once directory 186 | publish/ 187 | 188 | # Publish Web Output 189 | *.[Pp]ublish.xml 190 | *.azurePubxml 191 | # Note: Comment the next line if you want to checkin your web deploy settings, 192 | # but database connection strings (with potential passwords) will be unencrypted 193 | *.pubxml 194 | *.publishproj 195 | 196 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 197 | # checkin your Azure Web App publish settings, but sensitive information contained 198 | # in these scripts will be unencrypted 199 | PublishScripts/ 200 | 201 | # NuGet Packages 202 | *.nupkg 203 | # NuGet Symbol Packages 204 | *.snupkg 205 | # The packages folder can be ignored because of Package Restore 206 | **/[Pp]ackages/* 207 | # except build/, which is used as an MSBuild target. 208 | !**/[Pp]ackages/build/ 209 | # Uncomment if necessary however generally it will be regenerated when needed 210 | #!**/[Pp]ackages/repositories.config 211 | # NuGet v3's project.json files produces more ignorable files 212 | *.nuget.props 213 | *.nuget.targets 214 | 215 | # Microsoft Azure Build Output 216 | csx/ 217 | *.build.csdef 218 | 219 | # Microsoft Azure Emulator 220 | ecf/ 221 | rcf/ 222 | 223 | # Windows Store app package directories and files 224 | AppPackages/ 225 | BundleArtifacts/ 226 | Package.StoreAssociation.xml 227 | _pkginfo.txt 228 | *.appx 229 | *.appxbundle 230 | *.appxupload 231 | 232 | # Visual Studio cache files 233 | # files ending in .cache can be ignored 234 | *.[Cc]ache 235 | # but keep track of directories ending in .cache 236 | !?*.[Cc]ache/ 237 | 238 | # Others 239 | ClientBin/ 240 | ~$* 241 | *~ 242 | *.dbmdl 243 | *.dbproj.schemaview 244 | *.jfm 245 | *.pfx 246 | *.publishsettings 247 | orleans.codegen.cs 248 | 249 | # Including strong name files can present a security risk 250 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 251 | #*.snk 252 | 253 | # Since there are multiple workflows, uncomment next line to ignore bower_components 254 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 255 | #bower_components/ 256 | 257 | # RIA/Silverlight projects 258 | Generated_Code/ 259 | 260 | # Backup & report files from converting an old project file 261 | # to a newer Visual Studio version. Backup files are not needed, 262 | # because we have git ;-) 263 | _UpgradeReport_Files/ 264 | Backup*/ 265 | UpgradeLog*.XML 266 | UpgradeLog*.htm 267 | ServiceFabricBackup/ 268 | *.rptproj.bak 269 | 270 | # SQL Server files 271 | *.mdf 272 | *.ldf 273 | *.ndf 274 | 275 | # Business Intelligence projects 276 | *.rdl.data 277 | *.bim.layout 278 | *.bim_*.settings 279 | *.rptproj.rsuser 280 | *- [Bb]ackup.rdl 281 | *- [Bb]ackup ([0-9]).rdl 282 | *- [Bb]ackup ([0-9][0-9]).rdl 283 | 284 | # Microsoft Fakes 285 | FakesAssemblies/ 286 | 287 | # GhostDoc plugin setting file 288 | *.GhostDoc.xml 289 | 290 | # Node.js Tools for Visual Studio 291 | .ntvs_analysis.dat 292 | node_modules/ 293 | 294 | # Visual Studio 6 build log 295 | *.plg 296 | 297 | # Visual Studio 6 workspace options file 298 | *.opt 299 | 300 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 301 | *.vbw 302 | 303 | # Visual Studio LightSwitch build output 304 | **/*.HTMLClient/GeneratedArtifacts 305 | **/*.DesktopClient/GeneratedArtifacts 306 | **/*.DesktopClient/ModelManifest.xml 307 | **/*.Server/GeneratedArtifacts 308 | **/*.Server/ModelManifest.xml 309 | _Pvt_Extensions 310 | 311 | # Paket dependency manager 312 | .paket/paket.exe 313 | paket-files/ 314 | 315 | # FAKE - F# Make 316 | .fake/ 317 | 318 | # CodeRush personal settings 319 | .cr/personal 320 | 321 | # Python Tools for Visual Studio (PTVS) 322 | __pycache__/ 323 | *.pyc 324 | 325 | # Cake - Uncomment if you are using it 326 | # tools/** 327 | # !tools/packages.config 328 | 329 | # Tabs Studio 330 | *.tss 331 | 332 | # Telerik's JustMock configuration file 333 | *.jmconfig 334 | 335 | # BizTalk build output 336 | *.btp.cs 337 | *.btm.cs 338 | *.odx.cs 339 | *.xsd.cs 340 | 341 | # OpenCover UI analysis results 342 | OpenCover/ 343 | 344 | # Azure Stream Analytics local run output 345 | ASALocalRun/ 346 | 347 | # MSBuild Binary and Structured Log 348 | *.binlog 349 | 350 | # NVidia Nsight GPU debugger configuration file 351 | *.nvuser 352 | 353 | # MFractors (Xamarin productivity tool) working folder 354 | .mfractor/ 355 | 356 | # Local History for Visual Studio 357 | .localhistory/ 358 | 359 | # BeatPulse healthcheck temp database 360 | healthchecksdb 361 | 362 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 363 | MigrationBackup/ 364 | imgui.ini 365 | include/imgui_impl_glfw.h 366 | include/imgui_impl_opengl3.h 367 | src/imgui_impl_glfw.cpp 368 | src/imgui_impl_opengl3.cpp 369 | msvc/conan 370 | msvc/include 371 | msvc/src 372 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # set minimum cmake version 2 | cmake_minimum_required(VERSION 3.5 FATAL_ERROR) 3 | 4 | # project name and language 5 | project(imgui-opencv LANGUAGES CXX) 6 | set(CMAKE_CXX_STANDARD 11) 7 | 8 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 9 | conan_basic_setup() 10 | 11 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 12 | 13 | add_executable(imgui-opencv 14 | app/main.cpp 15 | src/imgui_impl_glfw.cpp 16 | src/imgui_impl_opengl3.cpp 17 | src/gui_renderer.cpp 18 | src/downloader.cpp 19 | include/imgui_impl_glfw.h 20 | include/imgui_impl_opengl3.h 21 | include/gui_renderer.hpp 22 | include/downloader.h 23 | ) 24 | 25 | target_link_libraries(imgui-opencv ${CONAN_LIBS}) -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/README.md: -------------------------------------------------------------------------------- 1 | ## imgui - opencv 2 | 3 | Just a simple demo to add opencv, imgui and poco libraries to a project using Conan.io 4 | The program will download a picture from the Internet and apply a threshold to the image with the desired level through an slider. 5 | 6 | ![use](https://raw.githubusercontent.com/conan-io/examples/master/libraries/imgui-opencv-poco/data/screen-capture.gif) 7 | 8 | ## How to use: 9 | 10 | This project provides 2 build systems. CMake one should work for all platforms. It also integrates a Visual Studio project, only 11 | for those interested in the pure Visual Studio integration without using CMake, but not mandatory, you can use the CMake one for 12 | Windows and having CMake compile with Visual Studio compiler. 13 | 14 | 1. Install conan: https://docs.conan.io/en/latest/installation.html 15 | 2. Clone this repo: `git clone https://github.com/conan-io/examples.git` 16 | 3. `cd libraries/imgui-opencv-poco` 17 | 18 | For CMake 19 | 20 | 4. `mkdir build && cd build` 21 | 5. `conan install ..` 22 | 6. `conan build ..` 23 | 7. `./bin/imgui-opencv` 24 | 25 | For Visual Studio 16 2019 26 | 27 | 4. `cd msvc` 28 | 5. `conan install .. -g=MSBuildDeps -if=conan` 29 | 6. Open msvc.sln 30 | 7. Change to Release and x64 configuration in IDE 31 | 8. Build solution & run 32 | 33 | 34 | #### App running 35 | * You can use a custom url to load your image 36 | * Click 'Open' to open the image 37 | * Apply a threshold with the slider 38 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/app/main.cpp: -------------------------------------------------------------------------------- 1 | // demo application to run a shader that 2 | // opens an image from the internet 3 | // and applies a threshold 4 | // using Imgui, Opencv and Poco 5 | 6 | #include "../include/gui_renderer.hpp" 7 | 8 | int main(int, char **) 9 | { 10 | GUIRenderer renderer; 11 | renderer.InitGUI(); 12 | renderer.Render(); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake 2 | 3 | 4 | class ImguiOpencvDemo(ConanFile): 5 | settings = "os", "compiler", "build_type", "arch" 6 | requires = "imgui/1.79",\ 7 | "glfw/3.3.2",\ 8 | "glew/2.1.0",\ 9 | "opencv/2.4.13.7",\ 10 | "poco/1.10.1" 11 | 12 | generators = "cmake" 13 | 14 | def build(self): 15 | cmake = CMake(self) 16 | cmake.configure() 17 | cmake.build() 18 | 19 | def imports(self): 20 | self.copy("*.dll", dst="bin", src="bin") 21 | self.copy("*.dylib*", dst="bin", src="lib") 22 | self.copy("imgui_impl_glfw.cpp", dst="../src", src="./res/bindings") 23 | self.copy("imgui_impl_opengl3.cpp", dst="../src", src="./res/bindings") 24 | self.copy("imgui_impl_glfw.h*", dst="../include", src="./res/bindings") 25 | self.copy("imgui_impl_opengl3.h*", dst="../include", src="./res/bindings") 26 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/data/bird.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/libraries/imgui-opencv-poco/data/bird.jpeg -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/data/screen-capture.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/libraries/imgui-opencv-poco/data/screen-capture.gif -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/include/downloader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Poco/URIStreamOpener.h" 5 | #include "Poco/StreamCopier.h" 6 | #include "Poco/Path.h" 7 | #include "Poco/URI.h" 8 | #include "Poco/Exception.h" 9 | #include "Poco/SharedPtr.h" 10 | #include "Poco/Net/HTTPStreamFactory.h" 11 | #include "Poco/Net/HTTPSStreamFactory.h" 12 | #include "Poco/Net/FTPStreamFactory.h" 13 | #include "Poco/Net/SSLManager.h" 14 | #include "Poco/Net/AcceptCertificateHandler.h" 15 | #include "Poco/Net/PrivateKeyPassphraseHandler.h" 16 | #include 17 | #include 18 | #include 19 | 20 | using Poco::Exception; 21 | using Poco::Path; 22 | using Poco::SharedPtr; 23 | using Poco::StreamCopier; 24 | using Poco::URI; 25 | using Poco::URIStreamOpener; 26 | using Poco::Net::AcceptCertificateHandler; 27 | using Poco::Net::Context; 28 | using Poco::Net::FTPStreamFactory; 29 | using Poco::Net::HTTPSStreamFactory; 30 | using Poco::Net::HTTPStreamFactory; 31 | using Poco::Net::InvalidCertificateHandler; 32 | using Poco::Net::SSLManager; 33 | 34 | class Downloader 35 | { 36 | public: 37 | Downloader(); 38 | ~Downloader(void); 39 | std::string DownloadFile(const std::string &url); 40 | }; 41 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/include/gui_renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "imgui.h" 5 | #include "../include/imgui_impl_glfw.h" 6 | #include "../include/imgui_impl_opengl3.h" 7 | #include 8 | #include 9 | 10 | #include "../include/downloader.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) 17 | #pragma comment(lib, "legacy_stdio_definitions") 18 | #endif 19 | 20 | class GUIRenderer 21 | { 22 | public: 23 | GUIRenderer(); 24 | ~GUIRenderer(void); 25 | int InitGUI(); 26 | void Render(); 27 | void ShowImage(); 28 | void UpdateTexture(); 29 | 30 | private: 31 | GLFWwindow *window_; 32 | GLuint texture_id_; 33 | int image_width_, image_height_; 34 | Downloader downloader_; 35 | cv::Mat resized_image_; 36 | cv::Mat thresholded_image_; 37 | int threshold_; 38 | }; 39 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/msvc/msvc.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msvc", "msvc.vcxproj", "{0A07CFE2-658B-4348-A811-5112E7AEF058}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0A07CFE2-658B-4348-A811-5112E7AEF058}.Debug|x64.ActiveCfg = Debug|x64 17 | {0A07CFE2-658B-4348-A811-5112E7AEF058}.Debug|x64.Build.0 = Debug|x64 18 | {0A07CFE2-658B-4348-A811-5112E7AEF058}.Debug|x86.ActiveCfg = Debug|Win32 19 | {0A07CFE2-658B-4348-A811-5112E7AEF058}.Debug|x86.Build.0 = Debug|Win32 20 | {0A07CFE2-658B-4348-A811-5112E7AEF058}.Release|x64.ActiveCfg = Release|x64 21 | {0A07CFE2-658B-4348-A811-5112E7AEF058}.Release|x64.Build.0 = Release|x64 22 | {0A07CFE2-658B-4348-A811-5112E7AEF058}.Release|x86.ActiveCfg = Release|Win32 23 | {0A07CFE2-658B-4348-A811-5112E7AEF058}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {5BD4CE16-B58A-4BD0-B73A-352720C0F134} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/msvc/msvc.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {0a07cfe2-658b-4348-a811-5112e7aef058} 25 | msvc 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | true 76 | 77 | 78 | false 79 | 80 | 81 | true 82 | 83 | 84 | false 85 | 86 | 87 | 88 | Level3 89 | true 90 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 91 | true 92 | $(SolutionDir)\include;$(SolutionDir)\..\include;%(AdditionalIncludeDirectories) 93 | 94 | 95 | Console 96 | true 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | true 104 | true 105 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 106 | true 107 | $(SolutionDir)\include;$(SolutionDir)\..\include;%(AdditionalIncludeDirectories) 108 | 109 | 110 | Console 111 | true 112 | true 113 | true 114 | 115 | 116 | 117 | 118 | Level3 119 | true 120 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 121 | true 122 | $(SolutionDir)\include;$(SolutionDir)\..\include;%(AdditionalIncludeDirectories) 123 | 124 | 125 | Console 126 | true 127 | 128 | 129 | 130 | 131 | Level3 132 | true 133 | true 134 | true 135 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 136 | true 137 | $(SolutionDir)\include;$(SolutionDir)\..\include;%(AdditionalIncludeDirectories) 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/msvc/msvc.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/src/downloader.cpp: -------------------------------------------------------------------------------- 1 | #include "downloader.h" 2 | #include 3 | 4 | Downloader::Downloader(void) 5 | { 6 | HTTPStreamFactory::registerFactory(); 7 | FTPStreamFactory::registerFactory(); 8 | HTTPSStreamFactory::registerFactory(); 9 | Poco::Net::initializeSSL(); 10 | } 11 | 12 | Downloader::~Downloader(void) 13 | { 14 | Poco::Net::uninitializeSSL(); 15 | } 16 | 17 | std::string Downloader::DownloadFile(const std::string &url) 18 | { 19 | Path path(url); 20 | std::string filename = ""; 21 | try 22 | { 23 | SharedPtr pCertHandler = new AcceptCertificateHandler(false); 24 | Context::Ptr pContext = new Context(Context::CLIENT_USE, ""); 25 | SSLManager::instance().initializeClient(0, pCertHandler, pContext); 26 | URI uri(url); 27 | std::unique_ptr pStr(URIStreamOpener::defaultOpener().open(uri)); 28 | std::ofstream fileStream; 29 | filename = path.getFileName(); 30 | fileStream.open(filename, std::ios::out | std::ios::trunc | std::ios::binary); 31 | StreamCopier::copyStream(*pStr.get(), fileStream); 32 | fileStream.close(); 33 | } 34 | catch (Exception &exc) 35 | { 36 | std::cerr << exc.displayText() << std::endl; 37 | filename = ""; 38 | } 39 | return filename; 40 | } 41 | -------------------------------------------------------------------------------- /libraries/imgui-opencv-poco/src/gui_renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "gui_renderer.hpp" 2 | 3 | static void glfw_error_callback(int error, const char *description) 4 | { 5 | fprintf(stderr, "Glfw Error %d: %s\n", error, description); 6 | } 7 | 8 | GUIRenderer::GUIRenderer(void) : texture_id_(-1), threshold_(127) 9 | { 10 | } 11 | 12 | GUIRenderer::~GUIRenderer(void) 13 | { 14 | } 15 | 16 | int GUIRenderer::InitGUI() 17 | { 18 | glfwSetErrorCallback(glfw_error_callback); 19 | if (!glfwInit()) 20 | return 1; 21 | 22 | // Decide GL+GLSL versions 23 | #if __APPLE__ 24 | // GL 3.2 + GLSL 150 25 | const char *glsl_version = "#version 150"; 26 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 27 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 28 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 29 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac 30 | #else 31 | // GL 3.0 + GLSL 130 32 | const char *glsl_version = "#version 130"; 33 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 34 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 35 | //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 36 | //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only 37 | #endif 38 | 39 | // Create window with graphics context 40 | window_ = glfwCreateWindow(1280, 720, "imgui-opencv demo", NULL, NULL); 41 | if (window_ == NULL) 42 | return 1; 43 | glfwMakeContextCurrent(window_); 44 | glfwSwapInterval(1); // Enable vsync 45 | 46 | // Initialize OpenGL loader 47 | bool err = glewInit() != GLEW_OK; 48 | if (err) 49 | { 50 | fprintf(stderr, "Failed to initialize OpenGL loader!\n"); 51 | return 1; 52 | } 53 | // Setup Dear ImGui context 54 | IMGUI_CHECKVERSION(); 55 | ImGui::CreateContext(); 56 | ImGuiIO &io = ImGui::GetIO(); 57 | (void)io; 58 | ImGui::StyleColorsDark(); 59 | // Setup Platform/Renderer bindings 60 | ImGui_ImplGlfw_InitForOpenGL(window_, true); 61 | ImGui_ImplOpenGL3_Init(glsl_version); 62 | return 0; 63 | } 64 | 65 | void GUIRenderer::UpdateTexture() 66 | { 67 | unsigned char *data = thresholded_image_.ptr(); 68 | image_width_ = thresholded_image_.cols; 69 | image_height_ = thresholded_image_.rows; 70 | if (texture_id_ == -1) 71 | glGenTextures(1, &texture_id_); 72 | glBindTexture(GL_TEXTURE_2D, texture_id_); 73 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 74 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 75 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 76 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image_width_, image_height_, 0, GL_BGR, GL_UNSIGNED_BYTE, data); 77 | glGenerateMipmap(GL_TEXTURE_2D); 78 | } 79 | 80 | void GUIRenderer::ShowImage() 81 | { 82 | ImGui::Begin("Image"); 83 | // Image downloaded from: https://www.pexels.com/photo/green-bird-1661179/ 84 | static char image_url[256] = "https://raw.githubusercontent.com/conan-io/examples/master/libraries/imgui-opencv-poco/data/bird.jpeg"; 85 | ImGui::InputText("URL:", image_url, IM_ARRAYSIZE(image_url)); 86 | ImGui::SameLine(); 87 | if (ImGui::Button("Open")) 88 | { 89 | std::string filename = ""; 90 | try 91 | { 92 | filename = downloader_.DownloadFile(std::string(image_url)); 93 | } 94 | catch (Exception &exc) 95 | { 96 | std::cerr << exc.displayText() << std::endl; 97 | } 98 | if (filename != "") 99 | { 100 | cv::Mat image = cv::imread(filename.c_str()); 101 | if (!image.empty()) 102 | { 103 | int resized_width = 640; 104 | double scale = static_cast(resized_width)/image.size().width; 105 | cv::resize(image, resized_image_, cv::Size(0, 0), scale, scale); 106 | resized_image_.copyTo(thresholded_image_); 107 | UpdateTexture(); 108 | } 109 | } 110 | } 111 | if (texture_id_ != -1) 112 | { 113 | ImVec2 canvas_size = ImVec2(image_width_, image_height_); 114 | ImGui::ImageButton((void *)(intptr_t)texture_id_, canvas_size, ImVec2(0, 0), ImVec2(1, 1), 0); 115 | ImGui::PushItemWidth(300); 116 | if (ImGui::SliderInt("threshold level", &threshold_, 0, 255)) 117 | { 118 | cv::threshold(resized_image_, thresholded_image_, threshold_, 255, cv::THRESH_BINARY); 119 | UpdateTexture(); 120 | } 121 | } 122 | ImGui::End(); 123 | } 124 | 125 | void GUIRenderer::Render() 126 | { 127 | while (!glfwWindowShouldClose(window_)) 128 | { 129 | glfwPollEvents(); 130 | ImGui_ImplOpenGL3_NewFrame(); 131 | ImGui_ImplGlfw_NewFrame(); 132 | ImGui::NewFrame(); 133 | 134 | ShowImage(); 135 | 136 | ImGui::Render(); 137 | int display_w, display_h; 138 | glfwMakeContextCurrent(window_); 139 | glfwGetFramebufferSize(window_, &display_w, &display_h); 140 | glViewport(0, 0, display_w, display_h); 141 | glClearColor(0.45, 0.56, 0.67, 1); 142 | glClear(GL_COLOR_BUFFER_BIT); 143 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 144 | glfwMakeContextCurrent(window_); 145 | glfwSwapBuffers(window_); 146 | } 147 | ImGui_ImplOpenGL3_Shutdown(); 148 | ImGui_ImplGlfw_Shutdown(); 149 | ImGui::DestroyContext(); 150 | glfwDestroyWindow(window_); 151 | glfwTerminate(); 152 | } 153 | -------------------------------------------------------------------------------- /libraries/poco/md5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(MD5Encrypter) 3 | 4 | if(CMAKE_VERSION VERSION_LESS 3.0.0) 5 | include(CheckCXXCompilerFlag) 6 | check_cxx_compiler_flag(-std=c++11 COMPILER_SUPPORTS_CXX11) 7 | check_cxx_compiler_flag(-std=c++0x COMPILER_SUPPORTS_CXX0X) 8 | if(COMPILER_SUPPORTS_CXX11) 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 10 | elseif(COMPILER_SUPPORTS_CXX0X) 11 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") 12 | endif() 13 | else() 14 | SET(CMAKE_CXX_STANDARD 11) 15 | SET(CMAKE_CXX_STANDARD_REQUIRED ON) 16 | endif() 17 | 18 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 19 | conan_basic_setup() 20 | 21 | add_executable(md5 md5.cpp) 22 | target_link_libraries(md5 ${CONAN_LIBS}) 23 | -------------------------------------------------------------------------------- /libraries/poco/md5/README.md: -------------------------------------------------------------------------------- 1 | # Poco MD5 Example 2 | 3 | Example of and MD5 calculation app using POCO C++ libraries installed with Conan C/C++ package manager. 4 | 5 | Mostly used to run the conan.io getting started: https://docs.conan.io/en/latest/getting_started.html 6 | 7 | ## Compiling steps 8 | 9 | 1. Create a build directory: 10 | 11 | ``` 12 | $ mkdir build && cd build 13 | ``` 14 | 15 | 2. Install dependencies (Poco -> OpenSSL -> zlib): 16 | 17 | ``` 18 | $ conan install .. 19 | ``` 20 | 21 | 3. Configure the CMake project (Using MSVC 16 in this example): 22 | 23 | ``` 24 | $ cmake .. -G "Visual Studio 16 2019" 25 | ``` 26 | 27 | 4. Build it: 28 | 29 | ``` 30 | $ cmake --build . --config Release 31 | ``` 32 | 33 | 5. Run the application: 34 | 35 | ``` 36 | $ .\bin\md5.exe 37 | c3fcd3d76192e4007dfb496cca67e13b 38 | ``` 39 | -------------------------------------------------------------------------------- /libraries/poco/md5/build.bat: -------------------------------------------------------------------------------- 1 | if "%CMAKE_GENERATOR%"=="" ( 2 | ECHO CMAKE_GENERATOR environment variable not defined. Please define the CMake generator in the CMAKE_GENERATOR environment variable. 3 | ) else ( 4 | @ECHO ON 5 | 6 | RMDIR /Q /S build 7 | MKDIR build 8 | PUSHD build 9 | 10 | conan install .. 11 | cmake .. -G "%CMAKE_GENERATOR%" -A "%CMAKE_GENERATOR_PLATFORM%" 12 | cmake --build . --config Release 13 | 14 | bin\md5.exe 15 | ) 16 | -------------------------------------------------------------------------------- /libraries/poco/md5/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | rm -rf build 7 | mkdir build 8 | pushd build 9 | 10 | conan install .. --build=missing 11 | cmake .. -DCMAKE_BUILD_TYPE=Release 12 | cmake --build . 13 | 14 | bin/md5 15 | -------------------------------------------------------------------------------- /libraries/poco/md5/conanfile.txt: -------------------------------------------------------------------------------- 1 | [requires] 2 | poco/1.9.4 3 | 4 | [generators] 5 | cmake 6 | -------------------------------------------------------------------------------- /libraries/poco/md5/md5.cpp: -------------------------------------------------------------------------------- 1 | #include "Poco/MD5Engine.h" 2 | #include "Poco/DigestStream.h" 3 | 4 | #include 5 | 6 | 7 | int main(int argc, char** argv) 8 | { 9 | Poco::MD5Engine md5; 10 | Poco::DigestOutputStream ds(md5); 11 | ds << "abcdefghijklmnopqrstuvwxyz"; 12 | ds.close(); 13 | std::cout << Poco::DigestEngine::digestToHex(md5.digest()) << std::endl; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /libraries/protobuf/serialization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1.2) 2 | project(sensor CXX) 3 | 4 | set(CMAKE_VERBOSE_MAKEFILE ON) 5 | 6 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 7 | conan_basic_setup(TARGETS) 8 | 9 | find_package(Protobuf REQUIRED) 10 | 11 | protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS sensor.proto) 12 | protobuf_generate_python(PROTO_PYS sensor.proto) 13 | 14 | add_executable(${PROJECT_NAME} main.cc ${PROTO_SRCS} ${PROTO_HDRS}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC CONAN_PKG::protobuf) 16 | target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}) 17 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11) 18 | 19 | add_custom_target(proto_python ALL DEPENDS ${PROTO_PYS}) -------------------------------------------------------------------------------- /libraries/protobuf/serialization/README.md: -------------------------------------------------------------------------------- 1 | # Conan Protobuf Example 2 | 3 | ## Protobuf example using Conan for blog post 4 | 5 | - Conan.io blog: https://blog.conan.io 6 | 7 | #### How to build 8 | To build this project using cmake: 9 | 10 | git clone https://github.com/conan-io/examples.git conan-examples 11 | cd conan-examples/libraries/protobuf/serialization 12 | mkdir build && cd build 13 | conan install .. 14 | cmake .. 15 | cmake --build . 16 | bin/sensor 17 | 18 | #### Requirements 19 | - CMake >=3.1.3 20 | - C++ compiler with C++11 support (Protobuf requirement) 21 | - Conan >=1.9.1 22 | -------------------------------------------------------------------------------- /libraries/protobuf/serialization/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/conan-io/examples/3244d6a6275312302bec123559a74126be1f168a/libraries/protobuf/serialization/__init__.py -------------------------------------------------------------------------------- /libraries/protobuf/serialization/build.bat: -------------------------------------------------------------------------------- 1 | if "%CMAKE_GENERATOR%"=="" ( 2 | ECHO CMAKE_GENERATOR environment variable not defined. Please define the CMake generator in the CMAKE_GENERATOR environment variable. 3 | ) else ( 4 | @ECHO ON 5 | 6 | RMDIR /Q /S build 7 | MKDIR build 8 | PUSHD build 9 | 10 | conan install .. 11 | cmake .. -G "%CMAKE_GENERATOR%" -A "%CMAKE_GENERATOR_PLATFORM%" 12 | cmake --build . --config Release 13 | 14 | bin\sensor.exe 15 | 16 | python ../main.py 17 | ) 18 | -------------------------------------------------------------------------------- /libraries/protobuf/serialization/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | rm -rf build 7 | mkdir build 8 | pushd build 9 | 10 | conan install .. --build=missing 11 | cmake .. -DCMAKE_BUILD_TYPE=Release 12 | cmake --build . 13 | 14 | bin/sensor 15 | 16 | python ../main.py 17 | -------------------------------------------------------------------------------- /libraries/protobuf/serialization/conanfile.txt: -------------------------------------------------------------------------------- 1 | [requires] 2 | protobuf/3.20.0 3 | 4 | [generators] 5 | cmake 6 | -------------------------------------------------------------------------------- /libraries/protobuf/serialization/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "sensor.pb.h" 4 | 5 | int main() { 6 | Sensor sensor; 7 | sensor.set_name("Laboratory"); 8 | sensor.set_temperature(23.4); 9 | sensor.set_humidity(68); 10 | sensor.set_door(Sensor_SwitchLevel_OPEN); 11 | 12 | std::cout << "Serialize " << sensor.name() << " to sensor.data\n"; 13 | std::ofstream ofs("sensor.data"); 14 | sensor.SerializeToOstream(&ofs); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /libraries/protobuf/serialization/main.py: -------------------------------------------------------------------------------- 1 | import os 2 | from build.sensor_pb2 import Sensor 3 | 4 | if __name__ == "__main__": 5 | with open("sensor.data", 'rb') as file: 6 | content = file.read() 7 | 8 | print("Retrieve Sensor object from sensor.data") 9 | sensor = Sensor() 10 | sensor.ParseFromString(content) 11 | door = "Open" if sensor.door else "Closed" 12 | print("Sensor name: {}".format(sensor.name)) 13 | print("Sensor temperature: {}".format(sensor.temperature)) 14 | print("Sensor humidity: {}".format(sensor.humidity)) 15 | print("Sensor door: {}".format(door)) 16 | -------------------------------------------------------------------------------- /libraries/protobuf/serialization/sensor.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | message Sensor { 3 | required string name = 1; 4 | required double temperature = 2; 5 | required int32 humidity = 3; 6 | 7 | enum SwitchLevel { 8 | CLOSED = 0; 9 | OPEN = 1; 10 | } 11 | required SwitchLevel door = 4; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | skipsdist=True 3 | envlist = 4 | py{38}-conancurrent 5 | 6 | [testenv] 7 | deps = 8 | conancurrent: conan<2 9 | coverage: coverage-enable-subprocess 10 | tabulate 11 | packaging 12 | colorama 13 | protobuf 14 | 15 | setenv = 16 | PYTHONDONTWRITEBYTECODE=1 17 | PYTHONPATH = {toxinidir}{:}{env:PYTHONPATH:} 18 | CONAN_PRINT_RUN_COMMANDS=1 19 | 20 | coverage: PYTEST_TEST_RUNNER=coverage run -m pytest 21 | coverage: COVERAGE_PROCESS_START={toxinidir}/.coveragerc 22 | coverage: COVERAGE_FILE={toxinidir}/.coverage 23 | coverage: PYTESTDJANGO_COVERAGE_SRC={toxinidir}/ 24 | 25 | passenv = PYTEST_ADDOPTS * 26 | 27 | commands = 28 | python .ci/run.py 29 | --------------------------------------------------------------------------------