Skip to content
Snippets Groups Projects
Commit c66953b4 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

CMake added to build python libraries

It works, but not perfect
parent 82bc76ed
Branches
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 3.10)
# set the project name
project(sisso++ VERSION 0.1 LANGUAGES CXX)
# Cmake modules/macros are in a subdirectory to keep this file cleaner
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
enable_testing()
# Compiler tests
include(CheckCXXCompilerFlag)
# Check for C++14 standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Check python settings
find_package(PythonInterp 3 REQUIRED)
execute_process(COMMAND ${PYTHON_EXECUTABLE}
-c "import distutils.sysconfig as cg; print(cg.get_python_inc())"
OUTPUT_VARIABLE PYTHON_INCLUDE_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(PYTHON_INCLUDE_PATH ${PYTHON_INCLUDE_PATH} CACHE PATH "Python Include Directory")
mark_as_advanced(PYTHON_INCLUDE_PATH)
include_directories(${PYTHON_INCLUDE_PATH})
if(NOT PYTHON_INSTDIR)
execute_process(COMMAND ${PYTHON_EXECUTABLE}
-c "import distutils.sysconfig as cg; print(cg.get_python_lib(1,0,prefix='${CMAKE_INSTALL_EXEC_PREFIX}'))"
OUTPUT_VARIABLE PYTHON_INSTDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
execute_process(COMMAND ${PYTHON_EXECUTABLE}
-c "import sys; print('{}{}'.format(sys.version_info[0], sys.version_info[1]))"
OUTPUT_VARIABLE BOOST_PYTHON_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PYTHON_EXECUTABLE}
-c "import sys; print(sys.version[:3])"
OUTPUT_VARIABLE PYTHON_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PYTHON_EXECUTABLE}
-c "import distutils.sysconfig as cg; print(cg.get_config_var('LIBDIR'))"
OUTPUT_VARIABLE PYTHON_LIBDIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "PYTHON_LIBDIR = ${PYTHON_LIBDIR}")
find_library(PYTHON_LIBRARIES
NAMES python${PYTHON_VERSION}m
PATHS ${PYTHON_LIBDIR} )
if(NOT PYTHON_LIBRARIES)
message(FATAL_ERROR "Python libraries not found!")
endif(NOT PYTHON_LIBRARIES)
message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
mark_as_advanced(PYTHON_INCLUDE_PATH PYTHON_LIBRARIES)
# Check for Boost
find_package(Boost REQUIRED COMPONENTS filesystem system mpi serialization)
set(Boost_LIBS ${Boost_LIBRARIES})
if(${Boost_VERSION} VERSION_LESS 106700)
find_package(Boost ${NEEDED_Boost_VERSION} REQUIRED COMPONENTS python)
else()
find_package(Boost ${NEEDED_Boost_VERSION} REQUIRED COMPONENTS python${BOOST_PYTHON_VERSION})
endif()
# Append Python library to the list of Boost libraries.
list(APPEND Boost_LIBS ${Boost_LIBRARIES})
set(Boost_LIBRARIES ${Boost_LIBS})
if(NOT Boost_FOUND)
message(FATAL_ERROR "Boost not found.")
endif(NOT Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
mark_as_advanced(PYTHON_INCLUDE_PATH Boost_LIBS)
# Check BLAS/LAPACK
find_package(MKL REQUIRED)
if(MKL_FOUND)
include_directories(${MKL_INCLUDE_DIRS})
set(LAPACK_LIBRARIES ${MKL_LIBRARIES})
else()
find_package(LAPACK)
if(LPACK_FOUND)
set(LAPACK_LIBRARIES ${LAPACK_LIBRARIES})
else()
message(FATAL_ERROR "LAPACK/BLAS not found")
endif()
target_link_libraries(mytest ${BLAS_LIBRARIES})
endif()
# Check MPI
find_package(MPI)
if(MPI_CXX_FOUND)
include_directories(MPI_CXX_INCLUDE_DIRS)
set(MPI_LIBRARIES, MPI_CXX_LIBRARIES)
else()
message(FATAL_ERROR "MPI not found.")
endif()
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src)
# # add the executable
# add_executable(sisso++ src/main.cpp)
# target_link_libraries(sisso++ ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} ${PYTHON_LIBRARIES} ${Boost_LIBS} ${PROJECT_NAME})
# # # add the library for python bindings
# # add_library(sisso++ SHARED src/python/bindings.cpp)
# # target_link_libraries(sisso++ ${Boost_LIBRARIES} ${PROJECT_NAME})
file(GLOB_RECURSE SISSOPP_SOURCES *.cpp)
file(GLOB_RECURSE SISSOLIB_SOURCES *.cpp)
file(GLOB_RECURSE NOT_SISSOPP_SOURCES python/*.cpp)
list(REMOVE_ITEM SISSOPP_SOURCES ${NOT_SISSOPP_SOURCES})
list(REMOVE_ITEM SISSOLIB_SOURCES main.cpp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sisso++_config.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/sisso++_config.hpp)
add_executable(sisso++ ${SISSOPP_SOURCES})
add_library(_sisso SHARED ${SISSOLIB_SOURCES})
include_directories(${CMAKE_CURRENT_LIST_DIR}/descriptor_identifier/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/descriptor_identifier/Model)
include_directories(${CMAKE_CURRENT_LIST_DIR}/feature_creation/node/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/feaure_creation/node/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/feaure_creation/node/operator_nodes/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/feaure_creation/node/value_storage/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/feature_creation/units/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/feature_creation/feature_space/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/feature_creation/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/inputs/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/mpi_interface/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/python/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/utils/)
# target_link_libraries(sisso ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} ${PYTHON_LIBRARIES} ${Boost_LIBS})
# set_target_properties(sisso PROPERTIES PREFIX "" SUFFIX ".so" LIBRARY_OUTPUT_DIRECTORY ..)
# install(TARGETS sisso LIBRARY DESTINATION ${PYTHON_INSTDIR} ARCHIVE DESTINATION ${PYTHON_INSTDIR})
# install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${PYTHON_INSTDIR}/sisso
# FILES_MATCHING PATTERN "*.py"
# PATTERN "CMakeFiles" EXCLUDE)
set_target_properties( sisso++
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
target_link_libraries(sisso++ ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} ${PYTHON_LIBRARIES} ${Boost_LIBS})
set_target_properties( _sisso
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
PREFIX ""
SUFFIX ".so"
)
target_link_libraries(_sisso ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} ${PYTHON_LIBRARIES} ${Boost_LIBS})
configure_file(__init__.py ${CMAKE_CURRENT_LIST_DIR}/python/__init__.py COPYONLY)
# install(TARGETZS _sisso ${CMAKE_CURRENT_LIST_DIR}/python/__init__.py DESTINATION "${PYTHON_INSTALL_PATH}")
#include <feature_creation/node/operator_nodes/OperatorNode.hpp>
BOOST_SERIALIZATION_ASSUME_ABSTRACT(OperatorNode)
#include <feature_creation/node/operator_nodes/functions.hpp>
std::map<NODE_TYPE, node_functions> node_function_map;
node_function_map[NODE_TYPE::ADD] = std::make_tuple(allowed_op_funcs::add, allowed_expr_funcs::add, allowed_unit_funcs::add);
node_function_map[NODE_TYPE::SUB] = std::make_tuple(allowed_op_funcs::sub, allowed_expr_funcs::sub, allowed_unit_funcs::sub);
node_function_map[NODE_TYPE::ABS_DIFF] = std::make_tuple(allowed_op_funcs::abs_diff, allowed_expr_funcs::abs_diff, allowed_unit_funcs::abs_diff);
node_function_map[NODE_TYPE::MULT] = std::make_tuple(allowed_op_funcs::mult, allowed_expr_funcs::mult, allowed_unit_funcs::mult);
node_function_map[NODE_TYPE::DIV] = std::make_tuple(allowed_op_funcs::div, allowed_expr_funcs::div, allowed_unit_funcs::div);
node_function_map[NODE_TYPE::EXP] = std::make_tuple(allowed_op_funcs::exp, allowed_expr_funcs::exp, allowed_unit_funcs::exp);
node_function_map[NODE_TYPE::NEG_EXP] = std::make_tuple(allowed_op_funcs::neg_exp, allowed_expr_funcs::neg_exp, allowed_unit_funcs::neg_exp);
node_function_map[NODE_TYPE::INV] = std::make_tuple(allowed_op_funcs::inv, allowed_expr_funcs::inv, allowed_unit_funcs::inv);
node_function_map[NODE_TYPE::SQ] = std::make_tuple(allowed_op_funcs::sq, allowed_expr_funcs::sq, allowed_unit_funcs::sq);
node_function_map[NODE_TYPE::CB] = std::make_tuple(allowed_op_funcs::cb, allowed_expr_funcs::cb, allowed_unit_funcs::cb);
node_function_map[NODE_TYPE::SIX_POW] = std::make_tuple(allowed_op_funcs::sixth_pow, allowed_expr_funcs::sixth_pow, allowed_unit_funcs::sixth_pow);
node_function_map[NODE_TYPE::SQRT] = std::make_tuple(allowed_op_funcs::sqrt, allowed_expr_funcs::sqrt, allowed_unit_funcs::sqrt);
node_function_map[NODE_TYPE::CBRT] = std::make_tuple(allowed_op_funcs::cbrt, allowed_expr_funcs::cbrt, allowed_unit_funcs::cbrt);
node_function_map[NODE_TYPE::LOG] = std::make_tuple(allowed_op_funcs::log, allowed_expr_funcs::log, allowed_unit_funcs::log);
node_function_map[NODE_TYPE::ABS] = std::make_tuple(allowed_op_funcs::abs, allowed_expr_funcs::abs, allowed_unit_funcs::abs);
node_function_map[NODE_TYPE::SIN] = std::make_tuple(allowed_op_funcs::sin, allowed_expr_funcs::sin, allowed_unit_funcs::sin);
node_function_map[NODE_TYPE::COS] = std::make_tuple(allowed_op_funcs::cos, allowed_expr_funcs::cos, allowed_unit_funcs::cos);
#include <python/bindings.hpp>
#include <utils/MPI_Interface.hpp>
#include <mpi_interface/MPI_Interface.hpp>
#include <Python.h>
static void finalize();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment