2
0

Update cmake for source and improve feature checking in ./build

This commit is contained in:
Maarten Billemont 2017-09-06 00:31:49 -04:00
parent 1439df9f9a
commit 4f552be5a9
2 changed files with 37 additions and 45 deletions

View File

@ -1,12 +1,13 @@
project(mpw) project(mpw C)
cmake_minimum_required(VERSION 3.0.2) cmake_minimum_required(VERSION 3.0.2)
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
set(CMAKE_C_FLAGS "-O3 -DHAS_SODIUM=1") set(CMAKE_C_FLAGS "-O3 -DMPW_SODIUM=1 -DMPW_JSON=1")
include_directories(core cli) include_directories(core cli)
file(GLOB SOURCES "core/*.c" "cli/mpw-cli.c") file(GLOB SOURCES "core/*.c" "cli/mpw-cli*.c")
add_executable(mpw ${SOURCES}) add_executable(mpw ${SOURCES})
find_library(libsodium REQUIRED) find_library(libsodium REQUIRED)
target_link_libraries(mpw sodium) find_library(libjson-c REQUIRED)
target_link_libraries(mpw sodium json-c)

View File

@ -55,9 +55,9 @@ echo 2>&1 "Current mpw source version ${mpw_version:-<unknown>}..."
### TARGET: MPW ### TARGET: MPW
mpw() { mpw() {
# dependencies # dependencies
use_mpw_sodium use_mpw_sodium required
use_mpw_color use_mpw_color optional
use_mpw_json use_mpw_json optional
# target # target
cflags=( cflags=(
@ -82,7 +82,7 @@ mpw() {
### TARGET: MPW-BENCH ### TARGET: MPW-BENCH
mpw-bench() { mpw-bench() {
# dependencies # dependencies
use_mpw_sodium use_mpw_sodium required
# target # target
cflags=( cflags=(
@ -107,8 +107,8 @@ mpw-bench() {
### TARGET: MPW-TESTS ### TARGET: MPW-TESTS
mpw-tests() { mpw-tests() {
# dependencies # dependencies
use_mpw_xml use_mpw_xml required
use_mpw_sodium use_mpw_sodium required
# target # target
cflags=( cflags=(
@ -132,7 +132,7 @@ mpw-tests() {
### TOOLS ### TOOLS
haslib() { haslib() {
cc -l"$1" -x c -o /dev/null - <<< 'int main() { return 0; }' cc -x c "${ldflags[@]}" -l"$1" -o /dev/null - <<< 'int main() { return 0; }' &>/dev/null
} }
cc() { cc() {
if hash llvm-gcc 2>/dev/null; then if hash llvm-gcc 2>/dev/null; then
@ -149,49 +149,40 @@ cc() {
### DEPENDENCIES ### DEPENDENCIES
use_mpw_sodium() { use() {
! (( mpw_sodium )) && return local option=$1 requisite=$2 lib=$3
local enabled=${!option}
if ! haslib sodium; then
echo >&2 "WARNING: mpw_sodium enabled but missing sodium library, will disable mpw_sodium."
if (( enabled )) && haslib "$lib"; then
echo >&2 "Enabled $option (lib$lib)."
ldflags+=( -l"$lib" )
return 0
elif [[ $requisite != required ]]; then
echo >&2 "WARNING: $option was enabled but is missing $lib library. Will continue with $option disabled!"
return 1
elif (( enabled )); then
echo >&2 "ERROR: $option was enabled but is missing $lib library. Please install this library before continuing."
exit 1
else else
echo >&2 "Enabled mpw_sodium (libsodium)." echo >&2 "ERROR: $option was required but is not enabled. Please enable the option or remove this target before continuing."
cflags+=( -D"MPW_SODIUM=1" ) ldflags+=( -l"sodium" ) exit 1
fi fi
} }
use_mpw_sodium() {
local requisite=$1
use mpw_sodium "$requisite" sodium && cflags+=( -D"MPW_SODIUM=1" ) ||:
}
use_mpw_color() { use_mpw_color() {
! (( mpw_color )) && return local requisite=$1
use mpw_color "$requisite" curses && cflags+=( -D"MPW_COLOR=1" ) ||:
if ! haslib curses; then
echo >&2 "WARNING: mpw_color enabled but missing curses library, will disable mpw_color."
else
echo >&2 "Enabled mpw_color (libcurses)."
cflags+=( -D"MPW_COLOR=1" ) ldflags+=( -l"curses" )
fi
} }
use_mpw_json() { use_mpw_json() {
! (( mpw_json )) && return local requisite=$1
use mpw_json "$requisite" json-c && cflags+=( -D"MPW_JSON=1" ) ||:
if ! haslib json-c; then
echo >&2 "WARNING: mpw_json enabled but missing json-c library, will disable mpw_json."
else
echo >&2 "Enabled mpw_json (libjson-c)."
cflags+=( -D"MPW_JSON=1" ) ldflags+=( -l"json-c" )
fi
} }
use_mpw_xml() { use_mpw_xml() {
! (( mpw_xml )) && return local requisite=$1
use mpw_xml "$requisite" xml2 && cflags+=( -D"MPW_XML=1" -I"/usr/include/libxml2" -I"/usr/local/include/libxml2" ) ||:
if ! haslib xml2; then
echo >&2 "WARNING: mpw_xml enabled but missing xml2 library, will disable mpw_xml."
else
echo >&2 "Enabled mpw_xml (libxml2)."
cflags+=( -D"MPW_XML=1" -I"/usr/include/libxml2" -I"/usr/local/include/libxml2" ) ldflags+=( -l"xml2" )
fi
} }