Skip to content

Commit

Permalink
Updated Readme.md, re-add LIBNEST2D_HEADER_ONLY
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasmeszaros committed Oct 24, 2019
1 parent cc69680 commit 85d66c7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -86,15 +88,21 @@ target_include_directories(libnest2d_headeronly INTERFACE $<BUILD_INTERFACE:${SR

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

set(LIBNAME libnest2d_${LIBNEST2D_GEOMETRIES}_${LIBNEST2D_OPTIMIZER})
add_library(${LIBNAME} ${PROJECT_SOURCE_DIR}/src/libnest2d.cpp)
set_target_properties(${LIBNAME} PROPERTIES PREFIX "")
set_target_properties(${LIBNAME} PROPERTIES DEBUG_POSTFIX "d")
target_link_libraries(${LIBNAME} PUBLIC libnest2d_headeronly)
target_compile_definitions(${LIBNAME} PUBLIC LIBNEST2D_STATIC)
target_sources(${LIBNAME} PRIVATE ${LIBNEST2D_SRCFILES})
add_library(libnest2d INTERFACE)
target_link_libraries(libnest2d INTERFACE ${LIBNAME})

if(NOT LIBNEST2D_HEADER_ONLY)
set(LIBNAME libnest2d_${LIBNEST2D_GEOMETRIES}_${LIBNEST2D_OPTIMIZER})
add_library(${LIBNAME} ${PROJECT_SOURCE_DIR}/src/libnest2d.cpp)
set_target_properties(${LIBNAME} PROPERTIES PREFIX "")
set_target_properties(${LIBNAME} PROPERTIES DEBUG_POSTFIX "d")
target_link_libraries(${LIBNAME} PUBLIC libnest2d_headeronly)
target_compile_definitions(${LIBNAME} PUBLIC LIBNEST2D_STATIC)
target_sources(${LIBNAME} PRIVATE ${LIBNEST2D_SRCFILES})

target_link_libraries(libnest2d INTERFACE ${LIBNAME})
else()
target_link_libraries(libnest2d INTERFACE libnest2d_headeronly)
endif()

if(LIBNEST2D_BUILD_EXAMPLES)
add_subdirectory(${PROJECT_SOURCE_DIR}/examples)
Expand Down
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,27 @@ Using libnest2d in its current state implies the following dependencies:

Integrating the library can be done in at least two ways. Use whichever suits your project the most.

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 downloaded and built automatically 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 (except for boost geometry). Just add the ```target_link_library(<your_target> 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(<your_target> 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=<installdir>
cmake --build . --target install
```
Substitute `<installdir>` 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.

Expand All @@ -58,7 +73,7 @@ A simple example may be the best way to demonstrate the usage of the library.
#include <string>

// Here we include the libnest2d library
#include <libnest2d.h>
#include <libnest2d/libnest2d.hpp>

int main(int argc, const char* argv[]) {
using namespace libnest2d;
Expand Down

0 comments on commit 85d66c7

Please sign in to comment.