Skip to content

Commit

Permalink
feat: New CI tooling, local dev setup and stp to glb parser (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krande authored Jan 24, 2024
1 parent 704fcf8 commit a2df512
Show file tree
Hide file tree
Showing 70 changed files with 1,949 additions and 209 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build/
.idea/
cmake-build*/
.env
.env
.env.json
temp/
180 changes: 80 additions & 100 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,92 @@ cmake_minimum_required(VERSION 3.20)
project(ada-cpp LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)

if (APPLE)
set(CMAKE_OSX_SYSROOT "/Users/runner/work/adacpp/MacOSX10.15.sdk" CACHE PATH "macOS SDK path" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "macOS deployment target" FORCE)

if (DEFINED CMAKE_OSX_SYSROOT)
message(STATUS "Setting macOS sysroot to ${CMAKE_OSX_SYSROOT}")
else ()
message(FATAL_ERROR "CMAKE_OSX_SYSROOT is not defined. Please set it to the path of the macOS SDK you want to use.")
endif ()

if (DEFINED CMAKE_OSX_DEPLOYMENT_TARGET)
message(STATUS "Setting macOS deployment target to ${CMAKE_OSX_DEPLOYMENT_TARGET}")
else ()
message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET is not defined. Please set it to the minimum macOS version you want to support.")
endif ()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
else ()
message(STATUS "Not building for macOS")
endif ()

OPTION(CONDA_LOCAL_DEV "Install into activate local development conda env." OFF)

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "Building for x64 architecture")
else ()
message(FATAL_ERROR "This project requires a 64-bit toolchain. Please update your toolchain arch to 'x86_amd64'")
if (CONDA_LOCAL_DEV)
message(STATUS "Building for local development conda env.")
set(EXE_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
endif ()

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type not set, defaulting to Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif ()
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
include(cmake/pre_checks.cmake)

find_package(Python 3 COMPONENTS Interpreter Development.Module REQUIRED)
find_package(Python 3
REQUIRED COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule)

# Create a list called ADA_CPP_SOURCES of all cpp files inside the src dir
set(ADA_CPP_SOURCES
src/adacpp.cpp
src/cadit/ifc/ifcop.cpp
src/helpers/helpers.cpp
src/models/Models.cpp
src/exchange/step_writer.cpp
src/exchange/gltf_writer.cpp
src/geom/ShapeTesselator.cpp
src/geom/tess_helpers.cpp
src/tessellation/solids/boxes.cpp
)

# Find CGAL
find_package(CGAL REQUIRED)

if (CGAL_FOUND)
message(STATUS "CGAL version found: " ${CGAL_VERSION})
message(STATUS "CGAL include directory: " ${CGAL_INCLUDE_DIRS})
message(STATUS "CGAL binary directory: " ${CGAL_DIR})
message(STATUS "CGAL library directory: " ${CGAL_LIBRARY_DIRS})

include_directories(${CGAL_INCLUDE_DIRS})
link_directories(${CGAL_LIBRARY_DIRS})
endif (CGAL_FOUND)


# Find OpenCASCADE
find_package(OpenCASCADE REQUIRED)
if (OpenCASCADE_FOUND)
message(STATUS "OpenCASCADE version found: " ${OpenCASCADE_MAJOR_VERSION} ".." ${OpenCASCADE_MINOR_VERSION} ".." ${OpenCASCADE_MAINTENANCE_VERSION})
message(STATUS "OpenCASCADE include directory: " ${OpenCASCADE_INCLUDE_DIR})
message(STATUS "OpenCASCADE binary directory: " ${OpenCASCADE_BINARY_DIR})
message(STATUS "OpenCASCADE library directory: " ${OpenCASCADE_LIBRARY_DIR})

include_directories(${OpenCASCADE_INCLUDE_DIR})
link_directories(${OpenCASCADE_LIBRARY_DIR})
endif (OpenCASCADE_FOUND)


# Detect the installed nanobind package and import it into CMake
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR)

message(STATUS "NanoBind Cmake directory: " ${NB_DIR})
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")

# Import nanobind through CMake's find_package mechanism
find_package(nanobind CONFIG REQUIRED)

# Print the list of cpp files separated by spaces without altering it
string(REPLACE ";" " " ADA_CPP_SOURCES_STR "${ADA_CPP_SOURCES}")
message(STATUS "AdaCpp sources: " ${ADA_CPP_SOURCES_STR})

# Create a Python module
nanobind_add_module(_ada_cpp_ext_impl ${ADA_CPP_SOURCES})

target_link_libraries(_ada_cpp_ext_impl
PRIVATE
TKernel
TKMath
TKBRep
TKPrim
TKTopAlgo
TKSTEP
TKXDESTEP
TKRWMesh
)

# Link the module to OpenCASCADE
install(TARGETS _ada_cpp_ext_impl LIBRARY DESTINATION .)
src/geom/Models.cpp
src/geom/geometries.cpp
src/cadit/occt/step_to_glb.cpp
src/cadit/occt/occt_convert.cpp
src/cadit/occt/step_writer.cpp
src/cadit/occt/gltf_writer.cpp
src/cadit/occt/colors.cpp
src/cadit/tinygltf/tiny.cpp
src/fem/simple_mesh.cpp
src/visit/ShapeTesselator.cpp
src/visit/tess_helpers.cpp
src/visit/manual/solids/boxes.cpp
src/visit/TessellateFactory.cpp
)
set(ADA_CPP_HEADERS
src/cadit/ifc/ifcop.h
src/helpers/helpers.h
src/geom/geometries.h
src/cadit/occt/occt_convert.h
src/cadit/occt/step_to_glb.h
src/cadit/occt/step_writer.h
src/cadit/occt/gltf_writer.h
src/cadit/occt/colors.h
src/cadit/tinygltf/tiny.h
src/cadit/tinygltf/tinyload.h
src/fem/simple_mesh.h
src/visit/ShapeTesselator.h
src/visit/tess_helpers.h
src/visit/TessellateFactory.h
)
# Create a empty list to hold all the linked libs
set(ADA_CPP_LINK_LIBS)

# Add dependencies
include(cmake/deps_cgal.cmake)
include(cmake/deps_occ.cmake)
include(cmake/deps_gmsh.cmake)
include(cmake/deps_ifc.cmake)

# Add Nanobind
include(cmake/nanobind.cmake)

# Link libraries to the module
target_link_libraries(_ada_cpp_ext_impl PRIVATE ${ADA_CPP_LINK_LIBS})

# Install the module
install(TARGETS _ada_cpp_ext_impl LIBRARY DESTINATION .)

# Install the C++ executable
set(SOURCES src/main.cpp src/cadit/occt/step_to_glb.cpp)
set(HEADERS src/cadit/occt/step_to_glb.h)

add_executable(STP2GLB ${SOURCES} ${HEADERS})

set_target_properties(STP2GLB PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/bin")

target_link_libraries(STP2GLB ${ADA_CPP_LINK_LIBS})

# install to executable into the bin dir
message(STATUS "Installing executable to ${EXE_BIN_DIR}")
install(TARGETS STP2GLB DESTINATION ${EXE_BIN_DIR})

# Include the tests directory
OPTION(BUILD_TESTING "Build the testing tree." OFF)
if (BUILD_TESTING)
message(STATUS "Building the testing tree.")
set(CMAKE_INSTALL_RPATH "${EXE_BIN_DIR}")
set(CMAKE_BUILD_RPATH "${EXE_BIN_DIR}")
include(tests/cpp/tests.cmake)
endif (BUILD_TESTING)
30 changes: 30 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": 6,
"include": [
".env.json"
],
"configurePresets": [
{
"name": "win-local",
"inherits": ["env-vars"],
"generator": "Ninja",
"hidden": false,
"environment": {
"LIBRARY_PREFIX": "$env{PREFIX}/Library"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelwithDebInfo",
"CMAKE_PREFIX_PATH": "$env{LIBRARY_PREFIX};$env{LIBRARY_PREFIX}/include;$env{LIBRARY_PREFIX}/lib;$env{LIBRARY_PREFIX}/bin",
"CMAKE_INSTALL_PREFIX": "$env{LIBRARY_PREFIX}",
"CGAL_DIR": "$env{LIBRARY_PREFIX}/lib/cmake/CGAL",
"OpenCASCADE_DIR": "$env{LIBRARY_PREFIX}/lib/cmake/opencascade",
"OpenCASCADE_INCLUDE_DIR": "$env{LIBRARY_PREFIX}/include/opencascade",
"Python_EXECUTABLE": "$env{PREFIX}/python.exe",
"Python_LIBRARIES": "$env{PREFIX}/libs/python311.lib",
"Python_INCLUDE_DIRS": "$env{LIBRARY_PREFIX}/include",
"BUILD_TESTING": "ON",
"CONDA_LOCAL_DEV": "ON"
}
}
]
}
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
A drop-in replacement library for adapy created to improve performance using c++.
The compilation and binding methods are based on the [nanobind-minimal repo](https://github.com/Krande/nanobind-minimal)

## Performance metrics
Todo

## Installation

Expand All @@ -17,7 +15,7 @@ mamba env update -f environment.build.yml --prune
Activate the environment and install the package in editable mode.

```bash
pip install --no-build-isolation .
pip install --no-build-isolation -e .
```

### Conda Build install
Expand All @@ -29,4 +27,28 @@ mamba mambabuild . -c conda-forge --python 3.11 --override-channels
mamba install --use-local ada-cpp
```

### Local IDE development

You can use the presets in the CMakePresets.json file.
But first you must create a `.env.json` file (which will be ignored by git) where you point to
the conda env `environment.build.yml`. The .env.json file should look like this,
where you fill in the path to your conda env as the "PREFIX" value.

```json
{
"version": 6,
"configurePresets": [
{
"name": "env-vars",
"hidden": true,
"environment": {
"PREFIX": "C:/miniforge3/envs/ada-cpp"
}
}
]
}
```


## Performance metrics
Todo
12 changes: 12 additions & 0 deletions cmake/deps_cgal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Find CGAL
find_package(CGAL REQUIRED)

if (CGAL_FOUND)
message(STATUS "CGAL version found: " ${CGAL_VERSION})
message(STATUS "CGAL include directory: " ${CGAL_INCLUDE_DIRS})
message(STATUS "CGAL binary directory: " ${CGAL_DIR})
message(STATUS "CGAL library directory: " ${CGAL_LIBRARY_DIRS})

include_directories(${CGAL_INCLUDE_DIRS})
link_directories(${CGAL_LIBRARY_DIRS})
endif (CGAL_FOUND)
15 changes: 15 additions & 0 deletions cmake/deps_gmsh.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
find_library(GMSH_LIB gmsh)
if(NOT GMSH_LIB)
message(FATAL_ERROR "Could not find libgmsh")
endif()

find_path(GMSH_INC gmsh.h)
if(NOT GMSH_INC)
message(FATAL_ERROR "Could not find gmsh.h")
endif()

include_directories(${GMSH_INC})

list(APPEND
ADA_CPP_LINK_LIBS
gmsh)
8 changes: 8 additions & 0 deletions cmake/deps_ifc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# link the library files located in %LIBRARY_PREFIX%/lib/ifcparse/IfcParse.lib (on windows as an example)
# to the executable

list(APPEND
ADA_CPP_LINK_LIBS
IfcParse
IfcGeom
)
24 changes: 24 additions & 0 deletions cmake/deps_occ.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Find OpenCASCADE
find_package(OpenCASCADE REQUIRED)
if (OpenCASCADE_FOUND)
message(STATUS "OpenCASCADE version found: " ${OpenCASCADE_MAJOR_VERSION} ".." ${OpenCASCADE_MINOR_VERSION} ".." ${OpenCASCADE_MAINTENANCE_VERSION})
message(STATUS "OpenCASCADE include directory: " ${OpenCASCADE_INCLUDE_DIR})
message(STATUS "OpenCASCADE binary directory: " ${OpenCASCADE_BINARY_DIR})
message(STATUS "OpenCASCADE library directory: " ${OpenCASCADE_LIBRARY_DIR})

include_directories(${OpenCASCADE_INCLUDE_DIR})
link_directories(${OpenCASCADE_LIBRARY_DIR})

list(APPEND
ADA_CPP_LINK_LIBS
TKernel
TKMath
TKBRep
TKPrim
TKTopAlgo
TKSTEP
TKXDESTEP
TKLCAF
TKXCAF
TKRWMesh)
endif (OpenCASCADE_FOUND)
17 changes: 17 additions & 0 deletions cmake/nanobind.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Detect the installed nanobind package and import it into CMake
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR)

message(STATUS "NanoBind Cmake directory: " ${NB_DIR})
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")

# Import nanobind through CMake's find_package mechanism
find_package(nanobind CONFIG REQUIRED)

# Print the list of cpp files separated by spaces without altering it
string(REPLACE ";" " " ADA_CPP_SOURCES_STR "${ADA_CPP_SOURCES}")
message(STATUS "AdaCpp sources: " ${ADA_CPP_SOURCES_STR})

# Create a Python module
nanobind_add_module(_ada_cpp_ext_impl STABLE_ABI ${ADA_CPP_SOURCES})
Loading

0 comments on commit a2df512

Please sign in to comment.