Skip to content

Commit

Permalink
Fixes in configure options (#273)
Browse files Browse the repository at this point in the history
Fixes in configure options
  • Loading branch information
ethouris authored and rndi committed Feb 12, 2018
1 parent e404ffc commit fcb5c70
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 110 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ endif()
# options
option(CYGWIN_USE_POSIX "Should the POSIX API be used for cygwin. Ignored if the system isn't cygwin." OFF)
option(ENABLE_CXX11 "Should the c++11 parts (srt-live-transmit) be enabled" ON)
option(ENABLE_PROFILE "Should the build contain profile information. Ignored if compiler isn't GNU compatable." env{HAI_BUILD_PROFILE})
option(ENABLE_PROFILE "Should instrument the code for profiling. Ignored for non-GNU compiler." $ENV{HAI_BUILD_PROFILE})
option(ENABLE_LOGGING "Should logging be enabled" ON)
option(ENABLE_HEAVY_LOGGING "Should logging be enabled" ${ENABLE_HEAVY_LOGGING_DEFAULT})
option(ENABLE_HEAVY_LOGGING "Should heavy debug logging be enabled" ${ENABLE_HEAVY_LOGGING_DEFAULT})
option(ENABLE_SHARED "Should libsrt be built as a shared library" ON)
option(ENABLE_STATIC "Should libsrt be built as a static library" ON)
option(ENABLE_SEPARATE_HAICRYPT "Should haicrypt be built as a separate library file" OFF)
option(ENABLE_SUFLIP "Shuld suflip tool be built" OFF)
option(ENABLE_SUFLIP "Should suflip tool be built" OFF)
option(USE_GNUTLS "Should use gnutls instead of openssl" OFF)
option(ENABLE_C_DEPS "Extra library dependencies in srt.pc for C language" OFF)
option(USE_STATIC_LIBSTDCXX "Should use static rather than shared libstdc++" OFF)
Expand Down
5 changes: 3 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ if { $argv == "--help" } {
puts stderr "\t$o$imark - $info($o)"
}

puts stderr "NOTE1: This is not the list of all options, see variables used in CMakeLists.txt"
puts stderr "NOTE2: You can use --disable-x instead of --enable-x=0 for the above options."
puts stderr "NOTE1: Option list may be incomplete. Refer to variables in CMakeLists.txt"
puts stderr "NOTE2: Non-internal options turn e.g. --enable-c++11 into cmake -DENABLE_CXX11=1"
puts stderr "NOTE3: You can use --disable-x instead of --enable-x=0 for the above options."

exit 1
}
Expand Down
157 changes: 52 additions & 105 deletions configure-data.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,40 @@
# - optval (array): contains all option names with their assigned values
# - cmakeopt (scalar): a list of all options for "cmake" command line


set options {
enable-shared "compile SRT parts as shared libraries (default: ON)"
enable-static "compile SRT parts as static libraries (default: ON)"
disable-c++11 "turn off parts that require C++11 support"
enable-debug "turn on debug+nonoptimized build mode (if =2, debug+optimized)"
enable-profile "turn on profile instrumentation"
enable-logging "turn on logging (not heavy debug logging) (default: ON)"
enable-heavy-logging "turn on heavy debug logging (default: OFF, ON in debug mode)"
# Options processed here internally, not passed to cmake
set internal_options {
with-compiler-prefix=<prefix> "set C/C++ toolchains <prefix>gcc and <prefix>g++"
with-compiler-type=<name> "compiler type: gcc(default), cc, others simply add ++ for C++"
with-openssl=<prefix> "Prefix for OpenSSL installation (adds include,lib)"
with-openssl-includedir=<incdir> "Use given path for OpenSSL header files"
with-openssl-libdir=<libdir> "Use given path for OpenSSL library path"
with-openssl-libraries=<files> "Use given file list instead of standard -lcrypto"
with-openssl-ldflags=<ldflags> "Use given -lDIR values for OpenSSL or absolute library filename"
with-pthread-includedir=<incdir> "Use extra path for pthreads (usually for Windows)"
with-pthread-ldflags=<flags> "Use specific flags for pthreads (some platforms require -pthread)"
use-gnutls "Use GNUTLS library instead of OpenSSL for cryptographic features"
with-srt-name=<name> "Override srt library name"
with-haicrypt-name=<name> "Override haicrypt library name (if compiled separately)"
enable-debug "turn on debug+nonoptimized build mode (if =2, debug+optimized)"
}

# Options that refer directly to variables used in CMakeLists.txt
set cmake_options {
cygwin-use-posix "Should the POSIX API be used for cygwin. Ignored if the system isn't cygwin. (default: OFF)"
enable-c++11 "Should the c++11 parts (srt-live-transmit) be enabled (default: ON)"
enable-c-deps "Extra library dependencies in srt.pc for C language (default: OFF)"
enable-heavy-logging "Should heavy debug logging be enabled (default: OFF)"
enable-logging "Should logging be enabled (default: ON)"
enable-profile "Should instrument the code for profiling. Ignored for non-GNU compiler. (default: OFF)"
enable-separate-haicrypt "Should haicrypt be built as a separate library file (default: OFF)"
enable-shared "Should libsrt be built as a shared library (default: ON)"
enable-static "Should libsrt be built as a static library (default: ON)"
enable-suflip "Shuld suflip tool be built (default: OFF)"
enable-thread-check "Enable #include <threadcheck.h> that implements THREAD_* macros"
openssl-crypto-library=<filepath> "Path to a library."
openssl-include-dir=<path> "Path to a file."
openssl-ssl-library=<filepath> "Path to a library."
pkg-config-executable=<filepath> "pkg-config executable"
pthread-include-dir=<path> "Path to a file."
pthread-library=<filepath> "Path to a library."
use-gnutls "Should use gnutls instead of openssl (default: OFF)"
use-static-libstdc++ "Should use static rather than shared libstdc++ (default: OFF)"
}

set options $internal_options$cmake_options

# Just example. Available in the system.
set alias {
--prefix --cmake-install-prefix=
Expand All @@ -70,6 +83,9 @@ proc flagval v {
return $out
}

set haicrypt_name ""
set srt_name ""

proc preprocess {} {

# Prepare windows basic path info
Expand Down Expand Up @@ -124,64 +140,17 @@ proc preprocess {} {
set ::target_path $::optval(--with-target-path)
unset ::optval(--with-target-path)
puts "NOTE: Explicit target path: $::target_path"
}

# # Now finally turn --with-compiler-prefix into cmake-c-compiler etc.
# set enforce_compiler 0
# set compiler ""
# if { [info exists ::optval(--with-compiler-type)] } {
# set compiler $::optval(--with-compiler-type)
# set enforce_compiler 1
#
# switch -- $compiler {
# gcc {
# set xcompiler g++
# }
#
# cc {
# set xcompiler c++
# }
#
# default {
# set xcompiler ${compiler}++
# }
# }
#
# } else {
# set compiler gcc
# set xcompiler g++
# }
#
# set px ""
# if { [info exists ::optval(--with-compiler-prefix)] } {
# set enforce_compiler 1
# set px $::optval(--with-compiler-prefix)
# unset ::optval(--with-compiler-prefix)
# }
#
# if { $enforce_compiler } {
#
# # If prefix path was not
# if { $px == "" } {
# set cmd [auto_execok $compiler]
# if { $cmd == "" } {
# puts "ERROR: --with-compiler-type: '$compiler' is not a command (add --with-compiler-prefix if not in PATH)"
# exit 1
# }
# set px [file dirname $cmd]/
# set cmd [auto_execok $xcompiler]
# if { $cmd == "" } {
# puts "ERROR: --with-compiler-type=$compiler, can't find correspoding C++ compiler '$xcompiler'"
# exit 1
# }
# set pxx [file dirname $cmd]/
# } else {
# set pxx $px
# }
#
# set ::optval(--cmake-c-compiler) ${px}${compiler}
# set ::optval(--cmake-c++-compiler) ${pxx}${xcompiler}
# }
}

if { "--with-srt-name" in $::optkeys } {
set ::srt_name $::optval(--with-srt-name)
unset ::optval(--with-srt-name)
}

if { "--with-haicrypt-name" in $::optkeys } {
set ::haicrypt_name $::optval(--with-haicrypt-name)
unset ::optval(--with-haicrypt-name)
}
}

proc GetCompilerCommand {} {
Expand Down Expand Up @@ -268,10 +237,16 @@ proc postprocess {} {
}
}

# Check if --with-openssl and the others are defined.
if { $::srt_name != "" } {
lappend ::cmakeopt "-DTARGET_srt=$::srt_name"
}

if { $::haicrypt_name != "" } {
lappend ::cmakeopt "-DTARGET_haicrypt=$::haicrypt_name"
}

set have_openssl 0
if { [lsearch -glob $::optkeys --with-openssl*] != -1 } {
if { [lsearch -glob $::optkeys --openssl*] != -1 } {
set have_openssl 1
}

Expand All @@ -289,11 +264,6 @@ proc postprocess {} {
lappend ::cmakeopt "-DUSE_GNUTLS=ON"
}

set have_pthread 0
if { [lsearch -glob $::optkeys --with-pthread*] != -1 } {
set have_pthread 1
}

if {$iscross} {

proc check-target-path {path} {
Expand Down Expand Up @@ -351,29 +321,6 @@ proc postprocess {} {
# Otherwise don't set PKG_CONFIG_PATH and we'll see.
}

# Autodetect OpenSSL and pthreads
if { $::HAVE_WINDOWS } {

if { !$have_openssl || !$have_gnutls } {
puts "Letting cmake detect OpenSSL installation"
} elseif { $have_gnutls } {
puts "Letting cmake detect GnuTLS installation"
} else {
puts "HAVE_OPENSSL: [lsearch -inline $::optkeys --with-openssl*]"
}


if { !$have_pthread } {
puts "Letting cmake detect PThread installation"
} else {
puts "HAVE_PTHREADS: [lsearch -inline $::optkeys --with-pthread*]"
}
}

if { $::HAVE_LINUX || $cygwin_posix } {
# Let cmake find openssl and pthread
}

if { $::HAVE_DARWIN } {

if { $have_gnutls } {
Expand Down
115 changes: 115 additions & 0 deletions scripts/generate-configure-options.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/tclsh

set cachefile [lindex $argv 0]

if { $cachefile == "" } {
puts stderr "Usage: [file tail $argv0] <existing CMakeCache.txt file>"
exit 1
}

set struct {
name
type
value
description
}

set fd [open $cachefile r]

set cached ""

set dbase ""

while {[gets $fd line] != -1 } {
set line [string trim $line]

# Hash comment
if { [string index $line 0] == "#" } {
continue
}

# empty line
if { $line == "" } {
set cached ""
continue
}

if { [string range $line 0 1] == "//" } {
set linepart [string range $line 2 end]
# Variable description. Add to cache.
if { $cached != "" && [string index $cached end] != " " && [string index $linepart 0] != " " } {
append cached " "
}
append cached $linepart
}

# Possibly a variable
if [string is alpha [string index $line 0]] {
# Note: this skips variables starting grom underscore.

if { [string range $line 0 5] == "CMAKE_" } {
# Skip variables with CMAKE_ prefix, they are internal.
continue
}

lassign [split $line =] vartype value
lassign [split $vartype :] var type

# Store the variable now
set storage [list $var $type $value $cached]
set cached ""
lappend dbase $storage

continue
}

#puts stderr "Ignored line: $line"

# Ignored.
}

# Now look over the stored variables

set lenlimit 80

foreach stor $dbase {

lassign $stor {*}$struct

if { [string length $description] > $lenlimit } {
set description [string range $description 0 $lenlimit-2]...
}

if { $type in {STATIC INTERNAL} } {
continue
}

# Check special case of CXX to turn back to c++.
set pos [string first CXX $name]
if { $pos != -1 } {
# Check around, actually after XX should be no letter.
if { $pos+3 >= [string length $name] || ![string is alpha [string index $name $pos+3]] } {
set name [string replace $name $pos $pos+2 C++]
}
}

set optname [string tolower [string map {_ -} $name]]

# Variables of type bool are just empty.
# Variables of other types must have =<value> added.
# Lowercase cmake type will be used here.
set optassign ""
set def ""
if { $type != "BOOL" } {
set optassign "=<[string tolower $type]>"
} else {
# Supply default for boolean option
set def " (default: $value)"
}

puts " $optname$optassign \"$description$def\""
}




0 comments on commit fcb5c70

Please sign in to comment.