Skip to content

Commit

Permalink
meshgen11_dealii: update cmake build
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Apr 9, 2024
1 parent cbcbc0b commit b8778d7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 73 deletions.
90 changes: 32 additions & 58 deletions contrib/meshgen11_dealii/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -22,65 +22,39 @@
##
## ---------------------------------------------------------------------

CMAKE_MINIMUM_REQUIRED(VERSION 3.5.0)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
PROJECT(meshgen11_dealii)

IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "DEBUG")
#SET(CMAKE_BUILD_TYPE "RELEASE")
#SET(CMAKE_BUILD_TYPE "RELWITHDEBINFO")
#SET(CMAKE_BUILD_TYPE "MINSIZEREL")
ENDIF()

# set(DEAL_II_DIR "/home/xywei/apps" CACHE STRING "Deal.II dir")
# deal.II >= 8.4.1
FIND_PACKAGE(deal.II REQUIRED
HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR} $ENV{CONDA_PREFIX}
)
cmake_minimum_required(VERSION 3.15.0)
project(meshgen11_dealii LANGUAGES CXX)

DEAL_II_INITIALIZE_CACHED_VARIABLES()
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ version selection")

find_package( PythonInterp 3.8 EXACT )
find_package( PythonLibs 3.8 EXACT )
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

add_subdirectory(pybind11)
pybind11_add_module(meshgen11 meshgen.cpp)
set_target_properties(meshgen11 PROPERTIES PREFIX "")
set_target_properties(meshgen11 PROPERTIES OUTPUT_NAME "meshgen")
# deal.II
find_package(deal.II REQUIRED
HINTS ${DEAL_II_DIR} $ENV{DEAL_II_DIR} $ENV{CONDA_PREFIX})
deal_ii_initialize_cached_variables()

if(FALSE)
# This script does not work on current Debian testing
DEAL_II_SETUP_TARGET(meshgen11)
else()
SET(_build "RELEASE")
STRING(TOLOWER "${CMAKE_BUILD_TYPE}" _cmake_build_type)
IF("${_cmake_build_type}" MATCHES "debug")
SET(_build "DEBUG")
ENDIF()
SET_PROPERTY(TARGET meshgen11 APPEND PROPERTY
INCLUDE_DIRECTORIES "${DEAL_II_INCLUDE_DIRS}"
)
SET_PROPERTY(TARGET meshgen11 APPEND PROPERTY
INCLUDE_DIRECTORIES "/usr/include/"
)
SET_PROPERTY(TARGET meshgen11 APPEND_STRING PROPERTY
COMPILE_FLAGS "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${_build}}"
)
SET_PROPERTY(TARGET meshgen11 APPEND_STRING PROPERTY
LINK_FLAGS " ${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_${_build}} $ENV{DEAL_II_LINKER_FLAGS}"
)
SET_PROPERTY(TARGET meshgen11 APPEND PROPERTY
COMPILE_DEFINITIONS "${DEAL_II_USER_DEFINITIONS};${DEAL_II_USER_DEFINITIONS_${_build}}"
)
GET_PROPERTY(_type TARGET meshgen11 PROPERTY TYPE)
IF(NOT "${_type}" STREQUAL "OBJECT_LIBRARY")
TARGET_LINK_LIBRARIES(meshgen11 PRIVATE ${DEAL_II_TARGET_${_build}})
ENDIF()
# Python
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(pybind11 CONFIG)
if (NOT pybind11_FOUND)
add_subdirectory(pybind11)
endif()

ADD_CUSTOM_COMMAND(TARGET meshgen11 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"meshgen.*.so"
"meshgen.so"
COMMENT "Copied meshgen lib to meshgen.so")
pybind11_add_module(meshgen11 meshgen.cpp)
set_target_properties(meshgen11 PROPERTIES
OUTPUT_NAME "meshgen"
LINK_FLAGS ${DEAL_II_LINKER_FLAGS} ${DEAL_II_LINKER_FLAGS_RELEASE}
COMPILE_DEFINITIONS ${DEAL_II_USER_DEFINITIONS}
INTERPROCEDURAL_OPTIMIZATION ON
VISIBILITY_INLINES_HIDDEN ON)
target_include_directories(meshgen11 PRIVATE ${DEAL_II_INCLUDE_DIRS})
target_link_libraries(meshgen11 PRIVATE ${DEAL_II_TARGET_RELEASE})

add_custom_command(TARGET meshgen11 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"meshgen.*.so"
"meshgen.so"
COMMENT "Copied meshgen lib to meshgen.so")
4 changes: 1 addition & 3 deletions contrib/meshgen11_dealii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ To build `meshgen11`, you need:
## Usage

The script `build.sh` also copies the built library to voluemential path so that you can use

```
```python
import voluemential.meshgen
```

directly.
22 changes: 10 additions & 12 deletions contrib/meshgen11_dealii/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -25,22 +25,20 @@

set -e

mkdir -p build
cd build
cmake ..
make
cd ..
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release
cmake --build build --verbose

echo Module built:
echo ${PWD}/build/meshgen.so
echo 'Module built:'
echo "${PWD}/build/meshgen.so"

outfile=$(realpath ../../volumential/meshgen_dealii.so)
if [ -f build/meshgen.so ]; then
cp build/meshgen.so ../../volumential/meshgen_dealii.so
cp build/meshgen.so "${outfile}"
elif [ -f build/meshgen.dylib ]; then
cp build/meshgen.dylib ../../volumential/meshgen_dealii.so
cp build/meshgen.dylib "${outfile}"
else
echo "Something went wrong. Build failed."
exit 1
fi

echo Library copied to volumential path.
echo "Library copied to '${outfile}'."
1 change: 1 addition & 0 deletions contrib/meshgen11_dealii/meshgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ py::tuple make_uniform_cubic_grid(int q, int level, int dim,
return make_uniform_cubic_grid_details<3>(q, level);
} else {
std::cout << "Dimension must be 1,2 or 3." << std::endl;
return py::tuple();
}
}

Expand Down

0 comments on commit b8778d7

Please sign in to comment.