Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.15)
project(poly2tri LANGUAGES CXX)

include(GNUInstallDirs)

add_library(poly2tri
${POLY2TRI_SRC_DIR}/common/shapes.cc
${POLY2TRI_SRC_DIR}/sweep/advancing_front.cc
${POLY2TRI_SRC_DIR}/sweep/cdt.cc
${POLY2TRI_SRC_DIR}/sweep/sweep.cc
${POLY2TRI_SRC_DIR}/sweep/sweep_context.cc
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify the source/header paths against upstream's layout. At this pinned commit, greenm01/poly2tri keeps all sources and headers under a top-level poly2tri/ subdirectory (poly2tri/common/shapes.cc, poly2tri/sweep/cdt.cc, poly2tri/poly2tri.h, ...). POLY2TRI_SRC_DIR is set to ctx.SourceDir (the checkout root) in the formula, so ${POLY2TRI_SRC_DIR}/common/shapes.cc resolves to <root>/common/shapes.cc, which doesn't exist — the paths look like they're missing the poly2tri/ prefix (e.g. ${POLY2TRI_SRC_DIR}/poly2tri/common/shapes.cc).

Same concern for the header install below: install(DIRECTORY ${POLY2TRI_SRC_DIR} ...) (no trailing slash) installs the checkout-root directory itself under include/, producing something like include/<checkout-name>/poly2tri/poly2tri.h, whereas the consumer test does #include <poly2tri/poly2tri.h> with only -Iinclude. Please confirm onTest actually passes; if it does, ctx.SourceDir must already point at the poly2tri/ subdir — otherwise both the source list and the include layout need the poly2tri/ prefix.


target_compile_definitions(poly2tri PRIVATE _USE_MATH_DEFINES)

if(MSVC AND BUILD_SHARED_LIBS)
set_property(TARGET poly2tri PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

install(
TARGETS poly2tri
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(
DIRECTORY ${POLY2TRI_SRC_DIR}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import (
"os"
"path/filepath"
"slices"
)

const consumerSource = `#include <poly2tri/poly2tri.h>

int main() {
p2t::Point p1(0.0, 0.0);
p2t::Point p2(1.0, 0.0);
p2t::Point p3(0.0, 1.0);
p2t::Triangle triangle(p1, p2, p3);
return 0;
}
`

// Conan Center cci.20130502 pins greenm01/poly2tri to this untagged commit.
id "greenm01/poly2tri"

fromVer "88de49021b6d9bef6faa1bc94ceb3fbd85c3c204"

defaults {
"shared": "OFF",
"fPIC": "ON",
}

filter => {
for name, values in target.options {
if name != "shared" && name != "fPIC" {
return false
}
for value in values {
if value != "ON" && value != "OFF" {
return false
}
}
}
return true
}

onBuild ctx => {
installDir := ctx.outputDir

cmakeLists := ctx.Proj.readFile("88de49021b6d9bef6faa1bc94ceb3fbd85c3c204/CMakeLists.txt")!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the commit SHA 88de49... is hardcoded in this readFile path and also in fromVer (line 22) / the directory name. If the pin ever changes, this path must be updated in lockstep. Consider deriving it from the version to avoid drift.

os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cmakeLists, 0o644)!

shared := slices.contains(target.options["shared"], "ON")
fPIC := slices.contains(target.options["fPIC"], "ON")
c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir)
c.define "POLY2TRI_SRC_DIR", filepath.join(ctx.SourceDir, "poly2tri")
c.define "CMAKE_INSTALL_LIBDIR", "lib"
c.defineBool "BUILD_SHARED_LIBS", shared
c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC
c.configure
c.build

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake Build doesn't add --parallel/-j by default (confirmed in llar's x/cmake), and no generator is set so it falls back to Make. The 5 independent translation units compile serially. Consider c.build "--parallel" for a faster build on multi-core runners.

c.install

licenseDir := filepath.join(installDir, "licenses")
os.mkdirAll(licenseDir, 0o755)!
os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0o644)!

pcDir := filepath.join(installDir, "lib", "pkgconfig")
os.mkdirAll(pcDir, 0o755)!
pc := `prefix=$${pcfiledir}/../..
exec_prefix=$${prefix}
libdir=$${prefix}/lib
includedir=$${prefix}/include

Name: poly2tri
Description: 2D constrained Delaunay triangulation library
Version: 88de49021b6d9bef6faa1bc94ceb3fbd85c3c204
Libs: -L$${libdir} -lpoly2tri`
if slices.contains(target.require["os"], "linux") || slices.contains(target.require["os"], "freebsd") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the -lm gating (slices.contains(target.require["os"], "linux") || ... "freebsd") and the base link flags are duplicated almost verbatim in onTest (lines 92-94). Extracting a small helper would keep the two paths in sync if the flag set changes.

pc += " -lm"
}
pc += `
Cflags: -I$${includedir}
`
os.writeFile(filepath.join(pcDir, "poly2tri.pc"), []byte(pc), 0o644)!

pkgconfig.use installDir
ctx.setMetadata pkgconfig.lookup("poly2tri")!
}

onTest ctx => {
installDir := ctx.outputDir
testDir := filepath.join(ctx.SourceDir, "_llar_consumer")
testBuild := filepath.join(testDir, "_build")
sourcePath := filepath.join(testDir, "consumer.cpp")
binary := filepath.join(testBuild, "consumer")
os.mkdirAll(testDir, 0o755)!
os.mkdirAll(testBuild, 0o755)!
os.writeFile(sourcePath, []byte(consumerSource), 0o644)!

pkgconfig.use installDir
args := []string{"-std=c++11", sourcePath}
// pkg-config escapes the `|` in LLAR option-cache paths; restore it before
// passing each complete lookup token to the compiler.
flags := pkgconfig.lookup("poly2tri")!
args <- flags.replaceAll(`\|`, `|`).fields...
args <- "-o", binary
exec! "c++", args...

if slices.contains(target.options["shared"], "ON") {
os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))!
os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))!
}
exec! binary
}
4 changes: 4 additions & 0 deletions greenm01/poly2tri/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "greenm01/poly2tri",
"deps": {}
}
Loading