Skip to content

Commit

Permalink
cmake changes for pip package building
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoes committed Mar 30, 2020
1 parent fbf4778 commit 72eef70
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ configure_file (
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CUDA_STANDARD 14)

if(${BUILD_CONTAINED_PYTHON})
set(BUILD_STATIC ON)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3")
Expand Down
26 changes: 20 additions & 6 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ if (NOT PYTHONLIBS_FOUND)
message(STATUS "Python libraries NOT found")
endif()

if(BUILD_CONTAINED_PYTHON)
# create a python library with as few runtime dependencies as possible
set(Boost_USE_STATIC_LIBS ON)
endif()

if(${CMAKE_VERSION} VERSION_LESS "3.13.0")
find_package( Boost COMPONENTS system filesystem python${PYTHON_VERSION_MAJOR} REQUIRED )
else()
#minor version numbers requires newer (3.13?) version of cmake
find_package( Boost COMPONENTS system filesystem python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR} REQUIRED )
endif()
#find_package( Boost COMPONENTS system filesystem python REQUIRED )

find_package( NumPy )

Expand Down Expand Up @@ -40,18 +44,28 @@ set( PYMOLGRID_PY
torch_bindings.py
)

# create the lib
add_library(molgrid SHARED ${PYMOLGRID_SOURCES})


file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/molgrid/")

# link
if(BUILD_CONTAINED_PYTHON)
# create a python library with as few runtime dependencies as possible
add_library(molgrid SHARED ${PYMOLGRID_SOURCES})
SET_TARGET_PROPERTIES(molgrid PROPERTIES CUDA_SEPARABLE_COMPILATION OFF)
target_link_libraries(molgrid ${Boost_LIBRARIES} ${CUDA_LIBRARIES} libmolgrid_static )
else()
# create the lib
add_library(molgrid SHARED ${PYMOLGRID_SOURCES})
target_link_libraries(molgrid ${Boost_LIBRARIES} ${CUDA_LIBRARIES} libmolgrid_shared)
endif()

# Suppress prefix "lib" because Python does not allow this prefix
set_target_properties(molgrid PROPERTIES
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/molgrid/")

# link
target_link_libraries(molgrid ${Boost_LIBRARIES} ${CUDA_LIBRARIES} libmolgrid_shared)


# copy module code
foreach(file ${PYMOLGRID_PY})
configure_file(${file} ${CMAKE_CURRENT_BINARY_DIR}/molgrid/)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ endif()

if(BUILD_STATIC)
add_library(libmolgrid_static STATIC ${LIBMOLGRID_HEADERS} ${LIBMOLGRID_SOURCES})
SET_TARGET_PROPERTIES(libmolgrid_static PROPERTIES OUTPUT_NAME molgrid CUDA_SEPARABLE_COMPILATION OFF)
SET_TARGET_PROPERTIES(libmolgrid_static PROPERTIES OUTPUT_NAME molgrid CUDA_SEPARABLE_COMPILATION OFF POSITION_INDEPENDENT_CODE ON )
target_link_libraries(libmolgrid_static ${OPENBABEL3_LIBRARIES} ${Boost_LIBRARIES})
#install libs
install(TARGETS libmolgrid_static DESTINATION lib)
Expand Down

0 comments on commit 72eef70

Please sign in to comment.