From 85d66c7a3b89cbd1eba61251b135d968b92bedd9 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 24 Oct 2019 15:36:05 +0200 Subject: [PATCH] Updated Readme.md, re-add LIBNEST2D_HEADER_ONLY --- .gitlab-ci.yml | 4 ++-- CMakeLists.txt | 24 ++++++++++++++++-------- README.md | 29 ++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1cdd3b6..0319259 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ build-clang: script: - mkdir -p build-clang - cd build-clang - - cmake .. -GNinja -DCMAKE_CXX_COMPILER=clang++-7 -DCMAKE_C_COMPILER=clang-7 -DCMAKE_BUILD_TYPE=Release -DLIBNEST2D_BUILD_EXAMPLES=ON -DLIBNEST2D_BUILD_UNITTESTS=ON -DRP_ENABLE_DOWNLOADING=ON + - cmake .. -GNinja -DCMAKE_CXX_COMPILER=clang++-7 -DCMAKE_C_COMPILER=clang-7 -DCMAKE_BUILD_TYPE=Release -DLIBNEST2D_BUILD_EXAMPLES=ON -DLIBNEST2D_BUILD_UNITTESTS=ON -DRP_ENABLE_DOWNLOADING=ON -DLIBNEST2D_HEADER_ONLY=OFF - cmake --build . --target all artifacts: paths: @@ -41,7 +41,7 @@ build-gcc: script: - mkdir -p build-gcc - cd build-gcc - - cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DLIBNEST2D_BUILD_EXAMPLES=ON -DLIBNEST2D_BUILD_UNITTESTS=ON -DRP_ENABLE_DOWNLOADING=ON + - cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DLIBNEST2D_BUILD_EXAMPLES=ON -DLIBNEST2D_BUILD_UNITTESTS=ON -DRP_ENABLE_DOWNLOADING=ON -DLIBNEST2D_HEADER_ONLY=OFF - cmake --build . --target all artifacts: paths: diff --git a/CMakeLists.txt b/CMakeLists.txt index 677b54d..14e4085 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,8 @@ option(LIBNEST2D_BUILD_EXAMPLES "If enabled, examples will be built." OFF) option(BUILD_SHARED_LIBS "Build shared libs instead of static (applies for dependencies as well)" OFF) +option(LIBNEST2D_HEADER_ONLY "If enabled static library will not be built." ON) + set(GEOMETRY_BACKENDS clipper boost eigen) set(LIBNEST2D_GEOMETRIES clipper CACHE STRING "Geometry backend") set_property(CACHE LIBNEST2D_GEOMETRIES PROPERTY STRINGS ${GEOMETRY_BACKENDS}) @@ -86,15 +88,21 @@ target_include_directories(libnest2d_headeronly INTERFACE $ libnest2d)``` line to your CMake build script. You can also compile the library with the selected dependencies into a static or shared library. To do this just disable the ```LIBNEST2D_HEADER_ONLY``` option in the CMake config. - -2. Copying source files directly into a target project: The library is header -only and it is enough to just copy the content of the ```include``` directory or specify the location of these headers to the compiler. Be aware that in this case you are on your own regarding the geometry backend and optimizer selection. To keep things simple just define ```LIBNEST2D_BACKEND_CLIPPER``` and ```LIBNEST2D_OPTIMIZER_NLOPT``` before including ```libnest2d.h```. You will also need to link to these libraries manually. - -Please note that the clipper backend still uses some algorithms from ```boost::geometry``` (header only). The boost headers are not downloaded by the build script and later releases will probably get rid of the direct dependency. +1. The project source tree can be used as a subdirectory (or git submodule) in any other CMake based C++ project by using ```add_subdirectory()``` command in the parent level ```CMakeLists.txt``` file. This method ensures that the appropriate dependencies are detected or (optionally) downloaded and built if not found. This means that by default, if Clipper and NLopt are not installed, they will be downloaded into the CMake binary directory, built there and linked statically with your project if RP_ENABLE_DOWNLOAD is ON. Just add the ```target_link_library( libnest2d_headeronly)``` line to your CMake build script. You can also compile the library with the selected dependencies into a static or shared library. To do this just disable the ```LIBNEST2D_HEADER_ONLY``` option in the CMake config. + +2. Copying source files directly into a target project: The library can be header +only and it is enough to just copy the content of the ```include``` directory or specify the location of these headers to the compiler. Be aware that in this case you are on your own regarding the geometry backend and optimizer selection. To keep things simple just define ```LIBNEST2D_GEOMETRIES_clipper``` and ```LIBNEST2D_OPTIMIZER_nlopt``` before including ```libnest2d.hpp```. You will also need to link to these libraries manually. + +3. *(Recommended)* Install the library after it was configured and "built" using cmake. +An example how to do this in a bash command line in the checked out source dir: + ``` bash + mkdir build + cd build + cmake .. -DLIBNEST2D_HEADER_ONLY=OFF -DCMAKE_INSTALL_PREFIX= + cmake --build . --target install + ``` + Substitute `` with your preferred location. If you don't have the + required dependencies installed, you can add `-DRP_ENABLE_DOWNLOAD=ON` and make it download + and build everything in the configure step. The built dependencies will be shared or static depending on `BUILD_SHARED_LIBS`. You can also specify the install location of the dependencies by setting `RP_INSTALL_PREFIX` variable. Alternatively you can (and should) install the dependencies first e.g. on Ubuntu: + ``` + sudo apt install libboost-dev libpolyclipping-dev libnlopt-dev + ``` + +Please note that the clipper backend still uses some algorithms from ```boost::geometry``` (header only). Later releases will probably get rid of the direct dependency. The goal is to provide more geometry backends (e.g. boost only) and optimizer engines (e.g. optimlib) in the future. This would make it possible to use the already available dependencies in your project tree without including new ones. @@ -58,7 +73,7 @@ A simple example may be the best way to demonstrate the usage of the library. #include // Here we include the libnest2d library -#include +#include int main(int argc, const char* argv[]) { using namespace libnest2d;