forked from flatironinstitute/simple_ans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
78 lines (64 loc) · 2.03 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
cmake_minimum_required(VERSION 3.14)
project(simple_ans VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_RELEASE_FLAGS "-O3 -march=native")
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_error)
if (ipo_supported)
message(STATUS "IPO/LTO is supported")
else()
message(WARNING "IPO/LTO is not supported: ${ipo_error}")
endif()
# Find pybind11
find_package(pybind11 REQUIRED)
include(FetchContent)
FetchContent_Declare(
unordered_dense
GIT_REPOSITORY https://github.com/martinus/unordered_dense.git
GIT_TAG v4.5.0
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(unordered_dense)
# Set C++ standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Add source files
set(SOURCES
simple_ans/cpp/simple_ans.cpp
simple_ans_bind.cpp
)
# Add header files
set(HEADERS
simple_ans/cpp/simple_ans.hpp
)
# Create Python module
pybind11_add_module(_simple_ans ${SOURCES} ${HEADERS})
# Set include directories
target_include_directories(_simple_ans
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/simple_ans/cpp
)
target_link_libraries(_simple_ans PRIVATE unordered_dense)
# Set compiler flags
if(MSVC)
target_compile_options(_simple_ans PRIVATE /W4)
else()
target_compile_options(_simple_ans PRIVATE -Wall -Wextra -Wpedantic)
endif()
if(ipo_supported AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
set_target_properties(_simple_ans PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
# Install rules
include(GNUInstallDirs)
install(TARGETS _simple_ans
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(FILES ${HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/simple_ans
)
# For editable installs, copy the extension module to the source directory
add_custom_command(TARGET _simple_ans POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:_simple_ans> ${CMAKE_SOURCE_DIR}/simple_ans/
COMMENT "Copying extension module to source directory for editable install"
)