Skip to content

Commit d35bd1c

Browse files
committed
Build nanobind with cmake
1 parent 53ef0c2 commit d35bd1c

File tree

2 files changed

+35
-83
lines changed

2 files changed

+35
-83
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=64", "setuptools_scm>=8"]
2+
requires = ["setuptools>=64", "setuptools_scm>=8", "nanobind", "ipp-devel", "ipp-static", "intel-openmp"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.setuptools_scm]

src/Core/CMakeLists.txt

Lines changed: 34 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,28 @@ if(NOT DEFINED CMAKE_BUILD_TYPE)
2323
set(CMAKE_BUILD_TYPE RelWithDebInfo)
2424
endif()
2525

26-
message ("OpenMP_CXX_FLAGS ${OpenMP_CXX_FLAGS}")
27-
find_package(OpenMP REQUIRED)
28-
add_definitions(${OpenMP_CXX_FLAGS})
2926

3027

31-
if (WIN32)
32-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ddll_EXPORTS")
33-
endif()
28+
29+
execute_process(
30+
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
31+
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
32+
find_package(nanobind CONFIG REQUIRED)
33+
34+
find_package(IPP REQUIRED CONFIG)
35+
36+
3437

3538
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNUCC")
3639
# appends some flags
3740
add_compile_options(-ftree-vectorize -fopt-info-vec-optimized -fopt-info-vec)
3841
# add_compile_options(-march=native -mavx )
3942
endif()
4043

44+
message ("OpenMP_CXX_FLAGS ${OpenMP_CXX_FLAGS}")
45+
find_package(OpenMP REQUIRED)
46+
add_definitions(${OpenMP_CXX_FLAGS})
47+
4148
message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}")
4249
message("CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}")
4350
message("CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}")
@@ -52,80 +59,25 @@ else()
5259
set (OpenMP_EXE_LINKER_FLAGS ${OpenMP_C_FLAGS})
5360
endif()
5461

55-
if(NOT DEFINED IPP_LIBRARY)
56-
if (UNIX)
57-
set(IPP_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib)
58-
elseif(WIN32)
59-
set(IPP_LIBRARY ${CMAKE_INSTALL_PREFIX}/Library/lib)
60-
endif()
61-
endif()
62-
63-
if(NOT DEFINED IPP_INCLUDE)
64-
set(IPP_INCLUDE ${CMAKE_INSTALL_PREFIX}/include)
65-
endif()
66-
67-
if (UNIX)
68-
find_library(IPP_CORE libippcore.so PATHS ${IPP_LIBRARY})
69-
find_library(IPP_S libipps.so PATHS ${IPP_LIBRARY})
70-
find_library(IPP_VM libippvm.so PATHS ${IPP_LIBRARY})
71-
find_library(IPP_I libippi.so PATHS ${IPP_LIBRARY})
72-
elseif(WIN32)
73-
find_library(IPP_CORE ippcore PATHS ${IPP_LIBRARY})
74-
find_library(IPP_S ipps PATHS ${IPP_LIBRARY})
75-
find_library(IPP_VM ippvm PATHS ${IPP_LIBRARY})
76-
find_library(IPP_I ippi PATHS ${IPP_LIBRARY})
77-
endif()
78-
79-
if(IPP_CORE AND IPP_S AND IPP_VM AND IPP_I)
80-
set(USE_IPP TRUE)
81-
message("IPP libraries found")
82-
else()
83-
set(USE_IPP FALSE)
84-
message("IPP libraries not found, FBP_filtering not in build")
85-
endif()
86-
87-
if(USE_IPP)
88-
add_library(cilacc SHARED ${CMAKE_CURRENT_SOURCE_DIR}/utilities.cpp
89-
${CMAKE_CURRENT_SOURCE_DIR}/axpby.cpp
90-
${CMAKE_CURRENT_SOURCE_DIR}/FiniteDifferenceLibrary.cpp
91-
${CMAKE_CURRENT_SOURCE_DIR}/FBP_filtering.cpp
92-
${CMAKE_CURRENT_SOURCE_DIR}/Binning.cpp)
93-
94-
95-
target_link_libraries(cilacc ${OpenMP_EXE_LINKER_FLAGS} ${IPP_CORE} ${IPP_S} ${IPP_I} ${IPP_VM})
96-
include_directories(cilacc PUBLIC ${IPP_INCLUDE} ${CMAKE_CURRENT_SOURCE_DIR}/include)
97-
else()
98-
add_library(cilacc SHARED ${CMAKE_CURRENT_SOURCE_DIR}/utilities.cpp
99-
${CMAKE_CURRENT_SOURCE_DIR}/axpby.cpp
100-
${CMAKE_CURRENT_SOURCE_DIR}/FiniteDifferenceLibrary.cpp )
101-
102-
target_link_libraries(cilacc ${OpenMP_EXE_LINKER_FLAGS})
103-
include_directories(cilacc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
104-
endif()
105-
106-
## Install
107-
#include(GNUInstallDirs)
108-
#install(TARGETS cilacc
109-
# RUNTIME DESTINATION bin
110-
# LIBRARY DESTINATION lib
111-
# ARCHIVE DESTINATION lib
112-
# CONFIGURATIONS ${CMAKE_BUILD_TYPE}
113-
# )
114-
115-
if (UNIX)
116-
message ("I'd install into ${CMAKE_INSTALL_PREFIX}/lib")
117-
install(TARGETS cilacc
118-
LIBRARY DESTINATION lib
119-
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
120-
)
121-
elseif(WIN32)
122-
message ("I'd install into ${CMAKE_INSTALL_PREFIX} lib bin")
123-
install(TARGETS cilacc
124-
RUNTIME DESTINATION Library/bin
125-
ARCHIVE DESTINATION lib
126-
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
127-
)
128-
endif()
62+
nanobind_add_module(
63+
cilacc
64+
NB_STATIC
65+
${CMAKE_CURRENT_SOURCE_DIR}/nanobind.cpp
66+
${CMAKE_CURRENT_SOURCE_DIR}/include/axpby.h
67+
${CMAKE_CURRENT_SOURCE_DIR}/include/Binning.h
68+
${CMAKE_CURRENT_SOURCE_DIR}/include/FBP_filtering.h
69+
${CMAKE_CURRENT_SOURCE_DIR}/include/FiniteDifferenceLibrary.h
70+
${CMAKE_CURRENT_SOURCE_DIR}/include/utilities.h
71+
${CMAKE_CURRENT_SOURCE_DIR}/axpby.cpp
72+
${CMAKE_CURRENT_SOURCE_DIR}/Binning.cpp
73+
${CMAKE_CURRENT_SOURCE_DIR}/FBP_filtering.cpp
74+
${CMAKE_CURRENT_SOURCE_DIR}/FiniteDifferenceLibrary.cpp
75+
${CMAKE_CURRENT_SOURCE_DIR}/utilities.cpp
76+
)
77+
target_link_libraries(cilacc PUBLIC ${OpenMP_EXE_LINKER_FLAGS} ${IPP_LIBRARIES})
78+
include_directories(cilacc PUBLIC
79+
${IPP_INCLUDE}
80+
${CMAKE_CURRENT_SOURCE_DIR}/include/
81+
)
82+
install(TARGETS cilacc LIBRARY DESTINATION cil)
12983

130-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/Core/include/
131-
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/cil)

0 commit comments

Comments
 (0)