-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
116 lines (95 loc) · 3.35 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Maintainer: Andrew White
if(NOT BUILD_MD)
message(FATAL_ERROR "HOOMD-TF package cannot be built without MD.")
endif(NOT BUILD_MD)
set(COMPONENT_NAME htf)
set(_${COMPONENT_NAME}_sources
module.cc
CommStruct.cc
TensorflowCompute.cc
TFArrayComm.cc
)
set(_${COMPONENT_NAME}_cu_sources
TensorflowCompute.cu
TFArrayComm.cu
)
if(ENABLE_HIP)
set(_cuda_sources ${_${COMPONENT_NAME}_cu_sources})
endif(ENABLE_HIP)
# check if we have python dependencies for compiling
set(TF_REQUIRE_COMPILER "")
if(NOT IGNORE_HTF_COMPILER)
set(TF_REQUIRE_COMPILER ${CMAKE_CXX_COMPILER_VERSION})
endif()
set(TF_REQUIRE_VERSION "2.3")
execute_process(COMMAND ${PYTHON_EXECUTABLE} -W ignore ${CMAKE_CURRENT_SOURCE_DIR}/check_tf_version.py ${TF_REQUIRE_VERSION} ${TF_REQUIRE_COMPILER}
RESULT_VARIABLE ret)
if(ret EQUAL "1")
message(FATAL_ERROR "-- Could not find suitable tensorflow or compiler to build ${COMPONENT_NAME} (see messages above)")
else()
message("-- Found suitable tensorflow version for minimum ${TF_REQUIRE_VERSION}")
endif()
pybind11_add_module(_${COMPONENT_NAME} SHARED ${_${COMPONENT_NAME}_sources} ${_cuda_soruces} NO_EXTRAS)
# alias into the HOOMD namespace so that plugins and symlinked components both work
add_library(HOOMD::_${COMPONENT_NAME} ALIAS _${COMPONENT_NAME})
# add visilibty flag, which is missing from hoomd?
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
if(APPLE)
set_target_properties(_${COMPONENT_NAME} PROPERTIES INSTALL_RPATH "@loader_path/..;@loader_path")
else()
set_target_properties(_${COMPONENT_NAME} PROPERTIES INSTALL_RPATH "\$ORIGIN/..;\$ORIGIN")
endif()
# link the library to its dependencies
if(NOT HOOMD_MD_LIB)
set(HOOMD_MD_LIB _md)
endif()
target_link_libraries(_${COMPONENT_NAME} PUBLIC HOOMD::_hoomd)
target_link_libraries(_${COMPONENT_NAME} PUBLIC HOOMD::_md)
# if we are compiling with MPI support built in, set appropriate
# compiler/linker flags
if(ENABLE_MPI)
if(MPI_COMPILE_FLAGS)
set_target_properties(_${COMPONENT_NAME} PROPERTIES COMPILE_FLAGS "${MPI_CXX_COMPILE_FLAGS}")
endif(MPI_COMPILE_FLAGS)
if(MPI_LINK_FLAGS)
set_target_properties(_${COMPONENT_NAME} PROPERTIES LINK_FLAGS "${MPI_CXX_LINK_FLAGS}")
endif(MPI_LINK_FLAGS)
endif(ENABLE_MPI)
if(ENABLE_HIP)
fix_cudart_rpath(_${COMPONENT_NAME})
endif(ENABLE_HIP)
# install the library
install(TARGETS _${COMPONENT_NAME}
LIBRARY DESTINATION ${PYTHON_SITE_INSTALL_DIR}/${COMPONENT_NAME}
)
##############################
# The Tensorflow
add_subdirectory(hoomd2tf_op)
add_subdirectory(tf2hoomd_op)
################ Python only modules
# copy python modules to the build directory to make it a working python package
MACRO(copy_file file)
add_custom_command(
OUTPUT ${file}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${CMAKE_CURRENT_BINARY_DIR}/${file}
COMMENT "Copy hoomd/${COMPONENT_NAME}/${file}"
)
ENDMACRO(copy_file)
set(files
__init__.py
tensorflowcompute.py
version.py
layers.py
simmodel.py
utils.py
)
install(FILES ${files}
DESTINATION ${PYTHON_SITE_INSTALL_DIR}/${COMPONENT_NAME}
)
copy_files_to_build("${files}" "${COMPONENT_NAME}" "*.py")
#add_custom_target(copy_${COMPONENT_NAME} ALL DEPENDS ${files})
if(BUILD_TESTING)
add_subdirectory(test-py)
endif()