-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
72 lines (60 loc) · 2.29 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
cmake_minimum_required(VERSION 2.8)
include(FindOpenSSL)
find_package(PythonLibs REQUIRED)
find_package(PythonInterp REQUIRED)
if(NOT PYTHONLIBS_FOUND OR NOT PYTHON_EXECUTABLE)
message(FATAL "You need Python to build Python binding")
endif()
if(NOT OPENSSL_FOUND)
message(FATAL "OpenSSL not found!")
endif()
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_definitions(
-std=gnu99
-pedantic
-fno-strict-aliasing # when Python authors write a line of code, kitten dies
-Wall
-Wuninitialized
-Wignored-qualifiers
-Wno-long-long
-Wno-unknown-pragmas
)
option(DEBUG_ECDSA "Display debug messages on stderr" FALSE)
if (DEBUG_ECDSA)
add_definitions(-DDEBUG_ECDSA)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES Linux OR ${CMAKE_SYSTEM_NAME} MATCHES Darwin)
set (RESOLVLIB resolv)
endif()
file(GLOB SOURCES "src/*.[ch]")
python_add_module(cEcdsa ${SOURCES})
set_target_properties(cEcdsa PROPERTIES PREFIX "") # older CMake versions don't remove prefix on their own
target_link_libraries(cEcdsa ${RESOLVLIB} ${PYTHON_LIBRARIES} ${OPENSSL_LIBRARIES})
option(INSTALL_DIR "Relative to prefix directory where to install" "")
if (NOT INSTALL_DIR)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import site, sys; sys.stdout.write(site.PREFIXES[-1])"
OUTPUT_VARIABLE PYTHON_PREFIX
)
file(TO_CMAKE_PATH "${PYTHON_PREFIX}" PYTHON_PREFIX)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import site, sys; sys.stdout.write(site.getsitepackages()[-1])"
OUTPUT_VARIABLE PYTHON_SITE_DIR
)
file(TO_CMAKE_PATH "${PYTHON_SITE_DIR}" PYTHON_SITE_DIR)
string(REGEX REPLACE "^${PYTHON_PREFIX}/" "" PYTHON_SITE_DIR "${PYTHON_SITE_DIR}")
message(STATUS "Python prefix is: ${PYTHON_PREFIX}")
message(STATUS "Python site dir is: ${PYTHON_SITE_DIR}")
else()
set(PYTHON_SITE_DIR "${INSTALL_DIR}")
endif()
install(TARGETS cEcdsa LIBRARY DESTINATION ${PYTHON_SITE_DIR} COMPONENT library)
enable_testing()
add_test(
NAME key_test
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_key.py"
WORKING_DIRECTORY ${CMAKE_BUILD_DIR}
)
set_tests_properties(key_test PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BUILD_DIR})