cosmotool/python/CMakeLists.txt

133 lines
5.9 KiB
CMake
Raw Normal View History

2014-05-25 10:43:06 +02:00
set(CMAKE_SHARED_MODULE_PREFIX)
2017-08-09 17:42:02 +02:00
set(PYTHON_INCLUDES ${NUMPY_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/python)
include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src)
2014-05-25 10:43:06 +02:00
IF(CYTHON)
2014-11-20 14:04:17 +01:00
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_cosmotool.cpp
COMMAND ${CYTHON} --cplus -o ${CMAKE_CURRENT_BINARY_DIR}/_cosmotool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/_cosmotool.pyx
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_cosmotool.pyx)
2014-11-20 14:04:17 +01:00
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_cosmo_power.cpp
COMMAND ${CYTHON} --cplus -o ${CMAKE_CURRENT_BINARY_DIR}/_cosmo_power.cpp ${CMAKE_CURRENT_SOURCE_DIR}/_cosmo_power.pyx
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_cosmo_power.pyx)
2014-11-20 14:04:17 +01:00
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_fast_interp.cpp
COMMAND ${CYTHON} --cplus -o ${CMAKE_CURRENT_BINARY_DIR}/_fast_interp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/_fast_interp.pyx
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_fast_interp.pyx)
2014-11-20 14:04:17 +01:00
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_cosmo_cic.cpp
COMMAND ${CYTHON} --cplus -o ${CMAKE_CURRENT_BINARY_DIR}/_cosmo_cic.cpp ${CMAKE_CURRENT_SOURCE_DIR}/_cosmo_cic.pyx
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_cosmo_cic.pyx)
2014-11-20 14:04:17 +01:00
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_project.cpp
COMMAND ${CYTHON} --cplus -o ${CMAKE_CURRENT_BINARY_DIR}/_project.cpp ${CMAKE_CURRENT_SOURCE_DIR}/_project.pyx
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_project.pyx ${CMAKE_CURRENT_SOURCE_DIR}/project_tool.hpp )
2020-10-03 20:51:39 +02:00
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_cosmomath.cpp
COMMAND ${CYTHON} --cplus -o ${CMAKE_CURRENT_BINARY_DIR}/_cosmomath.cpp ${CMAKE_CURRENT_SOURCE_DIR}/_cosmomath.pyx
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_cosmomath.pyx )
2014-05-25 10:43:06 +02:00
ENDIF(CYTHON)
add_library(_cosmotool MODULE ${CMAKE_CURRENT_BINARY_DIR}/_cosmotool.cpp)
2014-11-20 14:04:17 +01:00
add_library(_cosmo_power MODULE ${CMAKE_CURRENT_BINARY_DIR}/_cosmo_power.cpp)
add_library(_cosmo_cic MODULE ${CMAKE_CURRENT_BINARY_DIR}/_cosmo_cic.cpp)
add_library(_fast_interp MODULE ${CMAKE_CURRENT_BINARY_DIR}/_fast_interp.cpp)
add_library(_project MODULE ${CMAKE_CURRENT_BINARY_DIR}/_project.cpp)
2020-10-03 20:51:39 +02:00
add_library(_cosmomath MODULE ${CMAKE_CURRENT_BINARY_DIR}/_cosmomath.cpp)
target_include_directories(_cosmotool PRIVATE ${PYTHON_INCLUDES})
target_include_directories(_cosmo_power PRIVATE ${PYTHON_INCLUDES})
target_include_directories(_cosmo_cic PRIVATE ${PYTHON_INCLUDES})
target_include_directories(_fast_interp PRIVATE ${PYTHON_INCLUDES})
target_include_directories(_project PRIVATE ${PYTHON_INCLUDES})
2020-10-03 20:51:39 +02:00
target_include_directories(_cosmomath PRIVATE ${PYTHON_INCLUDES})
2014-05-25 10:43:06 +02:00
2017-08-09 17:42:02 +02:00
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Bsymbolic-functions")
if(APPLE)
set(CMAKE_MODULE_LINKER_FLAGS "-undefined dynamic_lookup")
endif()
2021-01-25 09:50:48 +01:00
IF(NOT APPLE)
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/cosmotool.version")
ENDIF()
2014-05-25 10:43:06 +02:00
2020-04-28 14:12:36 +02:00
target_link_libraries(_cosmotool PRIVATE ${CosmoTool_local} ${GSL_LIBRARIES})
target_link_libraries(_cosmo_power PRIVATE ${CosmoTool_local} ${GSL_LIBRARIES})
target_link_libraries(_cosmo_cic PRIVATE ${CosmoTool_local} ${GSL_LIBRARIES})
2020-10-03 20:51:39 +02:00
target_link_libraries(_cosmomath PRIVATE ${CosmoTool_local} ${GSL_LIBRARIES})
2018-09-14 10:51:27 +02:00
target_link_libraries(_project )
2020-04-28 14:12:36 +02:00
target_link_libraries(_fast_interp PRIVATE ${CosmoTool_local} )
2016-11-26 21:30:44 +01:00
2020-10-03 20:51:39 +02:00
SET(ct_TARGETS _cosmotool _project _cosmo_power _cosmo_cic _fast_interp _cosmomath)
2016-11-26 21:30:44 +01:00
2018-09-14 10:51:27 +02:00
if (Boost_FOUND)
2016-11-26 21:30:44 +01:00
message(STATUS "Building bispectrum support (path = ${Boost_INCLUDE_DIRS})")
include_directories(${Boost_INCLUDE_DIRS})
add_library(_cosmo_bispectrum MODULE _cosmo_bispectrum.cpp)
target_link_libraries(_cosmo_bispectrum ${MATH_LIBRARY})
if(ENABLE_OPENMP)
set_target_properties(_cosmo_bispectrum PROPERTIES COMPILE_FLAGS "${OpenMP_CXX_FLAGS}" LINK_FLAGS "${OpenMP_CXX_FLAGS}")
endif()
if (Boost_DEP)
add_dependencies(_cosmo_bispectrum ${Boost_DEP})
endif()
2016-11-26 21:30:44 +01:00
SET(ct_TARGETS ${ct_TARGETS} _cosmo_bispectrum)
endif()
2014-05-25 10:43:06 +02:00
# Discover where to put packages
if (NOT PYTHON_SITE_PACKAGES)
execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" OUTPUT_VARIABLE internal_PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
2014-05-25 10:43:06 +02:00
SET(SYSTEM_PYTHON_SITE_PACKAGES ${internal_PYTHON_SITE_PACKAGES} CACHE PATH "Path to the target system-wide site-package where to install python modules")
execute_process (COMMAND ${PYTHON_EXECUTABLE} -c "from site import USER_SITE; print(USER_SITE)" OUTPUT_VARIABLE internal_PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
2014-05-25 10:43:06 +02:00
SET(USER_PYTHON_SITE_PACKAGES ${internal_PYTHON_SITE_PACKAGES} CACHE PATH "Path to the target user site-package where to install python modules")
mark_as_advanced(USER_PYTHON_SITE_PACKAGES SYSTEM_PYTHON_SITE_PACKAGES)
endif (NOT PYTHON_SITE_PACKAGES)
2017-07-11 15:36:19 +02:00
message(STATUS "System python site: ${SYSTEM_PYTHON_SITE_PACKAGES}")
message(STATUS "User python site: ${USER_PYTHON_SITE_PACKAGES}")
2014-05-25 10:43:06 +02:00
OPTION(INSTALL_PYTHON_LOCAL OFF)
IF (NOT PYTHON_SITE_PACKAGES)
IF (NOT INSTALL_PYTHON_LOCAL)
SET(PYTHON_SITE_PACKAGES ${SYSTEM_PYTHON_SITE_PACKAGES})
ELSE (NOT INSTALL_PYTHON_LOCAL)
SET(PYTHON_SITE_PACKAGES ${USER_PYTHON_SITE_PACKAGES})
ENDIF(NOT INSTALL_PYTHON_LOCAL)
ENDIF()
2017-07-11 15:36:19 +02:00
cmessage(STATUS "Python install location: ${PYTHON_SITE_PACKAGES}")
2014-05-25 10:43:06 +02:00
if (WIN32 AND NOT CYGWIN)
SET_TARGET_PROPERTIES(_cosmotool PROPERTIES SUFFIX ".pyd")
endif (WIN32 AND NOT CYGWIN)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cosmotool/config.py.in ${CMAKE_CURRENT_BINARY_DIR}/cosmotool/config.py @ONLY)
INSTALL(TARGETS
2016-11-26 21:30:44 +01:00
${ct_TARGETS}
COMPONENT python
2014-05-26 14:24:53 +02:00
LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}/cosmotool
2014-05-25 10:43:06 +02:00
)
INSTALL(DIRECTORY cosmotool ${CMAKE_CURRENT_BINARY_DIR}/cosmotool
COMPONENT python DESTINATION ${PYTHON_SITE_PACKAGES}
2014-05-25 10:43:06 +02:00
FILES_MATCHING PATTERN "*.py")
add_custom_target(
python-install
DEPENDS ${ct_TARGETS}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=python -P
"${CMAKE_BINARY_DIR}/cmake_install.cmake")