c++cmakecgalconan

Installing CGAL using conan.io


I would like to install CGAL using conan.io

Here is my conan file

conanfile.txt

[requires]
cgal/5.6.1
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout

CMakeLists.txt

cmake_minimum_required(VERSION 3.29)
project(example)

find_package(CGAL REQUIRED)

add_executable(${PROJECT_NAME} src/hull.cpp)
target_link_libraries(${PROJECT_NAME} CGAL::CGAL )

A small example program taken from here:

src/hull.cpp

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/partition_2.h>
#include <CGAL/Partition_traits_2.h>
#include <CGAL/property_map.h>
#include <vector>
#include <cassert>
#include <list>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Partition_traits_2<K, CGAL::Pointer_property_map<K::Point_2>::type > Partition_traits_2;
typedef Partition_traits_2::Point_2                         Point_2;
typedef Partition_traits_2::Polygon_2                       Polygon_2;  // a polygon of indices
typedef std::list<Polygon_2>                                Polygon_list;
/*
      v4     v2
      | \   /|
      |  \ / |
      |  v3  |
      |      |
      v0-----v1
 */
int main( )
{
  std::vector<K::Point_2> points = { K::Point_2(0,0), K::Point_2(2,0), K::Point_2(2,2), K::Point_2(1,1), K::Point_2(0,2) };
  Partition_traits_2 traits(CGAL::make_property_map(points));
  Polygon_2 polygon;
  polygon.push_back(0);
  polygon.push_back(1);
  polygon.push_back(2);
  polygon.push_back(3);
  polygon.push_back(4);
  Polygon_list partition_polys;
  CGAL::y_monotone_partition_2(polygon.vertices_begin(),
                               polygon.vertices_end(),
                               std::back_inserter(partition_polys),
                               traits);
   for (const Polygon_2& poly : partition_polys){
     for(Point_2 p : poly.container()){
        std::cout << "points[" << p << "] =  " << points[p] << ", ";
      }
     std::cout << std::endl;
   }
   assert(CGAL::partition_is_valid_2(polygon.vertices_begin(),
                                     polygon.vertices_end(),
                                     partition_polys.begin(),
                                     partition_polys.end(),
                                     traits));
   return 0;
}

Attempting to build it all from the command line:

conan install . --output-folder=build --build=missing

Here is the error I get:

Error Message

Error Message


Solution

  • Here's what I've come up with using docker

    Dockerfile

    FROM ubuntu:22.04 AS base
    
    RUN apt-get update
    RUN apt-get upgrade -y
    RUN apt-get install python3-venv python3-pip cmake -y
    RUN python3 -m venv /venv
    RUN chmod -R 777 /venv
    ENV PATH="/venv/bin:$PATH"
    
    RUN pip install conan && conan profile detect
    RUN mkdir /app
    

    docker-compose.yml

    version: '3.9'
    services:
      cgal:
        build: .
        volumes:
          - .:/app
        command: >
          sh -c "./venv/bin/activate && 
          conan install /app --output-folder=/app/build --build=missing && 
          cd /app/build/build/Release/generators/ &&
          cmake /app -DCMAKE_TOOLCHAIN_FILE="/app/build/build/Release/generators/conan_toolchain.cmake" -DCMAKE_BUILD_TYPE="Release" &&
          cmake --build . --config Release &&
          /app/build/build/Release/generators/example"
          
          
    

    Run using docker compose up

    And it builds and runs working