{"action":"created","issue":{"url":"https://api.github.com/repos/toeb/cmakepp/issues/63","labels_url":"https://api.github.com/repos/toeb/cmakepp/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/toeb/cmakepp/issues/63/comments","events_url":"https://api.github.com/repos/toeb/cmakepp/issues/63/events","html_url":"https://github.com/toeb/cmakepp/issues/63","id":53177662,"number":63,"title":"Integrate oo-cmake with biicode C/C++ dependency management","user":{"login":"Manu343726","id":1561197,"avatar_url":"https://avatars.githubusercontent.com/u/1561197?v=3","gravatar_id":"","url":"https://api.github.com/users/Manu343726","html_url":"https://github.com/Manu343726","followers_url":"https://api.github.com/users/Manu343726/followers","following_url":"https://api.github.com/users/Manu343726/following{/other_user}","gists_url":"https://api.github.com/users/Manu343726/gists{/gist_id}","starred_url":"https://api.github.com/users/Manu343726/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manu343726/subscriptions","organizations_url":"https://api.github.com/users/Manu343726/orgs","repos_url":"https://api.github.com/users/Manu343726/repos","events_url":"https://api.github.com/users/Manu343726/events{/privacy}","received_events_url":"https://api.github.com/users/Manu343726/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2014-12-31T10:31:51Z","updated_at":"2015-03-02T20:59:53Z","closed_at":"2015-02-18T18:43:37Z","body":"Hi! I'm Manu Sánchez, from the [biicode](https://www.biicode.com) team.  \r\n\r\nI'm working intensively with CMake scripts and I find your library so useful to me. Maps, function calls, etc; features that make feasible writing complex CMake scripts without going crazy!\r\n\r\nbiicode is a file-based dependency manager for C and C++, in the same spirit of Java's Maven and Maven Central or Python's pip. The tool uses CMake under the hood to process builds, so to setup a biicode *block** you should play a bit with `CMakeLists.txt` files. *A block is our unit of code sharing, think of it as a package.*    \r\nHere's an example, part of the `CMakeLists.txt` file of our [Box2D block](https://www.biicode.com/erincatto/erincatto/box2d/master/10):\r\n\r\n``` cmake\r\nIF(BIICODE)\r\n    INCLUDE(${CMAKE_HOME_DIRECTORY}/biicode.cmake)\r\n    INIT_BIICODE_BLOCK()\r\n    ADD_DEFINITIONS(-DGLEW_STATIC)\r\n    SET(BII_LIB_SYSTEM_DEPS )\r\n    ADD_BIICODE_TARGETS()\r\n    target_include_directories(${BII_LIB_TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})\r\nELSE()\r\n    cmake_minimum_required(VERSION 2.6)\r\n\r\n    project(Box2D)\r\n\r\n    if(UNIX)\r\n        set(BOX2D_INSTALL_BY_DEFAULT ON)\r\n    else(UNIX)\r\n        set(BOX2D_INSTALL_BY_DEFAULT OFF)\r\n    endif(UNIX)\r\n\r\n    option(BOX2D_INSTALL \"Install Box2D libs, includes, and CMake scripts\" ${BOX2D_INSTALL_BY_DEFAULT})\r\n    option(BOX2D_INSTALL_DOC \"Install Box2D documentation\" OFF)\r\n    ...\r\nENDIF()\r\n```\r\n\r\nIt's exactly the same `CMakeLists.txt` from the original library, just adding a couple of toggles to make it work with biicode.  \r\nTo use Box2D, you only have to `#include` it in your C/C++ code, biicode does everything else (Download, setup build, etc). [Check our docs](http://docs.biicode.com/) for more info.\r\n\r\nSince version 2.0 we support dependency management of CMake scripts, via `include()` directives. Your library was very useful to me, so I created a block to deploy and reuse it easily across all my biicode blocks. Now I'm able to use your library inside my biicode `CMakeLists.txt` files just doing `include(manu343726/oo-cmake/oo-cmake)`.\r\n\r\nI hope you like it.\r\n\r\n\r\n## oo-cmake changes\r\n\r\nI tried not to touch your codebase at all, but use Travis CI to build and publish the block from your sources. So the only changes I propose you should be on the `.travis.yml` file (Among other minor changes on the README).\r\n\r\n### The block\r\n\r\nThe idea is to have a biicode block with all your sources, while users access functionality via `include(manu343726/oo-cmake/oo-cmake)`. Check the block [here](https://www.biicode.com/manu343726/oo-cmake).\r\n\r\n### Dependency management\r\n\r\nbiicode is a file-based dependency management system. That means biicode uses files as its unit of dependency. So if you use `foo.cpp` from a `manu343726/lib` block, biicode will download the `foo.cpp` file only, not the entire `manu343726/lib` block. This is interesting for large libraries and codebases, because only the `#include`d files will be downloaded.\r\n\r\nBut that does not work in this case. Your `oo-cmake.cmake` file depends in many CMake scripts and some extra C++ files that should be retrieved too, but you are not using our `include(user/block/script)` convention (And I'm not going to change your sources), so this dependency retrieving does not work directly.\r\n\r\nHowever, biicode allows you to specify dependencies manually in the `biicode.conf` file, the configuration file of the block:\r\n\r\n```\r\n[dependencies]\r\n    # Manual adjust file implicit dependencies, add (+), remove (-), or overwrite (=)\r\n    # hello.h + hello_imp.cpp hello_imp2.cpp\r\n    # *.h + *.cpp\r\n    oo-cmake.cmake + build/* cmake/* resources/* src/*\r\n```\r\nIn our case, I specified explicitly that `oo-cmake.cmake` depends on the contents of the `build/`, `cmake/`, `resources/`, and `src/` folders. Now biicode will download that folders when the ` oo-cmake.cmake` file is used.\r\n\r\n### CMakeLists.txt\r\n\r\nEach biicode block has it's own `CMakeLists.txt` with building configuration. If no CMakeLists.txt is provided, biicode generates one. By default biicode searches for any C/C++ file adding it to block targets (Library or executable, depending on the kind of file: Is it a header?, is it a `.cpp` with a `main()` function?, etc). \r\n\r\nThis process, done by the `ADD_BIICODE_TARGETS()` macro, works like a charm with C/C++ libraries, but not with CMake libraries that use some C/C++ files like yours. We don't want any C/C++ target in the oo-cmake block, we don't even want a target at all since this is designed to be `include()`d only. \r\n\r\nThe generated target is called `manu343726_oo-cmake_src_cmakeJsonParser_cmakeJsonParser`. SInce we don't want that target to be builded as part of our block, disable it after the `ADD_BIICODE_TARGETS()` call:\r\n\r\n``` cmake\r\nINIT_BIICODE_BLOCK()\r\nADD_BIICODE_TARGETS()\r\n\r\nset_target_properties(manu343726_oo-cmake_src_cmakeJsonParser_cmakeJsonParser                                                      \r\n                          PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) \r\n```\r\n\r\n### Generating and publishing the block automatically\r\n\r\nSo we have to get the block, copy your library sources on it, write the custom ` biicode.conf`, and edit the default biicode `CMakeLists.txt` to disable the undesired target. Then publish the block.\r\n\r\nIf you suppose the block already exists this is easier, we just need to open the block and update its contents:\r\n\r\n``` bash\r\n$ bii init #Initialize biicode project\r\n$ bii open manu343726/oo-cmake #Download the entire block for editing\r\n$ cp YOUR_SOURCES ./blocks/manu343726/oo-cmake/\r\n$ bii user manu343726 #We need to log in to publish a block\r\n$ bii publish manu343726/oo-cmake\r\n```\r\n\r\nWhat I did is to create the block using the web inteface, add the custom `biicode.conf` and `CMakeLists.txt` to it, and working in travis starting with that:\r\n\r\n``` yaml\r\ninstall: \r\n- wget http://apt.biicode.com/install.sh && chmod +x install.sh && ./install.sh\r\n- bii setup:cpp\r\nscript:\r\n- bii init\r\n- bii open manu343726/oo-cmake\r\n- rsync -av --exclude=\"blocks\" --exclude=\"bii\" --exclude=\".git\" --exclude=\".gitignore\" . blocks/manu343726/oo-cmake\r\n- cmake -P build/script.cmake\r\nafter_success: cmake -P build/after_success.cmake\r\nafter_failure: cmake -P build/after_failure.cmake\r\nafter_script: cmake -P build/after_script.cmake\r\ndeploy:\r\n  provider: biicode\r\n  user: manu343726\r\n  password:\r\n    secure: MY ENCRYPTED BIICODE PASSWORD\r\n  skip_cleanup: true #The biicode block is generated during build, don't discard build changes!\r\n```\r\n\r\nNote that Travis CI supports biicode deployment out of the box, just install the travis gem and run biicode setup inside your project:\r\n\r\n```\r\n$ gem install travis\r\n$ cd oo-cmake\r\n$ travis setup biicode\r\n```\r\n\r\nThis command will ask you for biicode credentials, some configuration flags, and then will add the `deploy` entry to your `travis.yml`.\r\n\r\n## Accepting changes\r\n\r\nThis changes cannot be accepted directly via a pull request, because some changes depend on configuration based on my project:\r\n\r\n - **The biicode block is published and owned by my account**: All the examples described above use my ` manu343726` account, and the block is `manu343726/oo-cmake`. If you accept this proposal I suppose that you want your own biicode account and to release the oo-cmake with it. That said, I have no problem with owning the block, but this is not possible if you merge the proposal into your project (See next point).\r\n\r\n - **The travis encryption is based on my project**. Travis encryption does not work across forks. So even if you like to deploy the library to biicode using my account, the deploy will not work since you need my password to publish the block. \r\n\r\nAs I said previously, I tried not to modify your sources. Actually, this is [the diff between my fork and your `master` branch](https://github.com/Manu343726/oo-cmake/compare/toeb:master...master):\r\n\r\n``` diff\r\n@@ -3,24 +3,22 @@ os:\r\n  - linux\r\n  - osx\r\n compiler:\r\n-  - gcc\r\n+ - gcc\r\n matrix:\r\n   allow_failures:\r\n-    - os: osx\r\n+   - os: osx\r\n #env:\r\n # - CMAKE_DIR=\"v3.0\" CMAKE_VERSION=\"3.0.1\"\r\n # - CMAKE_DIR=\"v2.8\" CMAKE_VERSION=\"2.8.12.2\"\r\n-notifications:\r\n-  slack: fallto:MlnVOMNkx8YopsaSSxqh2Rcr\r\n before_install:\r\n-  - sudo apt-get install cmake\r\n-  - sudo apt-get install mercurial\r\n-  - sudo apt-get install git  \r\n-  - sudo apt-get install subversion\r\n-  - git config --global user.email \"travis-ci@example.com\"\r\n-  - git config --global user.name \"Build Server\"\r\n-install:\r\n-     # install cmake --\r\n+ - sudo apt-get install cmake\r\n+ - sudo apt-get install mercurial\r\n+ - sudo apt-get install git\r\n+ - sudo apt-get install subversion\r\n+ - git config --global user.email \"travis-ci@example.com\"\r\n+ - git config --global user.name \"Build Server\"\r\n+install: \r\n+    # install cmake --\r\n     #- wget \"http://www.cmake.org/files/${CMAKE_DIR}/cmake-${CMAKE_VERSION}.tar.gz\"\r\n     #- tar xf \"cmake-${CMAKE_VERSION}.tar.gz\"\r\n     #- cmake -Hcmake-${CMAKE_VERSION} -B_builds -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=\"`pwd`/_install\"\r\n @@ -31,12 +29,26 @@ install:\r\n     #- which cmake\r\n     #- cmake --version    \r\n     # -- end\r\n-script: \"cmake -P build/script.cmake\"\r\n-after_success: \"cmake -P build/after_success.cmake\"\r\n-after_failure: \"cmake -P build/after_failure.cmake\"\r\n-after_script: \"cmake -P build/after_script.cmake\"\r\n+ - wget http://apt.biicode.com/install.sh && chmod +x install.sh && ./install.sh\r\n+ - bii setup:cpp\r\n+script:\r\n+ - bii init\r\n+ - bii open manu343726/oo-cmake\r\n+ - rsync -av --exclude=\"blocks\" --exclude=\"bii\" --exclude=\".git\" --exclude=\".gitignore\" . blocks/manu343726/oo-cmake\r\n+ - cmake -P build/script.cmake\r\n+after_success: cmake -P build/after_success.cmake\r\n+after_failure: cmake -P build/after_failure.cmake\r\n+after_script: cmake -P build/after_script.cmake\r\n+\r\n+deploy:\r\n+  provider: biicode\r\n+  user: manu343726\r\n+  password:\r\n+    secure: ZBdHcI8HEKMSBZbx5xWT5d7iIzm6db8YDibt7TNC9xM3B30+/D+oFXkvMquxp2cYuhhU2cX+IAwLA4AhJmbYzDvUHnIA+7fJjO8DFngf933cv7lO+Wu/pbEN9gmn/nNxR9zZ1kQfH627gWaehq0MQEhXyLebTzDjY3u1h55PIpU=\r\n+  skip_cleanup: true #The biicode block is generated during build, don't discard build changes!\r\n \r\n # branches:\r\n #   only:\r\n #     - master\r\n-#     - devel\r\n+#     - devel\r\n```\r\n\r\n*There are changes on the `README.md` too, the travis badge points to my builds, there's a cool biicode badge I generated with [shields.io](http://shields.io/), etc.*  \r\n\r\nSince you have to perform some steps to accept this changes, not only to accept `.travis.yml` changes, I decided to put this as an issue with everything explained in depth instead of a pull request.\r\n\r\nLet's see how you can setup your project to deploy a biicode block automatically:\r\n\r\n### How to create your oo-cmake block\r\n\r\n*You can download our client from [here](https://www.biicode.com/downloads)*.\r\n\r\n1. First **[create a biicode account](https://www.biicode.com/accounts/signup)**.\r\n2. **Set up a new biicode project localy**. This will be used to create and set   up the block:\r\n   \r\n        $ bii init oo-cmake-setup\r\n        $ cd oo-cmake-setup\r\n        \r\n  A folder `oo-cmake-setup` is created, with three directories inside:\r\n  \r\n  - `bii/`: biicode project metadata. Our `.git/` counterpart.\r\n  - `blocks`: Folder containing blocks being edited in the project. Each block has the path `blocks/username/blockname`.\r\n  - `deps/`: Location of dependency blocks. Follows the same path convention as project blocks: `deps/user/blockname`.   \r\n \r\n Say we have a block `a` created with the account `user`. That block has some sources depending on a block `b` created by `developer`. After running ` bii find` (The command which searches and solves dependencies) our project looks like this:\r\n\r\n        +-- oo-cmake-setup\r\n        |   +-- bii\r\n        |   +-- blocks\r\n        |   |   +-- user\r\n        |   |   |   +-- a\r\n        |   |   |   |   +-- main.cpp\r\n        |   +-- deps\r\n        |   |   +-- user\r\n        |   |   |   +-- b\r\n        |   |   |   |   +-- foo.hpp\r\n*In this example, `main.cpp` from `a` has an `#include <developer/b/foo.hpp>` directive*.\r\n\r\n See [`getting started`](http://docs.biicode.com/c++/gettingstarted.html) from our docs for more info about project layout.\r\n\r\n3. **Create the `oo-cmake` block**:\r\n   \r\n        $ bii new toeb/oo-cmake\r\n \r\n4. **Create the `biicode.conf` file for the block, adding the explicit dependencies inside the `[dependencies]` entry**:\r\n\r\n        $ vim blocks/toeb/oo-cmake/biicode.conf\r\n \r\n    ---\r\n        [dependencies]\r\n           oo-cmake.cmake + build/* cmake/* resources/* src/*\r\n\r\n6. **Create a `CMakeLists.txt` for the block with the target disable:\r\n\r\n        INIT_BIICODE_BLOCKS()\r\n        ADD_BIICODE_TARGETS()\r\n        set_target_properties(toeb_oo-cmake_src_cmakeJsonParser_cmakeJsonParser                                                      \r\n                          PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) \r\n\r\n   \r\n5. **Publish the block**: \r\n    \r\n        $ bii publish toeb/oo-cmake\r\n    \r\n    This will ask you for your account and password. Then the block is in the biicode cloud and we are ready to update it automatically via Travis CI builds.\r\n\r\n### Updating the block with Travis CI\r\n\r\nTake your `.travis.yml` and add the following entries:\r\n\r\n``` yaml\r\ninstall: \r\n- wget http://apt.biicode.com/install.sh && chmod +x install.sh && ./install.sh #\r\n- bii setup:cpp\r\nscript:\r\n- bii init\r\n- bii open toeb/oo-cmake\r\n- rsync -av --exclude=\"blocks\" --exclude=\"bii\" --exclude=\".git\" --exclude=\".gitignore\" . blocks/manu343726/oo-cmake\r\n```\r\n\r\nNow run `travis setup biicode`. It will add the deploy entry to the `.travis.yml` file:\r\n\r\n``` yaml\r\ndeploy:\r\n  provider: biicode\r\n  user: toeb\r\n  password:\r\n    secure: YOUR ENCRYPTED BIICODE PASSWORD\r\n  skip_cleanup: true #The biicode block is generated during build, don't discard build changes!\r\n```\r\n\r\n**Note the `skip_cleanup` entry, it's very important!** Since the block is opened and updated during build, we should specify Travis CI to not discard build changes before deploy. It should be added explicitly.\r\n\r\n## That's all!  \r\n\r\nFeel free to ask me whatever question you want to, use the comments system bellow if you like."},"comment":{"url":"https://api.github.com/repos/toeb/cmakepp/issues/comments/76821293","html_url":"https://github.com/toeb/cmakepp/issues/63#issuecomment-76821293","issue_url":"https://api.github.com/repos/toeb/cmakepp/issues/63","id":76821293,"user":{"login":"Manu343726","id":1561197,"avatar_url":"https://avatars.githubusercontent.com/u/1561197?v=3","gravatar_id":"","url":"https://api.github.com/users/Manu343726","html_url":"https://github.com/Manu343726","followers_url":"https://api.github.com/users/Manu343726/followers","following_url":"https://api.github.com/users/Manu343726/following{/other_user}","gists_url":"https://api.github.com/users/Manu343726/gists{/gist_id}","starred_url":"https://api.github.com/users/Manu343726/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Manu343726/subscriptions","organizations_url":"https://api.github.com/users/Manu343726/orgs","repos_url":"https://api.github.com/users/Manu343726/repos","events_url":"https://api.github.com/users/Manu343726/events{/privacy}","received_events_url":"https://api.github.com/users/Manu343726/received_events","type":"User","site_admin":false},"created_at":"2015-03-02T20:59:53Z","updated_at":"2015-03-02T20:59:53Z","body":"You asked me for help to update the bii block on travis builds.\r\n\r\nI think the best way is to use raw bii calls instead of the travis deploy service (It's a bit limited). Something like this:\r\n\r\n``` yaml\r\nlanguage: cpp\r\nos:\r\n - linux\r\n - osx\r\ncompiler:\r\n  - gcc\r\nmatrix:\r\n  allow_failures:\r\n    - os: osx\r\nenv:\r\n  global:\r\n    # github api token and secret\r\n    secure: \"fWQnD0UqfX9SfctAu7lAnUJ4V5brp8UqdmPxQ67MlbmR5GAXQK9yezeQEsOnDCbihM6H/WTkonR920+B14fOb1NO0RSY39yHzjZG6B4tM6ZJwRW0CAlgFzlCqdwyL//7EhfKnxmWqflsA8oY+ihuZsj8P9ZtQSpNWENlu0Cl324=\"\r\n    secure: \"i9rwJYZa6VDCpjXFaJoUggdn12mC1WB2zb9zaFP57VocTyL37Kpt3btXb9De5VQEJbyVKG2b9zlts20dEqvvruXBBuhWi+15VICT1yqq3zDQt25EPPDXw+AcB58dG+0icY1VKklWXR2Qxms4x/EZSN4TDNUp6LZgh+ACWlE1SRU=\"\r\n  matrix:\r\n    - CMAKE_DIR=\"v3.1\" CMAKE_VERSION=\"3.1.2\" \r\n    - CMAKE_DIR=\"v3.0\" CMAKE_VERSION=\"3.0.1\" \r\n    - CMAKE_DIR=\"v2.8\" CMAKE_VERSION=\"2.8.12.2\"\r\n    - CMAKE_DIR=\"v2.8\" CMAKE_VERSION=\"2.8.7\"\r\nmatrix:\r\n  allow_failures:\r\n    - env: CMAKE_DIR=\"v2.8\" CMAKE_VERSION=\"2.8.7\"\r\nnotifications:\r\n  slack: fallto:MlnVOMNkx8YopsaSSxqh2Rcr\r\nbefore_install:\r\n  - sudo add-apt-repository --yes ppa:kalakris/cmake\r\n  - sudo apt-get update -qq\r\n  - sudo apt-get install mercurial\r\n  - sudo apt-get install git  \r\n  - sudo apt-get install subversion\r\n  - git config --global user.email \"travis-ci@example.com\"\r\n  - git config --global user.name \"Build Server\"\r\ninstall:\r\n  - wget http://apt.biicode.com/install.sh && chmod +x install.sh && ./install.sh\r\n  - bii setup:cpp\r\n  - bii init\r\n  - bii open toeb/cmakepp\r\n  - rsync -av --exclude=\"blocks\" --exclude=\"bii\" --exclude=\".git\" --exclude=\".gitignore\" . blocks/toeb/cmakepp > /dev/null\r\n  #- sudo apt-get install cmake\r\n  #- cmake --version\r\n  # install cmake --\r\n  - wget \"http://www.cmake.org/files/${CMAKE_DIR}/cmake-${CMAKE_VERSION}.tar.gz\"\r\n  - tar xf \"cmake-${CMAKE_VERSION}.tar.gz\"\r\n  - cmake -Hcmake-${CMAKE_VERSION} -B_builds -DCMAKE_BUILD_TYPE=Release -DCMAKE_USE_OPENSSL=ON -DCMAKE_INSTALL_PREFIX=\"`pwd`/_install\"\r\n  - cmake --build _builds --target install\r\n  - export PATH=\"`pwd`/_install/bin:${PATH}\"\r\n  # -- end\r\n  # verify installed cmake --\r\n  - which cmake\r\n  - cmake --version    \r\n  #-- end\r\n \r\nscript: \r\n - cmake -P build/script.cmake\r\n\r\nafter_success: \r\n - \"cmake -P build/after_success.cmake\"\r\n - bii user toeb -p $YOUR_ENCRYPTED_BII_PASSWORD\r\n - bii publish toeb/cmakepp --tag STABLE\r\nafter_failure: \"cmake -P build/after_failure.cmake\"\r\nafter_script: \"cmake -P build/after_script.cmake\"\r\n\r\ndeploy:\r\n  - provider: releases\r\n    api_key:\r\n      secure: Y8fO6kLjCkPHi7qa1tkv9kVKvoEe/VsRO9gY8LFFsBliKFD1DC/+Sf1l5ij3SGawFduzCWWk4O62lEVawEnUhOqHFb+D6+SExVzF5QvkgSvnp6BkpyosvCn0/FXBy4tt4KZyLSJ3CzqLvDnD99d7vouHyxiLZy4JSTjmlnklkAo=\r\n    file: release/cmakepp.cmake\r\n    skip_cleanup: true\r\n    on:\r\n      tags: true\r\n      all_branches: true\r\n```\r\n\r\nNote how the block is published as `STABLE`. This allows anyone to use your block. *By default blocks published as `DEV` cannot be reused by others except explicitly asked in the user `policies.bii` file.*\r\n\r\nYou can also use travis branch variables to set up different biicode tracks for your block matching each development branch you have on the repo. Check the python scripts I have at [boost-biicode](https://github.com/Manu343726/boost-biicode) to generate different block tracks from block templates. *These scripts for easy block generation and publication will be released anytime soon as an independent project*"}}