Revision: 75895
http://sourceforge.net/p/brlcad/code/75895
Author: starseeker
Date: 2020-05-23 17:01:14 +0000 (Sat, 23 May 2020)
Log Message:
-----------
Make another try at detecting the Tcl/Tk graphics system. Tk's API doesn't let
us get at the info without doing a Tk_Init, which won't succeed in headless
configurations as we can't initialize a window. This is a hard problem since
Tk provides not proper way to do it - even building a program against libtk.so
doesn't work as the lower level library calls that might let us get directly at
the needed information are marked static. So we instead try to read the
information directly out of the TK_LIBRARY's printable strings - Tk stores the
windowingsystem command output as a string, so in princple it is there for us
to find.
Modified Paths:
--------------
brlcad/branches/bioh/misc/CMake/CMakeLists.txt
brlcad/branches/bioh/src/other/CMakeLists.txt
Added Paths:
-----------
brlcad/branches/bioh/misc/CMake/wsysstring.cpp
Modified: brlcad/branches/bioh/misc/CMake/CMakeLists.txt
===================================================================
--- brlcad/branches/bioh/misc/CMake/CMakeLists.txt 2020-05-23 16:59:56 UTC
(rev 75894)
+++ brlcad/branches/bioh/misc/CMake/CMakeLists.txt 2020-05-23 17:01:14 UTC
(rev 75895)
@@ -95,6 +95,7 @@
multiconfig_path_read.cmake.in
source_archive_setup.cmake.in
tcltest.tcl.in
+ wsysstring.cpp
)
CMAKEFILES(${cmake_ignore_files})
Added: brlcad/branches/bioh/misc/CMake/wsysstring.cpp
===================================================================
--- brlcad/branches/bioh/misc/CMake/wsysstring.cpp
(rev 0)
+++ brlcad/branches/bioh/misc/CMake/wsysstring.cpp 2020-05-23 17:01:14 UTC
(rev 75895)
@@ -0,0 +1,86 @@
+#include <fstream>
+#include <iostream>
+#include <cstring>
+#include <string>
+
+int
+main(int argc, const char *argv[])
+{
+ bool have_x11 = false;
+ bool have_win32 = false;
+ bool have_aqua = false;
+
+ if (argc != 2) {
+ std::cerr << "Usage: wsysstring <file>\n";
+ return -1;
+ }
+
+ std::string sfile;
+ std::ifstream lib;
+ lib.open(argv[1]);
+ if (!lib.is_open()) {
+ std::cerr << "Unable to open file" << argv[1] << "\n";
+ return -1;
+ }
+
+ lib.seekg(0, std::ios::end);
+ size_t llen = lib.tellg();
+ lib.seekg(0, std::ios::beg);
+ std::string lcontent;
+ lcontent.reserve(llen);
+ char buff[16384]; // 2^14
+ std::streamsize ss;
+ while (lib.read(buff, sizeof buff), ss = lib.gcount()) {
+ lcontent.append(buff, ss);
+ }
+
+ // Have contents, find any printable substrings and check them
+ size_t cpos = 0;
+ std::string cstr;
+ while (cpos < lcontent.length()) {
+ char c = lcontent[cpos];
+ if (isprint(c)) {
+ cstr.push_back(c);
+ } else {
+ // Hit a non-printable - if we have a cstr, work it
+ // and reset
+ if (cstr.length() > 2) {
+ if (cstr == std::string("x11")) {
+ have_x11 = true;
+ }
+ if (cstr == std::string("win32")) {
+ have_win32 = true;
+ }
+ if (cstr == std::string("aqua")) {
+ have_aqua = true;
+ }
+ }
+ cstr.clear();
+ }
+ cpos++;
+ }
+
+ int mcnt = 0;
+ mcnt += have_x11;
+ mcnt += have_win32;
+ mcnt += have_aqua;
+ if (mcnt > 1) return -1;
+
+ if (mcnt == 1) {
+ if (have_x11) std::cout << "x11\n";
+ if (have_win32) std::cout << "win32\n";
+ if (have_aqua) std::cout << "aqua\n";
+ return 1;
+ }
+
+ return 0;
+}
+
+// Local Variables:
+// tab-width: 8
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// c-file-style: "stroustrup"
+// End:
+// ex: shiftwidth=4 tabstop=8
Property changes on: brlcad/branches/bioh/misc/CMake/wsysstring.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: brlcad/branches/bioh/src/other/CMakeLists.txt
===================================================================
--- brlcad/branches/bioh/src/other/CMakeLists.txt 2020-05-23 16:59:56 UTC
(rev 75894)
+++ brlcad/branches/bioh/src/other/CMakeLists.txt 2020-05-23 17:01:14 UTC
(rev 75895)
@@ -455,18 +455,44 @@
set(HAVE_TK_H 1)
- # Packages probably still need to know the system graphics package
- if (NOT WIN32)
- if (APPLE AND TK_ENABLE_AQUA)
- set(TK_SYSTEM_GRAPHICS aqua)
- else ()
- set(TK_SYSTEM_GRAPHICS x11)
- endif (APPLE AND TK_ENABLE_AQUA)
- else (NOT WIN32)
- set(TK_SYSTEM_GRAPHICS win32)
- endif (NOT WIN32)
- set(TK_SYSTEM_GRAPHICS "${TK_SYSTEM_GRAPHICS}" CACHE STRING "Tk system
graphics type" FORCE)
+ # Packages probably still need to know the system graphics package.
Unfortunately
+ # it is not possible to run tclsh or wish to use the [tk windowingsystem]
command
+ # to extract this information on a system without the ability to launch a
graphics
+ # window successfully - Tk initialization will fail, and thus the command
fails,
+ # even though we don't actually need the window. There is no other reliable
+ # runtime way to use tclsh or wish to identify the system graphics system.
+ #
+ # In lieu of this, we look instead in the printiable strings of the Tk
library
+ # for the "win32", "aqua", or "x11" strings (or, if necessary, we will add
additional
+ # string checks.) This is not ideal, but there appears to be no other way
to learn
+ # what we want to know.
+ try_compile(WSYS_BUILD ${CMAKE_BINARY_DIR}/CMakeTmp
${BRLCAD_CMAKE_DIR}/wsysstring.cpp
+ OUTPUT_VARIABLE WSYS_MSG
+ COPY_FILE
${CMAKE_BINARY_DIR}/CMakeTmp/wsysstring${CMAKE_EXECUTABLE_SUFFIX})
+
+ if (NOT WSYS_BUILD)
+ message(FATAL_ERROR "Could not build wyssstring checker to test Tcl/Tk
windowing system: ${WSYS_MSG}")
+ endif (NOT WSYS_BUILD)
+
+ execute_process(COMMAND
${CMAKE_BINARY_DIR}/CMakeTmp/wsysstring${CMAKE_EXECUTABLE_SUFFIX} ${TK_LIBRARY}
+ RESULT_VARIABLE WSYS_TEST
+ OUTPUT_VARIABLE WSYS_VAL
+ )
+
+ if (WSYS_TEST EQUAL -1)
+ message(FATAL_ERROR "Tcl/Tk windowing system test failed")
+ endif (WSYS_TEST EQUAL -1)
+
+ string(REPLACE "\n" "" WSYS_VAL "${WSYS_VAL}")
+ if (BRLCAD_ENABLE_AQUA AND NOT "${WSYS_VAL}" STREQUAL "aqua")
+ message(FATAL_ERROR "Aqua build requested, but Tk graphics system is
\"${WSYS_VAL}\". Please direct FindTCL.cmake to a different Tcl/Tk
installation to use Aqua.")
+ endif (BRLCAD_ENABLE_AQUA AND NOT "${WSYS_VAL}" STREQUAL "aqua")
+
+ set(TK_SYSTEM_GRAPHICS "${WSYS_VAL}" CACHE STRING "Tk system graphics type"
FORCE)
+
+ message("TK_SYSTEM_GRAPHICS: ${TK_SYSTEM_GRAPHICS}")
+
else(BRLCAD_TK_BUILD)
# If we're not using Tk, make sure the variables are empty - CMake won't be
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits