Skip to content

Commit d413496

Browse files
committed
[Build] Initial CMake support
1 parent 458b08c commit d413496

7 files changed

+1039
-0
lines changed

CMakeLists.txt

+543
Large diffs are not rendered by default.

contrib/cmake/FindBerkeleyDB.cmake

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Author: sum01 <[email protected]>
2+
# Git: https://github.com/sum01/FindBerkeleyDB
3+
# Read the README.md for the full info.
4+
5+
# Allow user to pass a path instead of guessing
6+
if(BerkeleyDB_ROOT_DIR)
7+
set(_BERKELEYDB_PATHS "${BerkeleyDB_ROOT_DIR}")
8+
elseif(CMAKE_SYSTEM_NAME MATCHES ".*[wW]indows.*")
9+
# MATCHES is used to work on any devies with windows in the name
10+
# Shameless copy-paste from FindOpenSSL.cmake v3.8
11+
file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
12+
list(APPEND _BERKELEYDB_HINTS "${_programfiles}")
13+
14+
# There's actually production release and version numbers in the file path.
15+
# For example, if they're on v6.2.32: C:/Program Files/Oracle/Berkeley DB 12cR1 6.2.32/
16+
# But this still works to find it, so I'm guessing it can accept partial path matches.
17+
18+
foreach(_TARGET_BERKELEYDB_PATH "Oracle/Berkeley DB" "Berkeley DB")
19+
list(APPEND _BERKELEYDB_PATHS
20+
"${_programfiles}/${_TARGET_BERKELEYDB_PATH}"
21+
"C:/Program Files (x86)/${_TARGET_BERKELEYDB_PATH}"
22+
"C:/Program Files/${_TARGET_BERKELEYDB_PATH}"
23+
"C:/${_TARGET_BERKELEYDB_PATH}"
24+
)
25+
endforeach()
26+
else()
27+
# Paths for anything other than Windows
28+
# Cellar/berkeley-db is for macOS from homebrew installation
29+
list(APPEND _BERKELEYDB_PATHS
30+
"/usr/local/Cellar/berkeley-db@4"
31+
"/usr/local/Cellar/berkeley-db"
32+
"/opt"
33+
"/opt/local"
34+
"/usr/local"
35+
)
36+
endif()
37+
38+
# Find includes path
39+
find_path(BerkeleyDB_INCLUDE_DIRS
40+
db_cxx.h
41+
PATHS "${_BERKELEYDB_PATHS}"
42+
PATH_SUFFIXES "include" "includes"
43+
)
44+
45+
# Checks if the version file exists, save the version file to a var, and fail if there's no version file
46+
if(BerkeleyDB_INCLUDE_DIRS)
47+
# Read the version file db.h into a variable
48+
file(READ "${BerkeleyDB_INCLUDE_DIRS}/db.h" _BERKELEYDB_DB_HEADER)
49+
# Parse the DB version into variables to be used in the lib names
50+
string(REGEX REPLACE ".*DB_VERSION_MAJOR ([0-9]+).*" "\\1" BerkeleyDB_VERSION_MAJOR "${_BERKELEYDB_DB_HEADER}")
51+
string(REGEX REPLACE ".*DB_VERSION_MINOR ([0-9]+).*" "\\1" BerkeleyDB_VERSION_MINOR "${_BERKELEYDB_DB_HEADER}")
52+
# Patch version example on non-crypto installs: x.x.xNC
53+
string(REGEX REPLACE ".*DB_VERSION_PATCH ([0-9]+(NC)?).*" "\\1" BerkeleyDB_VERSION_PATCH "${_BERKELEYDB_DB_HEADER}")
54+
else()
55+
if(BerkeleyDB_FIND_REQUIRED)
56+
# If the find_package(BerkeleyDB REQUIRED) was used, fail since we couldn't find the header
57+
message(FATAL_ERROR "Failed to find Berkeley DB's header file \"db.h\"! Try setting \"BerkeleyDB_ROOT_DIR\" when initiating Cmake.")
58+
elseif(NOT BerkeleyDB_FIND_QUIETLY)
59+
message(WARNING "Failed to find Berkeley DB's header file \"db.h\"! Try setting \"BerkeleyDB_ROOT_DIR\" when initiating Cmake.")
60+
endif()
61+
# Set some garbage values to the versions since we didn't find a file to read
62+
set(BerkeleyDB_VERSION_MAJOR "0")
63+
set(BerkeleyDB_VERSION_MINOR "0")
64+
set(BerkeleyDB_VERSION_PATCH "0")
65+
endif()
66+
67+
# The actual returned/output version variable (the others can be used if needed)
68+
set(BerkeleyDB_VERSION "${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}.${BerkeleyDB_VERSION_PATCH}")
69+
70+
# Finds the target library for berkeley db, since they all follow the same naming conventions
71+
macro(findpackage_berkeleydb_get_lib _BERKELEYDB_OUTPUT_VARNAME _TARGET_BERKELEYDB_LIB)
72+
# Different systems sometimes have a version in the lib name...
73+
# and some have a dash or underscore before the versions.
74+
# CMake recommends to put unversioned names before versioned names
75+
find_library(${_BERKELEYDB_OUTPUT_VARNAME}
76+
NAMES
77+
"${_TARGET_BERKELEYDB_LIB}"
78+
"lib${_TARGET_BERKELEYDB_LIB}"
79+
"lib${_TARGET_BERKELEYDB_LIB}${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}"
80+
"lib${_TARGET_BERKELEYDB_LIB}-${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}"
81+
"lib${_TARGET_BERKELEYDB_LIB}_${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}"
82+
"lib${_TARGET_BERKELEYDB_LIB}${BerkeleyDB_VERSION_MAJOR}${BerkeleyDB_VERSION_MINOR}"
83+
"lib${_TARGET_BERKELEYDB_LIB}-${BerkeleyDB_VERSION_MAJOR}${BerkeleyDB_VERSION_MINOR}"
84+
"lib${_TARGET_BERKELEYDB_LIB}_${BerkeleyDB_VERSION_MAJOR}${BerkeleyDB_VERSION_MINOR}"
85+
"lib${_TARGET_BERKELEYDB_LIB}${BerkeleyDB_VERSION_MAJOR}"
86+
"lib${_TARGET_BERKELEYDB_LIB}-${BerkeleyDB_VERSION_MAJOR}"
87+
"lib${_TARGET_BERKELEYDB_LIB}_${BerkeleyDB_VERSION_MAJOR}"
88+
HINTS ${_BERKELEYDB_HINTS}
89+
PATH_SUFFIXES "lib" "lib64" "libs" "libs64"
90+
PATHS ${_BERKELEYDB_PATHS}
91+
)
92+
# If the library was found, add it to our list of libraries
93+
if(${_BERKELEYDB_OUTPUT_VARNAME})
94+
# If found, append to our libraries variable
95+
# The ${{}} is because the first expands to target the real variable, the second expands the variable's contents...
96+
# and the real variable's contents is the path to the lib. Thus, it appends the path of the lib to BerkeleyDB_LIBRARIES.
97+
list(APPEND BerkeleyDB_LIBRARIES "${${_BERKELEYDB_OUTPUT_VARNAME}}")
98+
endif()
99+
endmacro()
100+
101+
# Find and set the paths of the specific library to the variable
102+
findpackage_berkeleydb_get_lib(BerkeleyDB_LIBRARY "db")
103+
# NOTE: Windows doesn't have a db_cxx lib, but instead compiles the cxx code into the "db" lib
104+
findpackage_berkeleydb_get_lib(BerkeleyDB_Cxx_LIBRARY "db_cxx")
105+
# NOTE: I don't think Linux/Unix gets an SQL lib
106+
findpackage_berkeleydb_get_lib(BerkeleyDB_Sql_LIBRARY "db_sql")
107+
findpackage_berkeleydb_get_lib(BerkeleyDB_Stl_LIBRARY "db_stl")
108+
109+
# Needed for find_package_handle_standard_args()
110+
include(FindPackageHandleStandardArgs)
111+
# Fails if required vars aren't found, or if the version doesn't meet specifications.
112+
find_package_handle_standard_args(BerkeleyDB
113+
FOUND_VAR BerkeleyDB_FOUND
114+
REQUIRED_VARS
115+
BerkeleyDB_INCLUDE_DIRS
116+
BerkeleyDB_LIBRARY
117+
VERSION_VAR BerkeleyDB_VERSION
118+
)
119+
120+
# Create an imported lib for easy linking by external projects
121+
if(BerkeleyDB_FOUND AND BerkeleyDB_LIBRARIES AND NOT TARGET Oracle::BerkeleyDB)
122+
add_library(Oracle::BerkeleyDB UNKNOWN IMPORTED)
123+
set_target_properties(Oracle::BerkeleyDB PROPERTIES
124+
INTERFACE_INCLUDE_DIRECTORIES "${BerkeleyDB_INCLUDE_DIRS}"
125+
IMPORTED_LOCATION "${BerkeleyDB_LIBRARY}"
126+
INTERFACE_LINK_LIBRARIES "${BerkeleyDB_LIBRARIES}"
127+
)
128+
endif()
129+
130+
# Only show the includes path and libraries in the GUI if they click "advanced".
131+
# Does nothing when using the CLI
132+
mark_as_advanced(FORCE
133+
BerkeleyDB_INCLUDE_DIRS
134+
BerkeleyDB_LIBRARIES
135+
BerkeleyDB_LIBRARY
136+
BerkeleyDB_Cxx_LIBRARY
137+
BerkeleyDB_Sql_LIBRARY
138+
BerkeleyDB_Stl_LIBRARY
139+
)
140+
141+
include(FindPackageMessage)
142+
# A message that tells the user what includes/libs were found, and obeys the QUIET command.
143+
find_package_message(BerkeleyDB
144+
"Found BerkeleyDB libraries: ${BerkeleyDB_LIBRARIES}"
145+
"[${BerkeleyDB_LIBRARIES}[${BerkeleyDB_INCLUDE_DIRS}]]"
146+
)

contrib/cmake/FindGMP.cmake

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# - Find GMP
2+
# This module defines
3+
# GMP_INCLUDE_DIR, where to find GMP headers
4+
# GMP_LIBRARY, LibEvent libraries
5+
# GMP_FOUND, If false, do not try to use GMP
6+
7+
set(GMP_PREFIX "" CACHE PATH "path ")
8+
9+
find_path(GMP_INCLUDE_DIR gmp.h gmpxx.h
10+
PATHS ${GMP_PREFIX}/include /usr/include /usr/local/include )
11+
12+
find_library(GMP_LIBRARY NAMES gmp libgmp
13+
PATHS ${GMP_PREFIX}/lib /usr/lib /usr/local/lib)
14+
15+
if(GMP_INCLUDE_DIR AND GMP_LIBRARY)
16+
get_filename_component(GMP_LIBRARY_DIR ${GMP_LIBRARY} PATH)
17+
set(GMP_FOUND TRUE)
18+
endif()
19+
20+
if(GMP_FOUND)
21+
if(NOT GMP_FIND_QUIETLY)
22+
MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}")
23+
endif()
24+
elseif(GMP_FOUND)
25+
if(GMP_FIND_REQUIRED)
26+
message(FATAL_ERROR "Could not find GMP")
27+
endif()
28+
endif()
29+
30+
mark_as_advanced(
31+
GMP_LIB
32+
GMP_INCLUDE_DIR
33+
)

contrib/cmake/FindLibEvent.cmake

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# - Find LibEvent (a cross event library)
2+
# This module defines
3+
# LIBEVENT_INCLUDE_DIR, where to find LibEvent headers
4+
# LIBEVENT_LIB, LibEvent libraries
5+
# LibEvent_FOUND, If false, do not try to use libevent
6+
7+
if(($ENV{triple}) AND (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/depends/$ENV{triple}"))
8+
set(LIBEVENT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/depends/$ENV{triple}/include")
9+
set(LIBEVENT_LIB "${CMAKE_CURRENT_SOURCE_DIR}/depends/$ENV{triple}/lib/libevent.a")
10+
set(LIBEVENT_PTHREAD_LIB "${CMAKE_CURRENT_SOURCE_DIR}/depends/$ENV{triple}/lib/libevent.a")
11+
else()
12+
set(LibEvent_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}")
13+
foreach(prefix ${LibEvent_EXTRA_PREFIXES})
14+
list(APPEND LibEvent_INCLUDE_PATHS "${prefix}/include")
15+
list(APPEND LibEvent_LIB_PATHS "${prefix}/lib")
16+
endforeach()
17+
18+
find_path(LIBEVENT_INCLUDE_DIR event.h PATHS ${LibEvent_INCLUDE_PATHS})
19+
find_library(LIBEVENT_LIB NAMES event PATHS ${LibEvent_LIB_PATHS})
20+
find_library(LIBEVENT_PTHREAD_LIB NAMES event_pthreads PATHS ${LibEvent_LIB_PATHS})
21+
endif()
22+
23+
if (LIBEVENT_LIB AND LIBEVENT_INCLUDE_DIR AND LIBEVENT_PTHREAD_LIB)
24+
set(LibEvent_FOUND TRUE)
25+
set(LIBEVENT_LIB ${LIBEVENT_LIB} ${LIBEVENT_PTHREAD_LIB})
26+
else ()
27+
set(LibEvent_FOUND FALSE)
28+
endif ()
29+
30+
if (LibEvent_FOUND)
31+
if (NOT LibEvent_FIND_QUIETLY)
32+
message(STATUS "Found libevent: ${LIBEVENT_LIB}")
33+
endif ()
34+
else ()
35+
if (LibEvent_FIND_REQUIRED)
36+
message(FATAL_ERROR "Could NOT find libevent and libevent_pthread.")
37+
endif ()
38+
message(STATUS "libevent and libevent_pthread NOT found.")
39+
endif ()
40+
41+
mark_as_advanced(
42+
LIBEVENT_LIB
43+
LIBEVENT_INCLUDE_DIR
44+
)

contrib/cmake/FindQrcode.cmake

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# - Find Qrcode
2+
# This module defines
3+
# QRCODE_INCLUDE_DIR, where to find libqrencode headers
4+
# QRCODE_LIB, libqrencode libraries
5+
# QRCODE_FOUND, If false, do not try to use libqrencode
6+
7+
set(QRCODE_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}")
8+
foreach(prefix ${ZMQ_EXTRA_PREFIXES})
9+
list(APPEND QRCODE_INCLUDE_PATHS "${prefix}/include")
10+
list(APPEND QRCODE_LIB_PATHS "${prefix}/lib")
11+
endforeach()
12+
13+
find_path(QRCODE_INCLUDE_DIR qrencode.h PATHS ${QRCODE_INCLUDE_PATHS})
14+
find_library(QRCODE_LIB NAMES qrencode PATHS ${QRCODE_LIB_PATHS})
15+
16+
if (QRCODE_LIB AND QRCODE_INCLUDE_DIR)
17+
set(QRCODE_FOUND TRUE)
18+
else ()
19+
set(QRCODE_FOUND FALSE)
20+
endif ()
21+
22+
if (QRCODE_FOUND)
23+
if (NOT QRCODE_FIND_QUIETLY)
24+
message(STATUS "Found libqrencode: ${QRCODE_LIB}")
25+
include_directories(${QRCODE_INCLUDE_DIR})
26+
endif ()
27+
else ()
28+
if (QRCODE_FIND_REQUIRED)
29+
message(FATAL_ERROR "Could NOT find libqrencode.")
30+
endif ()
31+
message(STATUS "libqrencode NOT found.")
32+
endif ()
33+
34+
mark_as_advanced(
35+
QRCODE_LIB
36+
QRCODE_INCLUDE_DIR
37+
)

contrib/cmake/FindZMQ.cmake

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# - Find ZeroMQ
2+
# This module defines
3+
# ZMQ_INCLUDE_DIR, where to find ZMQ headers
4+
# ZMQ_LIB, ZMQ libraries
5+
# ZMQ_FOUND, If false, do not try to use ZeroMQ
6+
7+
set(ZMQ_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}")
8+
foreach(prefix ${ZMQ_EXTRA_PREFIXES})
9+
list(APPEND ZMQ_INCLUDE_PATHS "${prefix}/include")
10+
list(APPEND ZMQ_LIB_PATHS "${prefix}/lib")
11+
endforeach()
12+
13+
find_path(ZMQ_INCLUDE_DIR zmq.h PATHS ${ZMQ_INCLUDE_PATHS})
14+
find_library(ZMQ_LIB NAMES zmq PATHS ${ZMQ_LIB_PATHS})
15+
16+
if (ZMQ_LIB AND ZMQ_INCLUDE_DIR)
17+
set(ZMQ_FOUND TRUE)
18+
else ()
19+
set(ZMQ_FOUND FALSE)
20+
endif ()
21+
22+
if (ZMQ_FOUND)
23+
if (NOT ZMQ_FIND_QUIETLY)
24+
message(STATUS "Found ZeroMQ: ${ZMQ_LIB}")
25+
include_directories(${ZMQ_INCLUDE_DIR})
26+
endif ()
27+
else ()
28+
if (ZMQ_FIND_REQUIRED)
29+
message(FATAL_ERROR "Could NOT find ZeroMQ.")
30+
endif ()
31+
message(STATUS "ZeroMQ NOT found.")
32+
endif ()
33+
34+
mark_as_advanced(
35+
ZMQ_LIB
36+
ZMQ_INCLUDE_DIR
37+
)

0 commit comments

Comments
 (0)