Revision: 69960 http://sourceforge.net/p/brlcad/code/69960 Author: starseeker Date: 2017-07-17 02:32:54 +0000 (Mon, 17 Jul 2017) Log Message: ----------- Consolidate and simplify the username reporting logic
Modified Paths: -------------- brlcad/trunk/CMakeLists.txt Removed Paths: ------------- brlcad/trunk/misc/CMake/test_srcs/report_username.c.in Modified: brlcad/trunk/CMakeLists.txt =================================================================== --- brlcad/trunk/CMakeLists.txt 2017-07-16 22:08:08 UTC (rev 69959) +++ brlcad/trunk/CMakeLists.txt 2017-07-17 02:32:54 UTC (rev 69960) @@ -2677,16 +2677,38 @@ DISTCLEAN("${BRLCAD_HOSTNAME_FILE}") # USER -set(BRLCAD_USERNAME_FILE "${BRLCAD_BINARY_DIR}/CMakeTmp/BRLCAD_BUILD_USER") -configure_file("${BRLCAD_CMAKE_DIR}/test_srcs/report_username.c.in" "${CMAKE_BINARY_DIR}/CMakeTmp/report_username.c") -TRY_RUN(TIME_RESULT TIME_COMPILED - "${CMAKE_BINARY_DIR}/CMakeTmp" +set(report_username_src " +#include <stdio.h> +#include <stdlib.h> +#ifdef HAVE_UNISTD_H + #include <unistd.h> +#endif +int main(void) { + char *name = getenv(\"USERNAME\"); + if (!name) name = getenv(\"USER\"); + if (!name) name = \"unknown\"; + printf(\"%s\", name); + return 0; +}") +file(WRITE "${CMAKE_BINARY_DIR}/CMakeTmp/report_username.c" "${report_username_src}") +# Add definition HAVE_UNISTD_H to try_run +if(HAVE_UNISTED_H) + set(UNISTED_DEF "-DHAVE_UNISTED_H") +endif(HAVE_UNISTED_H) +try_run(RU_RESULT RU_COMPILED "${CMAKE_BINARY_DIR}/CMakeTmp" "${CMAKE_BINARY_DIR}/CMakeTmp/report_username.c" - OUTPUT_VARIABLE COMPILEMESSAGES) -# Let CMake give us the proper newline character(s) for the current platform -file(READ "${BRLCAD_USERNAME_FILE}" BRLCAD_COMPILE_USER) + COMPILE_DEFINITIONS "${UNISTED_DEF}" + COMPILE_OUTPUT_VARIABLE RU_COMPILE_MSGS + RUN_OUTPUT_VARIABLE BRLCAD_COMPILE_USER) +if(NOT RU_COMPILED) + message(FATAL_ERROR "Could not build username reporting utility: ${RU_COMPILE_MSGS}") +endif(NOT RU_COMPILED) +if(RU_RESULT) + message(FATAL_ERROR "Could not run username reporting utility: ${BRLCAD_COMPILE_USER}") +endif(RU_RESULT) string(STRIP ${BRLCAD_COMPILE_USER} BRLCAD_COMPILE_USER) -DISTCLEAN("${BRLCAD_USERNAME_FILE}") +message("BRLCAD_COMPILE_USER: ${BRLCAD_COMPILE_USER}") +file(REMOVE "${CMAKE_BINARY_DIR}/CMakeTmp/report_username.c") #--------------------------------------------------------------------- # We now have everything we need - configure files Deleted: brlcad/trunk/misc/CMake/test_srcs/report_username.c.in =================================================================== --- brlcad/trunk/misc/CMake/test_srcs/report_username.c.in 2017-07-16 22:08:08 UTC (rev 69959) +++ brlcad/trunk/misc/CMake/test_srcs/report_username.c.in 2017-07-17 02:32:54 UTC (rev 69960) @@ -1,20 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#ifdef _WIN32 - #define USERVAR "USERNAME" -#else - #include <unistd.h> - #define USERVAR "USER" -#endif -#define chararraysize 2048 -int main(void) { - FILE *outfp = NULL; - char *name = getenv(USERVAR); - outfp = fopen("@BRLCAD_USERNAME_FILE@", "w"); - if (!name) - name = "unknown"; - printf("user name: %s\n", name); - fprintf(outfp, "%s", name); - fclose(outfp); - return 0; -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits