Revision: 69944 http://sourceforge.net/p/brlcad/code/69944 Author: starseeker Date: 2017-07-15 03:27:44 +0000 (Sat, 15 Jul 2017) Log Message: ----------- See if we can avoid the separate builddir_cmd.cmake.in file - untested with MSVC (or for that matter Xcode - breakage is most likely in multiconfigs...
Modified Paths: -------------- brlcad/trunk/CMakeLists.txt brlcad/trunk/db/nist/CMakeLists.txt brlcad/trunk/misc/CMake/BRLCAD_Util.cmake Removed Paths: ------------- brlcad/trunk/misc/CMake/builddir_cmd.cmake.in Modified: brlcad/trunk/CMakeLists.txt =================================================================== --- brlcad/trunk/CMakeLists.txt 2017-07-14 19:51:43 UTC (rev 69943) +++ brlcad/trunk/CMakeLists.txt 2017-07-15 03:27:44 UTC (rev 69944) @@ -336,6 +336,34 @@ endif(BRLCAD_PREFIX) mark_as_advanced(CMAKE_SYSTEM_IGNORE_PATH) +#------------------------------------------------------------------------------ +# For multi-configuration builds, we frequently need to know the run-time build +# directory. Confusingly, we need to do different things for install commands +# and custom command definitions. To manage this, we define +# CMAKE_CURRENT_BUILD_DIR_SCRIPT and CMAKE_CURRENT_BUILD_DIR_INSTALL once at +# the top level, then use them when we need the configuration-dependent path. +# +# Note that neither of these will work when we need to generate a .cmake file +# that does runtime detection of the current build configuration. CMake +# scripts run using "cmake -P script.cmake" style invocation are independent of +# the "main" build system and will not know how to resolve either of the below +# variables correctly. In that case, the script itself must check the current +# file in CMakeTmp/CURRENT_PATH (TODO - need to better organize and document +# this mechanism, given how critical it is proving... possible convention will +# be to have the string CURRENT_BUILD_DIR in any path that needs the relevant +# logic in a script, and a standard substitution routine...) and set any +# necessary path variables accordingly. (TODO - make a standard function to do +# that the right way that scripts can load and use - right now that logic is +# scattered all over the code and if we wanted to change where those files went +# it would be a lot of work.) +if(CMAKE_CONFIGURATION_TYPES) + set(CMAKE_CURRENT_BUILD_DIR_SCRIPT "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}") + set(CMAKE_CURRENT_BUILD_DIR_INSTALL "${CMAKE_BINARY_DIR}/\${BUILD_TYPE}") +else(CMAKE_CONFIGURATION_TYPES) + set(CMAKE_CURRENT_BUILD_DIR_SCRIPT "${CMAKE_BINARY_DIR}") + set(CMAKE_CURRENT_BUILD_DIR_INSTALL "${CMAKE_BINARY_DIR}") +endif(CMAKE_CONFIGURATION_TYPES) + #--------------------------------------------------------------------- # For cleaning files as part of the distclean command, CMake needs # to be aware of what various generators will (or might) write out Modified: brlcad/trunk/db/nist/CMakeLists.txt =================================================================== --- brlcad/trunk/db/nist/CMakeLists.txt 2017-07-14 19:51:43 UTC (rev 69943) +++ brlcad/trunk/db/nist/CMakeLists.txt 2017-07-15 03:27:44 UTC (rev 69944) @@ -11,79 +11,84 @@ NIST_MBE_PMI_7-10.3dm ) -macro(ADD_NIST_STEP_TARGET step_model folder) +function(ADD_NIST_STEP_TARGET step_model folder) + + # Base output file name on input file string(REGEX REPLACE "([0-9a-z]*).stp" "\\1" step_model_root "${step_model}") - set(output_file ${bin_root}/${DATA_DIR}/db/${step_model_root}.g) + + # Define a relative output path - the quirks of CMake require this... + set(output_file ${DATA_DIR}/db/${step_model_root}.g) + + # One log file per target set(log_file ${CMAKE_CURRENT_BINARY_DIR}/${step_model_root}.log) + + # Define the target add_custom_command( - OUTPUT ${output_file} - COMMAND step-g -O ${output_file} ${CMAKE_CURRENT_SOURCE_DIR}/${step_model} > ${log_file} 2>&1 + OUTPUT ${CMAKE_CURRENT_BUILD_DIR_SCRIPT}/${output_file} + COMMAND step-g -O ${CMAKE_CURRENT_BUILD_DIR_SCRIPT}/${output_file} ${CMAKE_CURRENT_SOURCE_DIR}/${step_model} > ${log_file} 2>&1 DEPENDS step-g ${CMAKE_CURRENT_SOURCE_DIR}/${step_model} - ) - add_custom_target(${step_model_root}.g ALL DEPENDS ${output_file}) + ) + add_custom_target(${step_model_root}.g ALL DEPENDS ${CMAKE_CURRENT_BUILD_DIR_SCRIPT}/${output_file}) + + # Assign a target folder for tools like Visual Studio set_target_properties(${step_model_root}.g PROPERTIES FOLDER "${folder}") + + # If we're installing geometry, set up the install rule if(BRLCAD_INSTALL_EXAMPLE_GEOMETRY) - if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL "." AND CMAKE_CONFIGURATION_FILES) - string(REPLACE "${CMAKE_CFG_INTDIR}" "\${BUILD_TYPE}" output_file "${output_file}") - endif(NOT "${CMAKE_CFG_INTDIR}" STREQUAL "." AND CMAKE_CONFIGURATION_FILES) - install(FILES ${output_file} DESTINATION ${DATA_DIR}/db) + install(FILES ${CMAKE_CURRENT_BUILD_DIR_INSTALL}/${output_file} DESTINATION ${DATA_DIR}/db) endif(BRLCAD_INSTALL_EXAMPLE_GEOMETRY) - set(BUILT_MODELS "${BUILT_MODELS};${output_file}") - set(LOG_FILES "${LOG_FILES};${log_file}") + + # Cleanup + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BUILD_DIR_SCRIPT}/${output_file};${log_file}") DISTCLEAN(${log_file}) -endmacro(ADD_NIST_STEP_TARGET step_model folder) -# Get our root path -if(CMAKE_CONFIGURATION_TYPES) - set(bin_root "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}") -else(CMAKE_CONFIGURATION_TYPES) - set(bin_root "${CMAKE_BINARY_DIR}") -endif(CMAKE_CONFIGURATION_TYPES) +endfunction(ADD_NIST_STEP_TARGET step_model folder) -# The general pattern of the BRL-CAD build is to use CMAKE_CFG_INTDIR when -# multi-configuration builds complicate the location of binaries. In this -# case, however, we are using a generated script with a different mechanism -# for handling this situation, and we need to update the executable paths -# accordingly if they are configuration dependent. -if(CMAKE_CONFIGURATION_TYPES) - string(REPLACE "${CMAKE_CFG_INTDIR}" "\${BUILD_TYPE}" rbin_root "${bin_root}") -else(CMAKE_CONFIGURATION_TYPES) - set(rbin_root "${bin_root}") -endif(CMAKE_CONFIGURATION_TYPES) +function(ADD_NIST_3DM_TARGET rhino_model folder) -# Use the CMake executable to figure out if we need an extension -get_filename_component(EXE_EXT "${CMAKE_COMMAND}" EXT) + # Base output file name on input file + string(REGEX REPLACE "([0-9a-z]*).3dm" "\\1" rhino_model_root "${rhino_model}") + # Define a relative output path - the quirks of CMake require this... + set(output_file ${DATA_DIR}/db/${rhino_model_root}.g) -macro(ADD_NIST_3DM_TARGET rhino_model folder) - set(CMD_EXEC ${rbin_root}/${BIN_DIR}/3dm-g${EXE_EXT}) - string(REGEX REPLACE "([0-9a-z]*).3dm" "\\1" rhino_model_root "${rhino_model}") - set(output_file ${rbin_root}/${DATA_DIR}/db/${rhino_model_root}.g) + # Because we won't know the output directory in the script reliably until run time, + # we append CURRENT_BUILD_DIR as a string to the arguments - it is the script's + # responsibility to handle it correctly at run time. + set(CMD_ARGS "-o" "CURRENT_BUILD_DIR/${output_file}" "${CMAKE_CURRENT_SOURCE_DIR}/${rhino_model}") + + # One log file per target - we capture both stdout and stderror here set(log_file ${CMAKE_CURRENT_BINARY_DIR}/${rhino_model_root}.log) - set(STDOUT_LOG "${log_file}") - set(STDERR_LOG "${log_file}") - set(CMD_ARGS "-o \"${output_file}\" \"${CMAKE_CURRENT_SOURCE_DIR}/${rhino_model}\"") - configure_file(${BRLCAD_CMAKE_DIR}/builddir_cmd.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/3dm-g.cmake @ONLY) - set(output_file ${bin_root}/${DATA_DIR}/db/${rhino_model_root}.g) + + # Use the model name for the script as well, since the output file is specific to this input + set(script_file "${CMAKE_CURRENT_BINARY_DIR}/${rhino_model_root}.cmake") + + # We know enough - write the script + generate_cmd_script(3dm-g "${script_file}" OLOG "${log_file}" ELOG "${log_file}" CARGS "${CMD_ARGS}") + + # Define the target add_custom_command( - OUTPUT ${output_file} - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/3dm-g.cmake + OUTPUT ${CMAKE_CURRENT_BUILD_DIR_SCRIPT}/${output_file} + COMMAND ${CMAKE_COMMAND} -P "${script_file}" DEPENDS 3dm-g ${CMAKE_CURRENT_SOURCE_DIR}/${rhino_model} - ) - add_custom_target(${rhino_model_root}.g ALL DEPENDS ${output_file}) + ) + add_custom_target(${rhino_model_root}.g ALL DEPENDS ${CMAKE_CURRENT_BUILD_DIR_SCRIPT}/${output_file}) + + # Assign a target folder for tools like Visual Studio set_target_properties(${rhino_model_root}.g PROPERTIES FOLDER "${folder}") + + # If we're installing geometry, set up the install rule if(BRLCAD_INSTALL_EXAMPLE_GEOMETRY) - if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL "." AND CMAKE_CONFIGURATION_FILES) - string(REPLACE "${CMAKE_CFG_INTDIR}" "\${BUILD_TYPE}" output_file "${output_file}") - endif(NOT "${CMAKE_CFG_INTDIR}" STREQUAL "." AND CMAKE_CONFIGURATION_FILES) - install(FILES ${output_file} DESTINATION ${DATA_DIR}/db) + install(FILES ${CMAKE_CURRENT_BUILD_DIR_INSTALL}/${output_file} DESTINATION ${DATA_DIR}/db) endif(BRLCAD_INSTALL_EXAMPLE_GEOMETRY) - set(BUILT_MODELS "${BUILT_MODELS};${output_file}") - set(LOG_FILES "${LOG_FILES};${log_file}") + + # Cleanup + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BUILD_DIR_SCRIPT}/${output_file};${log_file}") DISTCLEAN(${log_file}) -endmacro(ADD_NIST_3DM_TARGET rhino_model folder) +endfunction(ADD_NIST_3DM_TARGET rhino_model folder) + foreach(step_input ${NIST_SAMPLE_STEP_MODELS}) ADD_NIST_STEP_TARGET(${step_input} "BRL-CAD Geometry Models/Sample") endforeach(step_input ${NIST_SAMPLE_STEP_MODELS}) @@ -95,9 +100,6 @@ CMAKEFILES(${NIST_SAMPLE_3DM_MODELS}) -set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${BUILT_MODELS}") -set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${LOG_FILES}") - CMAKEFILES( README pdf Modified: brlcad/trunk/misc/CMake/BRLCAD_Util.cmake =================================================================== --- brlcad/trunk/misc/CMake/BRLCAD_Util.cmake 2017-07-14 19:51:43 UTC (rev 69943) +++ brlcad/trunk/misc/CMake/BRLCAD_Util.cmake 2017-07-15 03:27:44 UTC (rev 69944) @@ -248,6 +248,56 @@ endif(TARGET ${tname}) endfunction(ADD_TARGET_DEPS tname) +#--------------------------------------------------------------------------- +# Write out an execution script to run commands with the necessary +# variables set to allow execution in the build directory, even if +# there are installed libraries present in the final installation +# directory. +function(generate_cmd_script cmd_exe script_file) + + cmake_parse_arguments(GCS "" "OLOG;ELOG" "CARGS" ${ARGN}) + + # Initialize file + file(WRITE "${script_file}" "# Script to run ${cmd_exe}\n") + + # Handle multiconfig (must be run-time determination for Visual Studio and XCode) + # TODO - logic writing this trick needs to become some sort of standard routine... + file(APPEND "${script_file}" "if(EXISTS \"${CMAKE_BINARY_DIR}/CMakeTmp/CURRENT_PATH/Release\")\n") + file(APPEND "${script_file}" " set(CBDIR \"${CMAKE_BINARY_DIR}/Release\")\n") + file(APPEND "${script_file}" "elseif(EXISTS \"${CMAKE_BINARY_DIR}/CMakeTmp/CURRENT_PATH/Debug\")\n") + file(APPEND "${script_file}" " set(CBDIR \"${CMAKE_BINARY_DIR}/Debug\")\n") + file(APPEND "${script_file}" "else(EXISTS \"${CMAKE_BINARY_DIR}/CMakeTmp/CURRENT_PATH/Release\")\n") + file(APPEND "${script_file}" " set(CBDIR \"${CMAKE_BINARY_DIR}\")\n") + file(APPEND "${script_file}" "endif(EXISTS \"${CMAKE_BINARY_DIR}/CMakeTmp/CURRENT_PATH/Release\")\n") + + # BRLCAD_ROOT is the hammer that makes certain we are running + # things found in the build directory + file(APPEND "${script_file}" "set(ENV{BRLCAD_ROOT} \"\${CBDIR}\")\n") + + # Substitute in the correct binary path anywhere it is needed in the args + file(APPEND "${script_file}" "string(REPLACE \"CURRENT_BUILD_DIR\" \"\${CBDIR}\" FIXED_CMD_ARGS \"${GCS_CARGS}\")\n") + + # Use the CMake executable to figure out if we need an extension + get_filename_component(EXE_EXT "${CMAKE_COMMAND}" EXT) + + # Write the actual cmake command to run the process + file(APPEND "${script_file}" "execute_process(COMMAND \"\${CBDIR}/${BIN_DIR}/${cmd_exe}${EXE_EXT}\" \${FIXED_CMD_ARGS} RESULT_VARIABLE CR OUTPUT_VARIABLE CO ERROR_VARIABLE CE)\n") + + # Log the outputs, if we are supposed to do that + if(GCS_OLOG) + file(APPEND "${script_file}" "file(APPEND \"${GCS_OLOG}\" \"\${CO}\")\n") + endif(GCS_OLOG) + if(GCS_ELOG) + file(APPEND "${script_file}" "file(APPEND \"${GCS_ELOG}\" \"\${CE}\")\n") + endif(GCS_ELOG) + + # Fail the command if the result was non-zero + file(APPEND "${script_file}" "if(CR)\n") + file(APPEND "${script_file}" " message(FATAL_ERROR \"\${CBDIR}/${BIN_DIR}/${cmd_exe}${EXE_EXT} failure: \${CR}\\n\${CO}\\n\${CE}\")\n") + file(APPEND "${script_file}" "endif(CR)\n") + +endfunction(generate_cmd_script) + # Local Variables: # tab-width: 8 # mode: cmake Deleted: brlcad/trunk/misc/CMake/builddir_cmd.cmake.in =================================================================== --- brlcad/trunk/misc/CMake/builddir_cmd.cmake.in 2017-07-14 19:51:43 UTC (rev 69943) +++ brlcad/trunk/misc/CMake/builddir_cmd.cmake.in 2017-07-15 03:27:44 UTC (rev 69944) @@ -1,78 +0,0 @@ -# B U I L D _ C M D . C M A K E . I N -# BRL-CAD -# -# Copyright (c) 2012-2016 United States Government as represented by -# the U.S. Army Research Laboratory. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# 3. The name of the author may not be used to endorse or promote -# products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS -# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -### - -# We need to be able to force libbu to use the build directory -# versions of plugins during build, in case there's already -# something in the install directory. -set(ENV{BRLCAD_ROOT} "@CMAKE_BINARY_DIR@") - -# Set BUILD_TYPE in case it is needed -if(EXISTS "@CMAKE_BINARY_DIR@/CMakeTmp/CURRENT_PATH/Release") - set(BUILD_TYPE Release) -elseif(EXISTS "@CMAKE_BINARY_DIR@/CMakeTmp/CURRENT_PATH/Debug") - set(BUILD_TYPE Debug) -else(EXISTS "@CMAKE_BINARY_DIR@/CMakeTmp/CURRENT_PATH/Release") - set(BUILD_TYPE) -endif(EXISTS "@CMAKE_BINARY_DIR@/CMakeTmp/CURRENT_PATH/Release") - -# Run Command -set(CMD_EXEC "@CMD_EXEC@") -set(CMD_ARGS @CMD_ARGS@) -execute_process(COMMAND "${CMD_EXEC}" ${CMD_ARGS} - RESULT_VARIABLE CMDRESULT OUTPUT_VARIABLE CMDOUT ERROR_VARIABLE CMDERR) - -# If we're supposed to put the output in log files, do that. -set(STDOUT_LOG "@STDOUT_LOG@") -set(STDERR_LOG "@STDERR_LOG@") -if(STDOUT_LOG) - file(APPEND "${STDOUT_LOG}" "${CMDOUT}") -endif(STDOUT_LOG) -if(STDERR_LOG) - file(APPEND "${STDERR_LOG}" "${CMDERR}") -endif(STDERR_LOG) - -if(CMDRESULT) - message(FATAL_ERROR "${CMD_EXEC} failure: ${CMDRESULT}\n${CMDOUT}\n${CMDERR}") -endif(CMDRESULT) - - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 - 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