Skip to content

Commit

Permalink
some improvements for wheel build target
Browse files Browse the repository at this point in the history
  • Loading branch information
carsten-forty2 committed Mar 9, 2024
1 parent 5e71238 commit 0cfa3b0
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 92 deletions.
54 changes: 30 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/core/cmake")
include(GIMLImacros)

add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})

add_custom_target(pygimli)

if (NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -236,7 +236,7 @@ if (OS_VAR STREQUAL "almalinux")
find_package(Python ${PYVERSION} COMPONENTS NumPy REQUIRED)
else()
find_package(Python ${PYVERSION} EXACT COMPONENTS Interpreter REQUIRED)
find_package(Python ${PYVERSION} EXACT COMPONENTS Development.Module REQUIRED)
find_package(Python ${PYVERSION} EXACT COMPONENTS Development REQUIRED)
find_package(Python ${PYVERSION} EXACT COMPONENTS NumPy REQUIRED)
endif()

Expand All @@ -252,7 +252,12 @@ message(STATUS "Python_SITELIB: ${Python_SITELIB}")
message(STATUS "Python_SITEARCH: ${Python_SITEARCH}")
message(STATUS "Python_SOABI: ${Python_SOABI}")
message(STATUS "Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}")
message(STATUS "Python_Development_FOUND: ${Python_Development_FOUND}")
message(STATUS "Python_Development.Embed_FOUND: ${Python_Development.Embed_FOUND}")
message(STATUS "Python_Development.Embed: $<TARGET_FILE:Python::Python>")
message(STATUS "Python_Development.Module_FOUND: ${Python_Development.Module_FOUND}")
message(STATUS "Python_Development.Module: $<TARGET_FILE:Python::Module>")
message(STATUS "Python_LIBRARIES: ${Python_LIBRARIES}")
message(STATUS "Python_LINK_OPTIONS: ${Python_LINK_OPTIONS}")
message(STATUS "Python_VERSION: ${Python_VERSION}")
message(STATUS "Python_NumPy: ${Python_NumPy_FOUND}, ${Python_NumPy_INCLUDE_DIRS}, ${Python_NumPy_VERSION}")
Expand Down Expand Up @@ -668,6 +673,12 @@ if (SPHINX_FOUND AND NOT SKIP_SPHINX)
COMMAND ${SPHINX_EXECUTABLE} --version
OUTPUT_VARIABLE SPHINX_VERSION
)

add_custom_target(removedoc
COMMAND
${CMAKE_MAKE_PROGRAM} clean -f ${CMAKE_CURRENT_BINARY_DIR}/doc/
)

endif()

message(STATUS "**********************************************************************")
Expand Down Expand Up @@ -725,24 +736,6 @@ configure_file("${PROJECT_SOURCE_DIR}/core/config.cmake.h.in"
"${PROJECT_BINARY_DIR}/config.cmake.h" )
add_definitions(-DHAVE_CONFIG_CMAKE_H)

add_custom_target(removedoc
COMMAND
${CMAKE_MAKE_PROGRAM} clean -f ${CMAKE_CURRENT_BINARY_DIR}/doc/
)
add_custom_target(checkall
DEPENDS
doc
#linkcheck
)
#add_dependencies(doc removedoc)

# Add if pytest found?
add_dependencies(checkall pgtest)
if (CPPUNIT_FOUND)
add_dependencies(checkall gtest)
endif (CPPUNIT_FOUND)


################################################################################
# Define the configurable options
################################################################################
Expand Down Expand Up @@ -820,16 +813,29 @@ message(STATUS "Found python executable for building: ${Python_EXECUTABLE}")
message(STATUS "Found python executable for testing (venv): ${Python3_EXECUTABLE}")

################################################################################
# descend into subdirs
# define test and checks
################################################################################
# if (LIBGIMLI_BUILD_TESTS)
# enable_testing()
# endif(LIBGIMLI_BUILD_TESTS)


if (LIBGIMLI_BUILD_TESTS)
enable_testing()
endif(LIBGIMLI_BUILD_TESTS)


################################################################################
# descend into subdirs
################################################################################
add_subdirectory(core/src)
add_subdirectory(core/tests EXCLUDE_FROM_ALL)

add_subdirectory(core/python EXCLUDE_FROM_ALL)
add_subdirectory(core/pgcore)
add_subdirectory(pygimli)

add_custom_target(check)
if (CPPUNIT_FOUND)
add_dependencies(check gtest)
endif (CPPUNIT_FOUND)
add_dependencies(check pgtest)

add_custom_target(checkall DEPENDS doc)
2 changes: 1 addition & 1 deletion core/cmake/GIMLImacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ macro(add_python_module PYTHON_MODULE_NAME SOURCE_DIR EXTRA_LIBS OUTDIR)

#TODO check!! (python3-config --extension-suffix)


if (APPLE)
# set(GIMLI_LIBRARY "${CMAKE_BINARY_DIR}/${LIBRARY_INSTALL_DIR}/libgimli.dylib")
target_link_libraries(${PYTHON_TARGET_NAME} "-bundle -undefined dynamic_lookup")
Expand Down Expand Up @@ -98,6 +97,7 @@ macro(add_python_module PYTHON_MODULE_NAME SOURCE_DIR EXTRA_LIBS OUTDIR)
endif()
endif()


#--copy pattern files to build folder--
## needed?
# set(PYTHON_IN_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
Expand Down
5 changes: 3 additions & 2 deletions core/pgcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ else()
add_custom_target(whl${TARGET_NAME}PackageBuild DEPENDS whl${TARGET_NAME}CopyLibs
COMMAND "${Python_EXECUTABLE}" -m pip wheel --wheel-dir=${CMAKE_BINARY_DIR}/wheelhouse .
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Building python wheel package"
COMMENT "Building python wheel package for ${TARGET_NAME}"
)
if (OS_VAR STREQUAL "almalinux")
add_custom_target(whl${TARGET_NAME}PackageRepair DEPENDS whl${TARGET_NAME}PackageBuild
Expand All @@ -85,12 +85,13 @@ else()
add_custom_target(whl${TARGET_NAME}TestInstall DEPENDS whl${TARGET_NAME}
COMMAND "${Python3_EXECUTABLE}" -m pip uninstall -y ${TARGET_NAME}
COMMAND "${Python3_EXECUTABLE}" -m pip install ${TARGET_NAME} --find-links=${CMAKE_BINARY_DIR}/wheelhouse
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Installing ${TARGET_NAME} in virtual test environment"
)
add_custom_target(whl${TARGET_NAME}TestRun DEPENDS whl${TARGET_NAME}TestInstall
COMMAND ${Python3_EXECUTABLE} -c "import pgcore; print(pgcore.versionStr())"
VERBATIM
COMMENT "Running pygimli installation in virtual test environment. ${Python3_EXECUTABLE} -c \'import pgcore; pgcore.versionStr()\'"
COMMENT "Testing ${TARGET_NAME} installation in virtual test environment. ${Python3_EXECUTABLE} -c \'import pgcore; pgcore.versionStr()\'"
)
add_custom_target(whl${TARGET_NAME}Test DEPENDS whl${TARGET_NAME}TestRun)

Expand Down
11 changes: 8 additions & 3 deletions core/pgcore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
"""
Basic import of gimli core extension.
"""
import sys
import sys, os

# if sys.platform == 'win32':
# os.environ['PATH'] = os.path.abspath(__file__) + ';' + os.environ['PATH']
if sys.platform == 'win32':
os.environ['PATH'] = os.path.join(os.path.dirname(__file__), 'libs') + ':' + os.environ['PATH']
#print(os.environ['LD_LIBRARY_PATH'])
elif sys.platform == 'linux':
if os.getenv('LD_LIBRARY_PATH'):
os.environ['LD_LIBRARY_PATH'] = os.path.join(os.path.dirname(__file__), 'libs') + ':' + os.environ['LD_LIBRARY_PATH']
#print(os.environ['LD_LIBRARY_PATH'])

_pygimli_ = None

Expand Down
32 changes: 18 additions & 14 deletions core/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ endif(WIN32)
add_python_module(pygimli "${CMAKE_CURRENT_BINARY_DIR}/generated/" "gimli" "${CMAKE_SOURCE_DIR}/pygimli/core/libs")
include_directories(${Python_NumPy_INCLUDE_DIRS})

add_dependencies(pggen gimli)
## copy libgimli.so INSOURCE so we can use and develop there directly
##add_dependencies(pggen copyLibGIMLi_INSOURCE)
#add_dependencies(copy_python pggen)

add_dependencies(fixpygimlisrc pggen)
add_dependencies(pgbuild fixpygimlisrc)

Expand All @@ -70,22 +72,24 @@ else(WIN32)
endif(WIN32)

# for calling the build only
ADD_CUSTOM_TARGET(pg ALL)

add_custom_target(pg ALL)

add_dependencies(pg _pygimli_)

ADD_CUSTOM_TARGET(pgtest)
ADD_CUSTOM_COMMAND(
COMMAND ${Python_EXECUTABLE}
ARGS -c 'import pygimli\; pygimli.test(show=False, abort=True) '
TARGET pgtest
)
ADD_CUSTOM_TARGET(pgtest
COMMAND ${Python_EXECUTABLE} -c 'import pygimli\; pygimli.test(show=False, abort=True) '
)

add_test(
NAME
pgtest:pygimli_tests
COMMAND
make pgtest
)
#add_dependencies(check pgtest)
#add_custom_target(checkpg ALL)

# add_test(
# NAME
# pgtest:pygimli_tests
# COMMAND
# make pgtest
# )

set(SCRIPTS pytripatch.py; meshmerge.py; meshconvert.py; pygi; datamerge.py)

Expand Down
23 changes: 23 additions & 0 deletions core/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ endif (UMFPACK_FOUND)

if (PYTHON_FOUND)
include_directories(${Python_INCLUDE_DIRS})

# needed since the later doesnt seems to work
target_link_libraries(${libgimli_TARGET_NAME} ${Python_LIBRARIES})

if (Python_Development.Module_FOUND)
target_link_libraries(${libgimli_TARGET_NAME} Python::Module)
else()
target_link_libraries(${libgimli_TARGET_NAME} ${Python_LIBRARIES})
endif()
endif (PYTHON_FOUND)

if (Boost_INCLUDE_DIR)
Expand Down Expand Up @@ -74,6 +82,21 @@ if (USE_BOOST_THREAD)
endif (Boost_SYSTEM_FOUND)
endif(USE_BOOST_THREAD)

## copy libgimli.so INSOURCE so we can use and develop there directly
set(INSOURCE_LIBRARIES_DIR ${CMAKE_SOURCE_DIR}/pygimli/core/libs/ )
add_custom_command(TARGET ${libgimli_TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${INSOURCE_LIBRARIES_DIR}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${libgimli_TARGET_NAME}> ${INSOURCE_LIBRARIES_DIR}
COMMENT "copy $<TARGET_FILE:gimli> to ${INSOURCE_LIBRARIES_DIR}"
)

# add_custom_target(copyLibGIMLi_INSOURCE DEPENDS gimli
# COMMAND
# cmake -E copy_if_different $<TARGET_FILE:gimli> ${OUTDIR}
# COMMENT "copy $<TARGET_FILE:gimli> to ${OUTDIR}"
# )



if (APPLE)
target_link_libraries(${libgimli_TARGET_NAME} "-undefined dynamic_lookup")
Expand Down
33 changes: 19 additions & 14 deletions core/tests/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,34 @@ file (GLOB unitTest_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.h)
#set(WITH_MEMCHECK TRUE)
#set(WITH_COVERAGE TRUE)

add_executable(gimliUnitTest unitTest.cpp ${unitTest_HEADERS})
set(TARGET_NAME gimliUnitTest)

add_executable(${TARGET_NAME} unitTest.cpp ${unitTest_HEADERS})

if (CPPUNIT_FOUND)

add_definitions(-DHAVE_UNITTEST)

include_directories(${CPPUNIT_INCLUDE_DIR})

target_link_libraries(gimliUnitTest ${CPPUNIT_LIBRARIES})
target_link_libraries(gimliUnitTest gimli)
target_link_libraries(${TARGET_NAME} gimli)
target_link_libraries(${TARGET_NAME} ${CPPUNIT_LIBRARIES})

# target_link_libraries(${TARGET_NAME} ${Python_LIBRARIES})

add_dependencies(check gimliUnitTest)

ADD_CUSTOM_TARGET(gtest)
ADD_CUSTOM_COMMAND(
COMMAND
${CMAKE_BINARY_DIR}/bin/gimliUnitTest
TARGET
gtest
)
# if (Python_Development.Module_FOUND)
# target_link_libraries(${TARGET_NAME} Python::Module)
# else()
# target_link_libraries(${TARGET_NAME} ${Python_LIBRARIES})
# endif()

add_dependencies(gimliUnitTest gimli)
add_dependencies(gtest gimliUnitTest)
add_dependencies(${TARGET_NAME} gimli)

ADD_CUSTOM_TARGET(gtest DEPENDS ${TARGET_NAME}
COMMAND ${CMAKE_BINARY_DIR}/bin/${TARGET_NAME}
)

#add_dependencies(check gtest)

# add_test(
# NAME
Expand Down
49 changes: 29 additions & 20 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# pip install -r dev_requirements.txt --user
# pip list
# pip install package== --user # list all possible versions for <pip-20.3
# pip install --use-deprecated=legacy-resolver package== --user # same as above for >=pip-20.3 and <pip-21
# pip install package==version --user
# recommand to create a suitable virtual environment first:
# python -m venv $ENVNAME
# source $ENVNAME/bin/activate
# python -m pip install -r dev_requirements.txt
# python -m pip list
# python -m pip install package==version


# needed
numpy
matplotlib
# needed to build
numpy>=1.25
pyplusplus==1.8.4
pygccxml==2.0.0

# needed to run
matplotlib>=1.37

# useful to run
ipython
jupytext

# optional, but strongly recommended
scipy>=1.11
scooby
pyvista[all,trame]>=0.42
pyqt5

# needed to build docu
sphinx>=3.1
sphinxcontrib-bibtex
sphinxcontrib-programoutput
Expand All @@ -19,19 +33,14 @@ sphinx-design
pydata-sphinx-theme
bibtexparser

pyvista[all,trame]>=0.42

# optional, but strongly recommended
scipy<1.12
scooby

# useful
ipython
jupytext

# for testing
# needed for testing
pytest
meshio

# needed for wheel build
wheel
auditwheel
twine

# optional
tetgen
13 changes: 7 additions & 6 deletions pygimli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,27 @@ else()
add_custom_target(whl${TARGET_NAME}PackageBuild #DEPENDS whlCopyLibs
COMMAND "${Python_EXECUTABLE}" -m pip wheel . --wheel-dir=${CMAKE_BINARY_DIR}/wheelhouse --find-links ${CMAKE_BINARY_DIR}/wheelhouse/
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Building python wheel package"
COMMENT "Building python wheel package for ${TARGET_NAME}"
)

add_custom_target(whl${TARGET_NAME} DEPENDS whl${TARGET_NAME}PackageBuild)
## test the wheel: make whlTest

add_custom_target(whl${TARGET_NAME}TestInstall DEPENDS whl${TARGET_NAME}
## test the wheel: make whlTest
# update the environment with VIRTUAL_ENV variable (mimic the activate script) and search again
add_custom_target(whl${TARGET_NAME}TestInstall DEPENDS whl${TARGET_NAME} whlpgcoreTestRun
COMMAND "${Python3_EXECUTABLE}" -m pip uninstall -y ${TARGET_NAME}
COMMAND "${Python3_EXECUTABLE}" -m pip install ${TARGET_NAME} --find-links=${CMAKE_BINARY_DIR}/wheelhouse
COMMENT "Installing ${TARGET_NAME} in virtual test environment"
)
add_custom_target(whl${TARGET_NAME}TestRun DEPENDS whl${TARGET_NAME}TestInstall
COMMAND ${Python3_EXECUTABLE} -c "import pygimli as pg; pg.version()"
VERBATIM
COMMENT "Running pygimli installation in virtual test environment. ${Python3_EXECUTABLE} -c \'import pygimli as pg; pg.version()\'"
COMMENT "Testing ${TARGET_NAME} installation in virtual test environment. ${Python3_EXECUTABLE} -c \'import pygimli as pg; pg.version()\'"
)
add_custom_target(whl${TARGET_NAME}Test DEPENDS whl${TARGET_NAME}TestRun)

#add_custom_target(whl DEPENDS whl${TARGET_NAME})

add_custom_target(whlTest DEPENDS whl${TARGET_NAME}TestRun)
## deploy the wheel: make whlDeploy
add_custom_target(whl${TARGET_NAME}Deploy DEPENDS whl${TARGET_NAME}Test
COMMAND "${Python_EXECUTABLE}" -m twine upload --repository testpypi ${CMAKE_BINARY_DIR}/wheelhouse/${PY_WHEELFILE}
Expand Down
Loading

0 comments on commit 0cfa3b0

Please sign in to comment.