Skip to content

Commit

Permalink
find_package(Python) (#1842)
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Aug 21, 2024
2 parents f25b198 + 2590ef3 commit c87b61e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 49 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,5 @@ if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()

find_package(Git REQUIRED)
find_package(Python COMPONENTS Interpreter REQUIRED)

add_subdirectory(src/Core)
add_subdirectory(Wrappers/Python)
72 changes: 26 additions & 46 deletions Wrappers/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,30 @@
option (BUILD_PYTHON_WRAPPER "Build Python Wrapper" ON)
find_package(Python COMPONENTS Interpreter REQUIRED)

if (BUILD_PYTHON_WRAPPER)
find_package(PythonInterp REQUIRED)

#set(PYTHON_DEST_DIR "" CACHE PATH "Directory of the Python wrappers")
if (PYTHON_DEST_DIR)
file(TO_CMAKE_PATH "${PYTHON_DEST_DIR}" TMP)
set(PYTHON_DEST "${TMP}")
unset(TMP)
endif()

message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")
if(NOT DEFINED)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
if(PYTHON_DEST_DIR)
file(TO_CMAKE_PATH "${PYTHON_DEST_DIR}" PYTHON_DEST)
endif()

find_package(PythonLibs)
if (PYTHONINTERP_FOUND)
message(STATUS "Found PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}")
message(STATUS "Python version ${PYTHON_VERSION_STRING}")
endif()
if (PYTHONLIBS_FOUND)
message(STATUS "Found PYTHON_INCLUDE_DIRS=${PYTHON_INCLUDE_DIRS}")
message(STATUS "Found PYTHON_LIBRARIES=${PYTHON_LIBRARIES}")
endif()
message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")
if(NOT DEFINED)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()

if (PYTHONINTERP_FOUND)
message("Python found " ${PYTHON_EXECUTABLE})
# TODO: add to add_custom_command DEPENDS the list of python files of the project.
# file(GLOB_RECURSE DEPS ${CMAKE_CURRENT_SOURCE_DIR}/cil/*.py )
message("SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL: $ENV{SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL}")
message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
if(PYTHON_DEST_DIR)
message(STATUS "CIL install using ${PYTHON_EXECUTABLE} -m pip install -t ${PYTHON_DEST}")
add_custom_target(pythonsetup ALL
COMMAND ${PYTHON_EXECUTABLE} -m pip install ${CMAKE_SOURCE_DIR} -t ${PYTHON_DEST} --upgrade
DEPENDS cilacc)
else()
message(STATUS "CIL install using ${PYTHON_EXECUTABLE} -m pip install")
add_custom_target(pythonsetup ALL
COMMAND ${PYTHON_EXECUTABLE} -m pip install ${CMAKE_SOURCE_DIR} --upgrade
DEPENDS cilacc)
endif()
# install the data if not a conda build. With conda the data is in the dependency package cil-data
if (NOT CONDA_BUILD)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cil)
endif()
endif()
# TODO: add to add_custom_command DEPENDS the list of python files of the project.
# file(GLOB_RECURSE DEPS ${CMAKE_CURRENT_SOURCE_DIR}/cil/*.py )
message("SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL: $ENV{SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL}")
message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
if(PYTHON_DEST_DIR)
message(STATUS "CIL install using ${Python_EXECUTABLE} -m pip install -t ${PYTHON_DEST}")
add_custom_target(pythonsetup ALL
COMMAND ${Python_EXECUTABLE} -m pip install ${CMAKE_SOURCE_DIR} -t ${PYTHON_DEST} --upgrade
DEPENDS cilacc)
else()
message(STATUS "CIL install using ${Python_EXECUTABLE} -m pip install")
add_custom_target(pythonsetup ALL
COMMAND ${Python_EXECUTABLE} -m pip install ${CMAKE_SOURCE_DIR} --upgrade
DEPENDS cilacc)
endif()
# install the data if not a conda build. With conda the data is in the dependency package cil-data
if (NOT CONDA_BUILD)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cil)
endif()

0 comments on commit c87b61e

Please sign in to comment.