CMake add_custom_target COMMAND find files and exec [duplicate] - cmake

This question already has an answer here:
How to use find -exec in CMake execute_process?
(1 answer)
Closed 1 year ago.
I have a .cmake file and I have a custom target in which I need to add a command to find and sign apk files. I do the following:
add_custom_target(${APK_BUILD_TARGET} ALL
COMMAND find ${APK_DIR} -name "*.apk" -exec jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore myKey.keystore -storepass myStorePass -keypass myKeyPass {} myName \;
)
I keep getting the error
find: missing argument to `-exec'
If I execute the command alone, in a console, it works fine. I have the same problem with a simple echo command:
COMMAND find ${APK_DIR} -name "*.apk" -exec echo {} \;
I assume something is missing when doing that in COMMAND of add_custom_target, but what?
EDIT:
This work for echo command but not for jarsigner which still gives the previous error:
COMMAND find ${APK_DIR} -name "*.apk" -exec echo {} +

Following this post
How to use find -exec in CMake execute_process?
I finally got the correct command line:
add_custom_target(${APK_BUILD_TARGET} ALL
COMMAND find ${APK_DIR} -name "*.apk" -exec jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore myKey.keystore -storepass myStorePass -keypass myKeyPass {} myName "\;"
)
So with "\;" instead of just \;

Related

open certmgr from command line and save cert to c:directory

I'am trying to export certificates from my personal store to c:drive location using certmgr in script
Does someone know what the command is, or can send me to some website. Thanks alot..
CertMgr /s /r CurrentUser my /put cert1.cer /s /r C:\
The following command saves a certificate with the common name myCert in the my system store to a file called newCert.cer. (certmgr command is certmgr.exe instead of certmgr.msc)
certmgr /add /c /n myCert /s my newCert.cer
Please refer to the below link.
https://learn.microsoft.com/en-us/dotnet/framework/tools/certmgr-exe-certificate-manager-tool
Besides, we could refer to the below Powershell cmdlet, which can export a certificate to a file, the difference between these commands is whether the private key and some other extended properties are exported.
https://learn.microsoft.com/en-us/powershell/module/pkiclient/export-certificate?view=win10-ps
https://learn.microsoft.com/en-us/powershell/module/pkiclient/export-pfxcertificate?view=win10-ps
Here is an example of exporting a certificate to a PFX file.
$mypwd = ConvertTo-SecureString -String "1234" -Force -AsPlainText
Get-ChildItem -Path cert:\localMachine\my\5F98EBBFE735CDDAE00E33E0FD69050EF9220254 | Export-PfxCertificate -FilePath C:\mypfx.pfx -Password $mypwd

Multi-line command execution over remote SSH

I want to execute multiple lines of shell commands over remote ssh.
According to https://unix.stackexchange.com/questions/1459/remote-for-loop-over-ssh, I just need to use single quotes to execute a multi-line for loop. Here is what I tried:
ssh user#server ‘cd ~/Data; cwd=pwd; for i in `find 201806 -name "day_*"`; do echo $i; cd $i; a.sh; cd $cwd; done’
Since nothing happens, I am speculating that there is a syntax error that I must not be understanding. 201806 is the name of a folder in the Data directory, and I have tested that the command works without the ssh user#server. Any suggestions?
Try this
ssh -v user#server ‘cd ~/Data; cwd=`pwd`; for i in `find 201806 -name "day_*"`; do echo $i; cd $i; ./a.sh; cd $cwd; done’
Also, make sure your a.sh file have execute permission. -v option will give debugging messages about its progress.

How can I delete only the last five users of a OU with the command dsrm?

I have to delete only the last five users of a OU using a script with the command dsrm on Windows Server 2016
The only way I found is to add the users manually but I would like to know if it's possible to do it with a command or something (using a script).
This is what I have:
dsrm -noprompt -c "cn=rallendem,ou=GruposIvanov,ou=DAMivanov,dc=IvanovD16,dc=local"
dsrm -noprompt -c "cn=mpitarchs,ou=GruposIvanov,ou=DAMivanov,dc=IvanovD16,dc=local"
dsrm -noprompt -c "cn=mrosilloa,ou=GruposIvanov,ou=DAMivanov,dc=IvanovD16,dc=local"
dsrm -noprompt -c "cn=vmanuelp,ou=GruposIvanov,ou=DAMivanov,dc=IvanovD16,dc=local"
dsrm -noprompt -c "cn=vmesasa,ou=GruposIvanov,ou=DAMivanov,dc=IvanovD16,dc=local"

Ask the compiler to ignore #pragma message

As said in the title, I want the compiler to ignore pragma message for the time being, so it's easier for me to read and fix actual warnings. I've done some searching, but there doesn't seem to be any information on it.
No it isn't possible, so the best thing to do would be to mass-edit all the #pragmas out:
$ cd MySourceFolder
$ find . -name \*.m -exec perl -p -i -n -e 's/^#pragma/\/\/#pragma/' {} \;
When you want the #pragma's back again:
$ cd MySourceFolder
$ find . -name \*.m -exec perl -p -i -n -e 's/^\/\/#pragma/#pragma/' {} \;
If you do this kind of thing alot, I would wrap that in a script, and put it into your ~/bin directory.

CMake: How to output semicolon (;) as command options in ADD_CUSTOM_TARGET

Suppose I have the following CMake snippet:
MACRO(ADD_CUSTOM_TARGET_COMMAND tag OUTPUT file)
ADD_CUSTOM_TARGET(tag
${ARGN}
)
ADD_CUSTOM_TARGET(OUTPUT file
${ARGN}
)
ENDMACRO()
ADD_CUSTOM_TARGET_COMMAND(tag
OUTPUT file
COMMAND git tag -a -m "${msg}" 1.0.0 HEAD
VERBATIM
)
If msg contains semicolon such as "msg1;msg2", then the actual command is expanded to
git -a -m "msg1" "msg2" 1.0.0. HEAD
which leads to a syntax error.
I have tried to use \ to escape the ; but to no avail.
What should I do?
There is a special token since 2.8.11 version: $<SEMICOLON> (http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:add_custom_command).
I use it for example for such find command:
find /path/to/search -name some\*name \! -path excluded\*Pattern -exec ln -sf "{}" \;
the following way:
set(
FIND_ARGUMENTS
"${SEARCH_PATH} -name some\\*name \\! -path exclued\\*Pattern -exec ln -sf {} \\$<SEMICOLON>"
)
separate_arguments(FIND_ARGUMENTS)
add_custom_command(TARGET ${PROJECT}
POST_BUILD
COMMAND "find" ${FIND_ARGUMENTS}
WORKING_DIRECTORY ${WORKING_PATH}
)
Note that with separate_arguments VERBATIM parameter for add_custom_command is not needed.
CMake manages list using semi-colon, so I see no better way than just writing the message to file and git tag -F file