Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better code to pass all arguments of cmake function to execute_process #419

Open
xdelaruelle opened this issue Sep 26, 2021 · 2 comments
Open

Comments

@xdelaruelle
Copy link
Member

Current CMake code that defines the module command could be improved to handle better the arguments that the function receives. In current code there is a test on the number of arguments to call the execute_process CMake command with the ARGVX variables specifically set:

function(module)
   cmake_policy(SET CMP0007 NEW)
   set(_mlstatus TRUE)
   execute_process(COMMAND mktemp -t moduleinit.cmake.XXXXXXXXXXXX
      OUTPUT_VARIABLE tempfile_name
      OUTPUT_STRIP_TRAILING_WHITESPACE)
   if(${ARGC} EQUAL 1)
      execute_process(COMMAND /usr/bin/tclsh /path/to/modules/modulecmd.tcl cmake "${ARGV0}"
         OUTPUT_FILE ${tempfile_name})
   elseif(${ARGC} EQUAL 2)
      execute_process(COMMAND /usr/bin/tclsh /path/to/modules/modulecmd.tcl cmake "${ARGV0}" "${ARGV1}"
         OUTPUT_FILE ${tempfile_name})
   elseif(${ARGC} EQUAL 3)
      execute_process(COMMAND /usr/bin/tclsh /path/to/modules/modulecmd.tcl cmake "${ARGV0}" "${ARGV1}" "${ARGV2}"
         OUTPUT_FILE ${tempfile_name})
   elseif(${ARGC} EQUAL 4)
      execute_process(COMMAND /usr/bin/tclsh /path/to/modules/modulecmd.tcl cmake "${ARGV0}" "${ARGV1}" "${ARGV2}" "${ARGV3}"
         OUTPUT_FILE ${tempfile_name})
   else()
      execute_process(COMMAND /usr/bin/tclsh /path/to/modules/modulecmd.tcl cmake ${ARGV}
         OUTPUT_FILE ${tempfile_name})
   endif()
   if(EXISTS ${tempfile_name})
      include(${tempfile_name})
      file(REMOVE ${tempfile_name})
   endif()
   set(module_result ${_mlstatus} PARENT_SCOPE)
endfunction(module)

Someone with better CMake skills may find a simpler code to call execute_process with the arguments passed to the module function.

To change the module function definition, update the renderAutoinit procedure in the tcl/envmngt.tcl.in file.

To check the produced module function definition:

$ make modulecmd.tcl
$ ./modulecmd.tcl cmake autoinit

Then to test if this code is performing correctly:

$ make testinstall
@nkilm
Copy link

nkilm commented Oct 8, 2022

At present, the number of arguments is hardcoded and checked using if condition. So the function has to be modified such that it should be able execute variable number of commands provided via arguments?

@xdelaruelle
Copy link
Member Author

@nkilm Function has to be modified such that it should be able to execute a command with a variable number of arguments provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants