Skip to content

Commit

Permalink
Merge pull request #179 from ethouris/dev-fix-restore-cross-depcheck
Browse files Browse the repository at this point in the history
Restored dep check for all cases. Add path autodetection and prefix supplying in configure.
  • Loading branch information
rndi authored Dec 4, 2017
2 parents 7638ced + 9b16757 commit b6fd2ae
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 52 deletions.
76 changes: 30 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,45 +113,31 @@ endif()
set_if(DARWIN ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_if(LINUX ${CMAKE_SYSTEM_NAME} MATCHES "Linux")

# In case when a crosscompiler is detected, do not require strictly
# to use OpenSSL - assume it's provided by the system. In such a case
# it's not possible to determine if OpenSSL is available; the below
# checking will see if OpenSSL is installed ON THE COMPILER SYSTEM,
# but this has nothing to do with having OpenSSL on the TARGET SYSTEM.
if (NOT HAVE_CROSSCOMPILER)

# find OpenSSL
if ( USE_GNUTLS )
pkg_check_modules (SSL REQUIRED gnutls nettle)

add_definitions(
-DUSE_GNUTLS=1
)

link_directories(
${SSL_LIBRARY_DIRS}
)
message(STATUS "SSL Dependency: using GNUTLS with Nettle, as requested")
else()
find_package(OpenSSL REQUIRED)
set (SSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
set (SSL_LIBRARIES ${OPENSSL_LIBRARIES})

add_definitions(
-DHAICRYPT_USE_OPENSSL_EVP=1
-DHAICRYPT_USE_OPENSSL_AES
)
message(STATUS "SSL Dependency: using OpenSSL (default)")
endif()
# When you use crosscompiling, you have to take care that PKT_CONFIG_PATH
# and CMAKE_PREFIX_PATH are set properly.

# find OpenSSL
if ( USE_GNUTLS )
pkg_check_modules (SSL REQUIRED gnutls nettle)

add_definitions(
-DUSE_GNUTLS=1
)

link_directories(
${SSL_LIBRARY_DIRS}
)
message(STATUS "SSL Dependency: using GNUTLS with Nettle, as requested")
else()
message(STATUS "SSL Dependency: CROSSCOMPILER detected, assuming OpenSSL is in the system.")
find_package(OpenSSL REQUIRED)
set (SSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
set (SSL_LIBRARIES ${OPENSSL_LIBRARIES})

add_definitions(
-DHAICRYPT_USE_OPENSSL_EVP=1
-DHAICRYPT_USE_OPENSSL_AES
)

set (SSL_LIBRARIES "-lcrypto")
message(STATUS "SSL Dependency: using OpenSSL (default)")
endif()

message (STATUS "SSL libraries: ${SSL_LIBRARIES}")
Expand Down Expand Up @@ -256,25 +242,23 @@ if (${ENABLE_PROFILE} AND HAVE_COMPILER_GNU_COMPAT)
link_libraries(-g -pg)
endif()

if (NOT HAVE_CROSSCOMPILER)

# find pthread
# find pthread
find_path(PTHREAD_INCLUDE_DIR pthread.h HINTS C:/pthread-win32/include)
if (PTHREAD_INCLUDE_DIR)
message(STATUS "Pthread include dir: ${PTHREAD_INCLUDE_DIR}")
else()
message(FATAL_ERROR "Failed to find pthread.h. Specify PTHREAD_INCLUDE_DIR.")
endif()
if (PTHREAD_INCLUDE_DIR)
message(STATUS "Pthread include dir: ${PTHREAD_INCLUDE_DIR}")
else()
message(FATAL_ERROR "Failed to find pthread.h. Specify PTHREAD_INCLUDE_DIR.")
endif()

find_library(PTHREAD_LIBRARY NAMES pthread pthread_dll pthread_lib HINTS C:/pthread-win32/lib)
if (PTHREAD_LIBRARY)
message(STATUS "Pthread library: ${PTHREAD_LIBRARY}")
else()
message(FATAL_ERROR "Failed to find pthread library. Specify PTHREAD_LIBRARY.")
endif()

if (PTHREAD_LIBRARY)
message(STATUS "Pthread library: ${PTHREAD_LIBRARY}")
else()
message(FATAL_ERROR "Failed to find pthread library. Specify PTHREAD_LIBRARY.")
endif()


# This is required in some projects that add some other sources
# to the SRT library to be compiled together (aka "virtual library").
if (DEFINED SRT_EXTRA_LIB_INC)
Expand Down
74 changes: 68 additions & 6 deletions configure-data.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ proc preprocess {} {
puts "WARNING: --with-gnutls is a deprecated alias to --use-gnutls, please use the latter one"
}

if { [info exists ::optval(--with-target-path)] } {
set ::target_path $::optval(--with-target-path)
unset ::optval(--with-target-path)
}

# # Now finally turn --with-compiler-prefix into cmake-c-compiler etc.
# set enforce_compiler 0
# set compiler ""
Expand Down Expand Up @@ -232,24 +237,26 @@ proc postprocess {} {
if { $toolchain_changed } {
# Check characteristics of the compiler - in particular, whether the target is different
# than the current target.
set compiler_path ""
set cmd [GetCompilerCommand]
if { $cmd != "" } {
set gcc_version [exec $cmd -v 2>@1]
set target ""
set compiler_path [file dirname $cmd]
foreach l [split $gcc_version \n] {
if { [string match Target:* $l] } {
set name [lindex $l 1] ;# [0]Target: [1]x86_64-some-things-further
set target [lindex [split $name -] 0] ;# [0]x86_64 [1]redhat [2]linux
set target [lindex $l 1] ;# [0]Target: [1]x86_64-some-things-further
set target_platform [lindex [split $target -] 0] ;# [0]x86_64 [1]redhat [2]linux
break
}
}

if { $target == "" } {
if { $target_platform == "" } {
puts "NOTE: can't obtain target from gcc -v: $l"
} else {
if { $target != $::tcl_platform(machine) } {
puts "NOTE: foreign target type detected ($target) - setting CROSSCOMPILING flag"
lappend ::cmakeopt "-DHAVE_CROSSCOMPILER=1"
if { $target_platform != $::tcl_platform(machine) } {
puts "NOTE: foreign target type detected ($target)" ;# - setting CROSSCOMPILING flag"
#lappend ::cmakeopt "-DHAVE_CROSSCOMPILER=1"
set iscross 1
}
}
Expand Down Expand Up @@ -278,6 +285,61 @@ proc postprocess {} {
set have_pthread 1
}

if {$iscross} {

proc check-target-path {path} {
puts "Checking path '$path'"
if { [file isdir $path]
&& [file isdir $path/bin]
&& [file isdir $path/include]
&& ([file isdir $path/lib] || [file isdir $path/lib64]) } {
return yes
}
return no
}

if { ![info exists ::target_path)] } {
# Try to autodetect the target path by having the basic 3 directories.
set target_path ""
set compiler_prefix [file dirname $compiler_path] ;# strip 'bin' directory
foreach path [list $compiler_path $compiler_prefix/$target] {
if { [check-target-path $path] } {
set target_path $path
puts "NOTE: target path detected: $target_path"
break
}
}

if { $target_path == "" } {
puts "ERROR: Can't determine compiler's platform files root path (using compiler command path). Specify --with-target-path."
exit 1
}
} else {
set target_path $::target_path
# Still, check if correct.
if { ![check-target-path $target_path] } {
puts "ERROR: path in --with-target-path does not contain typical subdirectories"
exit 1
}
puts "NOTE: Using explicit target path: $target_path"

# Prevent --with-target-path from being translated
unset ::optval(--with-target-path)
}

# Add this for cmake, should it need for something
lappend ::cmakeopt "-DCMAKE_PREFIX_PATH=$target_path"

# Add explicitly the path for pkg-config
# which lib
if { [file isdir $target_path/lib64/pkgconfig] } {
set env(PKG_CONFIG_PATH) $target_path/lib64/pkgconfig
} elseif { [file isdir $target_path/lib/pkgconfig] } {
set env(PKG_CONFIG_PATH) $target_path/lib/pkgconfig
}
# Otherwise don't set PKG_CONFIG_PATH and we'll see.
}

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

Expand Down

0 comments on commit b6fd2ae

Please sign in to comment.