-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
170 lines (125 loc) · 4.84 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
cmake_minimum_required(VERSION 3.22)
set(PROJECT_LIB ed25519cpp)
project(${PROJECT_LIB} VERSION 1.4.0)
set(CMAKE_CXX_STANDARD 17)
option(DEHANCER_TARGET_ARCH "")
option(BUILD_TESTING "Enable creation of Eigen tests." OFF)
# first we can indicate the documentation build as an option and set it to ON by default
option(BUILD_DOC "Build documentation" OFF)
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -EHsc -Wno-deprecated-declarations")
add_definitions(/MT /DWIN32=1 /D_ITERATOR_DEBUG_LEVEL=0)
string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
if (${BUILD_TYPE} STREQUAL "debug")
add_definitions(/MTd)
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -ffast-math")
endif ()
set (EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)
#
# Packages
#
find_package(PkgConfig REQUIRED)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
message(STATUS ${CMAKE_CURRENT_SOURCE_DIR} )
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(STATUS "Using Clang" )
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(STATUS "Using gcc" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -W -Wall -Wextra -Wvariadic-macros -static-libgcc -static-libstdc++ ")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
if (${CMAKE_SYSTEM_NAME} STREQUAL Linux)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DX86_LINUX")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
message( FATAL_ERROR "The project does not support Intel compiler" )
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
message( FATAL_ERROR "The project does not support MSVC compiler" )
endif()
# check if Doxygen is installed
if(BUILD_DOC)
find_package(Doxygen)
if (DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the application
add_custom_target( doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else (DOXYGEN_FOUND)
message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND)
endif()
#
# Google Test
#
if (BUILD_TESTING)
find_package(GTest)
if (NOT GTest_FOUND)
string(STRIP "${CMAKE_C_FLAGS} -D_ITERATOR_DEBUG_LEVEL=0" C_FLAGS)
string(STRIP "${CMAKE_CXX_FLAGS} -D_ITERATOR_DEBUG_LEVEL=0" CXX_FLAGS)
set(CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING "" FORCE)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
INSTALL_COMMAND
OVERRIDE_FIND_PACKAGE
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif ()
endif ()
#
# Details
#
include_directories(
${EXTERNAL_INSTALL_LOCATION}/include
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/external
${SQLITE3_INCLUDE_DIRS}
)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib)
if (BUILD_TESTING)
add_subdirectory(test)
enable_testing ()
endif ()
# Install package
#
if (NOT CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR lib)
endif ()
if (NOT CMAKE_INSTALL_INCLUDEDIR)
set(CMAKE_INSTALL_INCLUDEDIR include)
endif ()
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ed25519cpp.pc.in ${CMAKE_CURRENT_BINARY_DIR}/ed25519cpp.pc @ONLY)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/ed25519cpp.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)