Lines 18-34
Link Here
|
18 |
crypto_box_curve25519xsalsa20poly1305.h |
18 |
crypto_box_curve25519xsalsa20poly1305.h |
19 |
PATHS |
19 |
PATHS |
20 |
${NACL_PREFIX}/include |
20 |
${NACL_PREFIX}/include |
21 |
/usr/include |
21 |
/usr/include/sodium |
22 |
/usr/include/nacl |
|
|
23 |
/usr/local/include |
24 |
/opt/local/include |
25 |
${CMAKE_BINARY_DIR}/nacl_build/include/ |
26 |
NO_DEFAULT_PATH |
22 |
NO_DEFAULT_PATH |
27 |
) |
23 |
) |
28 |
|
24 |
|
29 |
find_library(NACL_LIBRARIES |
25 |
find_library(NACL_LIBRARIES |
30 |
NAMES |
26 |
NAMES |
31 |
nacl |
27 |
libsodium.a |
32 |
PATHS |
28 |
PATHS |
33 |
${NACL_INCLUDE_DIRS}/../ |
29 |
${NACL_INCLUDE_DIRS}/../ |
34 |
${NACL_INCLUDE_DIRS}/../lib |
30 |
${NACL_INCLUDE_DIRS}/../lib |
Lines 37-114
Link Here
|
37 |
) |
33 |
) |
38 |
|
34 |
|
39 |
if(NACL_INCLUDE_DIRS AND NACL_LIBRARIES) |
35 |
if(NACL_INCLUDE_DIRS AND NACL_LIBRARIES) |
40 |
message("libnacl found: ${NACL_INCLUDE_DIRS}") |
36 |
message("libnacl (libsodium) found: ${NACL_INCLUDE_DIRS}") |
41 |
set(NACL_FOUND TRUE) |
37 |
set(NACL_FOUND TRUE) |
42 |
endif() |
38 |
endif() |
43 |
|
39 |
|
44 |
endif() |
40 |
endif() |
45 |
|
|
|
46 |
if(NOT NACL_FOUND) |
47 |
message("libnacl not found, will be downloaded and compiled.") |
48 |
include(ExternalProject) |
49 |
|
50 |
# Without this, the build doesn't happen until link time. |
51 |
include_directories(${NACL_USE_FILES}) |
52 |
|
53 |
# the name of the tag |
54 |
set(tag "cnacl-e551eb9a55897c651a6688223b8734223f990175.tar.gz") |
55 |
|
56 |
# Configure cnacl |
57 |
set(cNaClConfig " |
58 |
add_definitions(\"-fPIC\") |
59 |
set(MY_CMAKE_ASM_FLAGS \"-fPIC\") |
60 |
set(CMAKE_ASM_COMPILER \"${CMAKE_C_COMPILER}\") |
61 |
") |
62 |
file(WRITE ${CMAKE_BINARY_DIR}/cNaClConfig.cmake "${cNaClConfig}") |
63 |
set(cmakeArgs "-DCNACL_CONFIG_SCRIPT=${CMAKE_BINARY_DIR}/cNaClConfig.cmake") |
64 |
|
65 |
if (CMAKE_TOOLCHAIN_FILE) |
66 |
get_filename_component(toolchainFilePath "${CMAKE_TOOLCHAIN_FILE}" REALPATH) |
67 |
list(APPEND cmakeArgs "-DCMAKE_TOOLCHAIN_FILE=${toolchainFilePath}") |
68 |
endif() |
69 |
|
70 |
set(file ${CMAKE_BINARY_DIR}/nacl_ep-prefix/src/${tag}) |
71 |
set(AssertSHA256 ${CMAKE_SOURCE_DIR}/cmake/modules/AssertSHA256.cmake) |
72 |
set(check ${CMAKE_COMMAND} -DFILE=${file} -DEXPECTED=${hash} -P ${AssertSHA256}) |
73 |
|
74 |
set(url "${CMAKE_SOURCE_DIR}/cmake/externals/${tag}") |
75 |
if(NOT EXISTS "${url}") |
76 |
set(url ${CMAKE_BINARY_DIR}/nacl_ep-prefix/src/${tag}) |
77 |
endif() |
78 |
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/nacl_build") |
79 |
ExternalProject_Add(nacl_ep |
80 |
URL ${url} |
81 |
SOURCE_DIR "${CMAKE_BINARY_DIR}/nacl" |
82 |
BINARY_DIR "${CMAKE_BINARY_DIR}/nacl_build" |
83 |
CMAKE_ARGS ${cmakeArgs} |
84 |
INSTALL_COMMAND "" |
85 |
UPDATE_COMMAND "" |
86 |
PATCH_COMMAND "" |
87 |
) |
88 |
|
89 |
add_custom_command( |
90 |
OUTPUT ${CMAKE_BINARY_DIR}/nacl/build/nacl_test.out |
91 |
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/modules/TestNACL.cmake |
92 |
) |
93 |
add_custom_target(nacl_test DEPENDS ${CMAKE_BINARY_DIR}/nacl/build/nacl_test.out) |
94 |
add_dependencies(nacl_test nacl_ep) |
95 |
|
96 |
# The source of this uglyness is a limit on adding dependencies to imported libraries. |
97 |
# see: http://www.cmake.org/Bug/print_bug_page.php?bug_id=10395 |
98 |
# It's fixed in cmake 2.8.4 but it would be nice to continue supporting 2.8.2 and 2.8.3 |
99 |
if(NOT EXISTS ${CMAKE_BINARY_DIR}/DoNothing.c) |
100 |
file(WRITE ${CMAKE_BINARY_DIR}/DoNothing.c "int DoNothing() { return 0; }\n") |
101 |
endif() |
102 |
add_library(nacl_test_dependency ${CMAKE_BINARY_DIR}/DoNothing.c) |
103 |
add_dependencies(nacl_test_dependency nacl_test) |
104 |
|
105 |
|
106 |
add_library(nacl STATIC IMPORTED) |
107 |
set_property(TARGET nacl |
108 |
PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/nacl_build/libnacl.a) |
109 |
|
110 |
set(NACL_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/nacl_build/include/") |
111 |
set(NACL_LIBRARIES nacl nacl_test_dependency) |
112 |
set(NACL_FOUND TRUE) |
113 |
|
114 |
endif() |