Skip to content

Commit

Permalink
Merge pull request cyclus#1737 from bennibbelink/pyinstall-cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke authored Apr 21, 2024
2 parents 26f5438 + ad33d53 commit 5353209
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Since last release
**Changed:**

* Moved to unified CHANGELOG Entry and check them with GithubAction (#1571)
* Major update and modernization of build (#1587, #1632, #1734)
* Major update and modernization of build (#1587, #1632, #1734, #1737)
* Changed Json formatting for compatibility with current python standards (#1587)
* Changed README.rst installation instructions, tested on fresh Ubuntu-22.04 system with Python 3.11 (#1617, #1644)
* Resolved various compilation warnings due to use of deprecated APIs (#1671)
Expand Down
23 changes: 16 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,11 @@ IF(NOT CYCLUS_DOC_ONLY)
#
# Use new Python library finder
find_package (Python3 REQUIRED COMPONENTS Interpreter Development)

execute_process(COMMAND "${Python3_EXECUTABLE}" -m site --user-site
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT DEFINED PYTHON_SITE_PACKAGES)
execute_process(COMMAND "${Python3_EXECUTABLE}" -m site --user-site
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
message("-- PYTHON_EXECUTABLE: ${Python3_EXECUTABLE}")
message("-- PYTHON_SITE_PACKAGES: ${PYTHON_SITE_PACKAGES}")
IF (NOT APPLE)
Expand Down Expand Up @@ -437,9 +438,17 @@ IF(NOT CYCLUS_DOC_ONLY)
)

if(Cython_FOUND)
set(pyinstallscript "${CMAKE_CURRENT_BINARY_DIR}/cmake/SetupPyInstall.cmake")
configure_file(cmake/SetupPyInstall.cmake.in ${pyinstallscript} @ONLY)
install(SCRIPT ${pyinstallscript})
install(CODE "
message(\"############### Begin Python Install ###############\")
set(ENV{CYCLUS_PROJECT_VERSION} \"${CMAKE_PROJECT_VERSION}\")
execute_process(COMMAND ${Python3_EXECUTABLE} -m pip install --target=${PYTHON_SITE_PACKAGES} --force-reinstall --upgrade --no-deps .
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
RESULT_VARIABLE res_var)
if(NOT \"${res_var}\" STREQUAL \"\")
message(FATAL_ERROR \"Process python -m pip install failed, res_var = '${res_var}'\")
endif()
message(\"Cyclus Python package successfully installed in ${PYTHON_SITE_PACKAGES}\")
")
endif(Cython_FOUND)
##############################################################################################
################################## begin uninstall target ####################################
Expand Down
35 changes: 35 additions & 0 deletions cmake/FindCyclus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ FIND_LIBRARY(CYCLUS_CORE_LIBRARY NAMES cyclus
/opt/local /opt/local/cyclus
PATH_SUFFIXES cyclus/lib lib)

# Look for the library
FIND_LIBRARY(CYCLUS_EVENTHOOKS_LIBRARY NAMES eventhooks.so
HINTS "${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus"
${DEPS_CYCLUS}
/usr/local/cyclus/lib /usr/local/cyclus
/opt/local /opt/local/cyclus
PATH_SUFFIXES cyclus/lib lib)

# Look for the library
FIND_LIBRARY(CYCLUS_PYINFILE_LIBRARY NAMES pyinfile.so
HINTS "${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus"
${DEPS_CYCLUS}
/usr/local/cyclus/lib /usr/local/cyclus
/opt/local /opt/local/cyclus
PATH_SUFFIXES cyclus/lib lib)

# Look for the library
FIND_LIBRARY(CYCLUS_PYMODULE_LIBRARY NAMES pymodule.so
HINTS "${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus"
${DEPS_CYCLUS}
/usr/local/cyclus/lib /usr/local/cyclus
/opt/local /opt/local/cyclus
PATH_SUFFIXES cyclus/lib lib)

# Look for the library
FIND_LIBRARY(CYCLUS_AGENT_TEST_LIBRARY NAMES baseagentunittests
HINTS "${CYCLUS_ROOT_DIR}" "${CYCLUS_ROOT_DIR}/cyclus"
Expand All @@ -112,6 +136,17 @@ IF(CYCLUS_CORE_INCLUDE_DIR AND CYCLUS_CORE_TEST_INCLUDE_DIR
AND CYCLUS_AGENT_TEST_LIBRARY)
SET(CYCLUS_CORE_FOUND 1)
SET(CYCLUS_CORE_LIBRARIES "${CYCLUS_CORE_LIBRARY}")
# if Cyclus was installed without Cython these three libraries won't be found because they don't exist
# if Cyclus was installed WITH Cython we need to link against them
if(NOT ${CYCLUS_EVENTHOOKS_LIBRARY} STREQUAL "CYCLUS_EVENTHOOKS_LIBRARY-NOTFOUND")
SET(CYCLUS_CORE_LIBRARIES "${CYCLUS_CORE_LIBRARIES}" "${CYCLUS_EVENTHOOKS_LIBRARY}")
endif()
if(NOT ${CYCLUS_PYINFILE_LIBRARY} STREQUAL "CYCLUS_PYINFILE_LIBRARY-NOTFOUND")
SET(CYCLUS_CORE_LIBRARIES "${CYCLUS_CORE_LIBRARIES}" "${CYCLUS_PYINFILE_LIBRARY}")
endif()
if(NOT ${CYCLUS_PYMODULE_LIBRARY} STREQUAL "CYCLUS_PYMODULE_LIBRARY-NOTFOUND")
SET(CYCLUS_CORE_LIBRARIES "${CYCLUS_CORE_LIBRARIES}" "${CYCLUS_PYMODULE_LIBRARY}")
endif()
SET(CYCLUS_TEST_LIBRARIES "${CYCLUS_GTEST_LIBRARY}" "${CYCLUS_AGENT_TEST_LIBRARY}")
SET(CYCLUS_AGENT_TEST_LIBRARIES "${CYCLUS_AGENT_TEST_LIBRARY}")
SET(CYCLUS_CORE_INCLUDE_DIRS "${CYCLUS_CORE_INCLUDE_DIR}")
Expand Down
26 changes: 0 additions & 26 deletions cmake/SetupPyInstall.cmake.in

This file was deleted.

3 changes: 0 additions & 3 deletions cyclus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ foreach(file ${CYCLUS_CYTHON_FILES})
# by setup.py, along with the pure python files.
install(TARGETS ${targ} LIBRARY DESTINATION "${PYTHON_SITE_PACKAGES}/cyclus")
endforeach()

FILE(GLOB CYCLUS_PYTHON_FILES "${CYCLUS_PYSOURCE_DIR}/*.py")
INSTALL(FILES ${CYCLUS_PYTHON_FILES} DESTINATION "${PYTHON_SITE_PACKAGES}/cyclus")
3 changes: 1 addition & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ RUN conda update -y --all && \
liblapack \
pkg-config \
coincbc \
boost-cpp \
libboost-devel \
hdf5 \
sqlite \
pcre \
Expand Down Expand Up @@ -137,7 +137,6 @@ WORKDIR /cyclus
# for further CMake debugging.
RUN python install.py -j ${make_cores} --build-type=Release --allow-milps
ENV PATH /root/.local/bin:$PATH
ENV LD_LIBRARY_PATH /root/.local/lib:/root/.local/lib/cyclus

FROM cyclus as deb-generation
WORKDIR /cyclus/build
Expand Down
8 changes: 4 additions & 4 deletions tests/cycpp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
sys.path.insert(0, os.path.join(cycdir, 'cli'))

# pass 1 Filters
from cycpp import NamespaceFilter, TypedefFilter, UsingFilter,\
from cyclus.cycpp import NamespaceFilter, TypedefFilter, UsingFilter,\
UsingNamespaceFilter, NamespaceAliasFilter, ClassFilter, \
AccessFilter, PragmaCyclusErrorFilter

# pass 2 Filters
from cycpp import VarDecorationFilter, VarDeclarationFilter, ExecFilter, \
from cyclus.cycpp import VarDecorationFilter, VarDeclarationFilter, ExecFilter, \
NoteDecorationFilter, StateAccumulator

# pass 3 Filters
from cycpp import CloneFilter, InitFromCopyFilter, \
from cyclus.cycpp import CloneFilter, InitFromCopyFilter, \
InitFromDbFilter, InfileToDbFilter, SchemaFilter, SnapshotFilter, \
SnapshotInvFilter, InitInvFilter, DefaultPragmaFilter, AnnotationsFilter

import cycpp
import cyclus.cycpp as cycpp

class MockMachine(object):
def __init__(self):
Expand Down

0 comments on commit 5353209

Please sign in to comment.