Skip to content

Commit

Permalink
package the library
Browse files Browse the repository at this point in the history
create libyams split the header-only library from the binary targets
add a python package structure to install pyams
make the CLI, C++ tests and python bindings rely on libyams
update the conda recipe
add cmake config files for downstream packages
add README for build instructions
add missing deps in env-dev yaml file
use pre-installed libyams if lib is not built
  • Loading branch information
adriendelsalle committed Jul 4, 2022
1 parent 2be9e73 commit 2eb3349
Show file tree
Hide file tree
Showing 43 changed files with 563 additions and 254 deletions.
49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,52 @@ build/
/doc/*.log
/doc/*.fls
__pycache__

pyams.egg-info/
*.orig

CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll
*.pyd

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
112 changes: 17 additions & 95 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,123 +1,45 @@
cmake_minimum_required(VERSION 3.17.0)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
project(yams)

project(gbs LANGUAGES CXX)

#
# c++ conf
#
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# #
# Build options
option(BUILD_LIB "Enable the build of header-only library" ON)
option(BUILD_CLI "Enable the build of the CLI" OFF)
option(BUILD_TESTS "Enable the build of the C++ tests" OFF)
option(BUILD_PYTHON_BINDINGS "Enable the build of Python bindings" OFF)

# Set installation directories
include(GNUInstallDirs)

message("-- CMake install prefix: " ${CMAKE_INSTALL_PREFIX})
message(" -> binaries: " ${CMAKE_INSTALL_BINDIR})
message(" -> libs: " ${CMAKE_INSTALL_LIBDIR})
message(" -> includes: " ${CMAKE_INSTALL_INCLUDEDIR})
#
# set output dirs (vs is a pain)
#
function(SET_OUT_DIR REQUIRED_ARG)
list(GET ARGV 0 TARGET_NAME)
list(GET ARGV 1 OUT_DIR)
message(${TARGET_NAME})
message(${OUT_DIR})
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set_property(TARGET ${TARGET_NAME} PROPERTY RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUT_DIR} )
set_property(TARGET ${TARGET_NAME} PROPERTY LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUT_DIR} )
set_property(TARGET ${TARGET_NAME} PROPERTY ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUT_DIR} )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
endfunction()

set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE
STRING "install path for libyamsConfig.cmake")

# Paths
# TODO: remove this after GBS refactoring
file(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} lib_dir)
file(TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR} bin_dir)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/gbs)
link_directories(${lib_dir})
link_directories(${bin_dir})


# Eigen
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
include_directories(${EIGEN3_INCLUDE_DIR})
# libIGES
include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/iges/)
#
# xtensors
#
set(XTENSOR_USE_XSIMD BOOL:ON)
find_package(xtl REQUIRED)
find_package(xtensor REQUIRED)
find_package(xsimd REQUIRED)
add_definitions(-DXTENSOR_USE_XSIMD)
#
# VTK
#
find_package(
VTK REQUIRED
COMPONENTS
CommonCore
CommonColor
CommonDataModel
FiltersSources
InteractionStyle
RenderingCore
RenderingAnnotation
RenderingFreeType
IOXML
ChartsCore
InteractionStyle
RenderingContext2D
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
ViewsContext2D
RenderingOpenGL2
Python
WrappingPythonCore
)
# NLopt
find_package(NLopt REQUIRED)

if(LINUX)
# add_definitions(-D__TBB_show_deprecation_message_task_H))
find_package(TBB REQUIRED)
if (${BUILD_LIB})
add_subdirectory(libyams)
endif()

if(${BUILD_TESTS})
add_subdirectory(tests)
endif()

if(${BUILD_PYTHON_BINDING})
if(${BUILD_PYTHON_BINDINGS})
add_subdirectory(python)
endif()

add_executable(
yams MACOSX_BUNDLE
yams.cpp
)
target_link_libraries(
yams
NLopt::nlopt
${VTK_LIBRARIES}
xtensor
xtensor::optimize
xtensor::use_xsimd
gbs-render
iges
TBB::tbb
)

vtk_module_autoinit(
TARGETS yams
MODULES ${VTK_LIBRARIES}
)
install(TARGETS yams)
if(${BUILD_CLI})
add_subdirectory(yams-cli)
endif()
116 changes: 116 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# YAMS

## Build instructions

### Clone the repo

Start by cloning the repo:

```bash
$ git clone https://github.com/ssg-aero/yams.git
```

Then move to the newly created directory:

```bash
$ cd yams
```

### Install dev requirements

Make sure you have `yams`'s development requirements installed in your environment.
To do so, you can create a new ``conda`` env using ``mamba`` or ``micromamba``:

```bash
$ micromamba create -f environment-dev.yml
```

### Build the projects

Note:
All ``cmake`` commands listed below use ``bash`` multi-line syntax.
On Windows, replace ``\`` trailing character with ``^``.

Note:
Feel free to use your favorite generator: ``make``, ``ninja``, etc.

Note:
Installation prefix on Unix (linux and MacOS) is set to your `conda` env using
the `CMAKE_INSTALL_PREFIX` CMake option to the `CONDA_PREFIX` env variable. On Windows,
it has to be set to `CONDA_PREFIX/Library`.


#### ``libyams`` library

`libyams` is a header-only library, so it has no translation unit to compile and the
library CMake definition is used:
- to install headers in the correct directory
- to forward include directories and link libraries to downstream projects

```bash
$ mkdir -p build
$ cd build
$ cmake .. \
$ -DBUILD_LIB=ON \
$ -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
$ ninja
```

Note:
This target is built by default

#### C++ Tests

Build C++ tests by activating the `BUILD_TESTS` CMake option:

```bash
$ mkdir -p build
$ cd build
$ cmake .. \
$ -G"Ninja" \
$ -DBUILD_TESTS=ON \
$ -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
$ ninja
```

#### Python bindings

To build the Python bindings and make it possible to use `yams` from Python code, just
active the `BUILD_PYTHON_BINDINGS` CMake option:

```bash
$ mkdir -p build
$ cd build
$ cmake .. \
$ -G"Ninja" \
$ -DBUILD_PYTHON_BINDINGS=ON \
$ -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
$ ninja install
```
CMake will install the shared library in the Python package source directory.
It can be then installed using `pip`:

```bash
$ pip install ./python
```

or in editable mode:

```bash
$ pip install -e ./python
```

#### CLI interface

`yams` as a simple CLI interface one can use to run a simulation.
To build it, just active the `BUILD_CLI` CMake option in the `cmake` command.

```bash
$ mkdir -p build
$ cd build
$ cmake .. \
$ -G"Ninja" \
$ -BUILD_CLI=ON \
$ -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
$ ninja install
```
3 changes: 3 additions & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ dependencies:
- python=3.9
- pybind11
- pytest
- gtest
- gmock
- nlopt
- sel(win): vs2019_win-64
Loading

0 comments on commit 2eb3349

Please sign in to comment.