Skip to content

Commit

Permalink
port to cmake #1
Browse files Browse the repository at this point in the history
add install
now we can use python verdandi module
  • Loading branch information
prudhomm committed Aug 3, 2021
1 parent c5a44aa commit 1fd7f4e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
22 changes: 18 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
#set(BLA_VENDOR Intel10_64lp)
find_package(BLAS)
find_package(LAPACK)

include(GNUInstallDirs)
include(FetchContent)

# get seldon from github
FetchContent_Declare(seldon GIT_REPOSITORY https://github.com/libseldon/seldon.git)
set(FETCHCONTENT_SOURCE_DIR_SELDON /home/prudhomm/Devel/seldon)
FetchContent_Declare(seldon GIT_REPOSITORY https://github.com/feelpp/seldon.git )
FetchContent_GetProperties(seldon)
if(NOT seldon_POPULATED)
FetchContent_Populate(seldon)
endif()
add_library(seldon SHARED ${seldon_SOURCE_DIR}/Seldon.cpp)
add_library(seldon SHARED ${seldon_SOURCE_DIR}/Seldon.cpp)
#target_compile_definitions(seldon PUBLIC -DSELDON_WITH_COMPILED_LIBRARY)
target_compile_features(seldon PUBLIC cxx_std_17)
target_link_libraries(seldon ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})

Expand All @@ -34,7 +36,13 @@ add_dependencies(seldon seldon_link_target)
target_include_directories(seldon PUBLIC
$<BUILD_INTERFACE:${seldon_SOURCE_DIR}/>
$<INSTALL_INTERFACE:include/seldon> )

install(TARGETS seldon EXPORT VerdandiTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

find_library(MATH_LIBRARY_FOR_LUA m)
message(STATUS "${MATH_LIBRARY_FOR_LUA}")
find_package(Lua 5.2)
Expand Down Expand Up @@ -65,6 +73,12 @@ target_link_libraries(ops PUBLIC lua)
target_include_directories(ops PUBLIC
$<BUILD_INTERFACE:${libops_SOURCE_DIR}/>
$<INSTALL_INTERFACE:include/ops> )
install(TARGETS ops EXPORT VerdandiTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)


add_subdirectory(share)
Expand Down
4 changes: 4 additions & 0 deletions example/quadratic_model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ add_dependencies(quadratic_model quadratic_model_forward)
add_executable(quadratic_model_optimal_interpolation optimal_interpolation.cpp)
target_link_libraries(quadratic_model_optimal_interpolation verdandi)
add_dependencies(quadratic_model quadratic_model_optimal_interpolation)

add_executable(quadratic_model_nudging nudging.cpp)
target_link_libraries(quadratic_model_nudging verdandi)
add_dependencies(quadratic_model quadratic_model_nudging)
22 changes: 21 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,24 @@ set_property(TARGET _verdandi PROPERTY SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE)
set_property(TARGET _verdandi PROPERTY INCLUDE_DIRECTORIES ${libops_SOURCE_DIR} ${seldon_SOURCE_DIR}/ ${Python_INCLUDE_DIRS})
set_property(TARGET _verdandi PROPERTY SWIG_COMPILE_DEFINITIONS SELDON_EXCLUDE_FROM_EXPLICIT_INSTANTIATION VERDANDI_DEBUG_LEVEL_4 VERDANDI_PYTHON_VERSION=${Python_VERSION_MAJOR}.${Python_VERSION_MINOR})
target_link_libraries(_verdandi PUBLIC verdandi ops)
target_include_directories(_verdandi PRIVATE ${Python3_INCLUDE_DIRS} )
target_include_directories(_verdandi PRIVATE ${Python3_INCLUDE_DIRS} )

if (DEFINED PYTHON_SITE_PACKAGES)
set (VERDANDI_PYTHON_MODULE_PATH ${PYTHON_SITE_PACKAGES})
else ()
execute_process (COMMAND ${Python3_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))"
OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
RESULT_VARIABLE _PYTHON_pythonlib_result
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (_PYTHON_pythonlib_result)
message (SEND_ERROR "Could not run ${Python3_EXECUTABLE}")
endif ()

get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE)
file (RELATIVE_PATH VERDANDI_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH})
endif ()
set (VERDANDI_PYTHON${PYTHON_VERSION_MAJOR}_MODULE_PATH ${VERDANDI_PYTHON_MODULE_PATH})
message(STATUS "[verdandi] python module path: ${VERDANDI_PYTHON_MODULE_PATH}")
install(TARGETS _verdandi DESTINATION ${VERDANDI_PYTHON_MODULE_PATH})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/verdandi.py DESTINATION ${VERDANDI_PYTHON_MODULE_PATH})
10 changes: 9 additions & 1 deletion share/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ target_include_directories(verdandi PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/share>
$<INSTALL_INTERFACE:include/ops> )
target_link_libraries(verdandi PUBLIC seldon ops lua)
target_link_libraries(verdandi PUBLIC seldon ops lua)


install(TARGETS verdandi EXPORT VerdandiTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

0 comments on commit 1fd7f4e

Please sign in to comment.