In JetBrains IDEs (e.g. CLion, IntelliJ), external tools cannot use globbing patterns - bash

I added an external tool to CLion with the following details:
Program: zip
Parameters: asm.zip *.cc *.h
Working directory: $ProjectFileDir$
When I run this external tool as part of my build command, it says:
zip asm.zip *.cc *.h
zip warning: name not matched: *.cc
zip warning: name not matched: *.h
zip error: Nothing to do! (asm.zip)
Process finished with exit code 12
But when I replace the details with:
Program: ls
Parameters:
Working directory: $ProjectFileDir$
Then the output is the list of files in the project folder (which includes .cc and .h files) and the build completes successfully. What am I doing wrong?

Clion invokes the command you run directly, without expanding globs (* character).
Modify the settings to, eg.:
Program: sh
Parameters: -c "zip asm.zip *.cc *.h"
This way, the sh shell will correctly expand the arguments.

Related

Creating an archive with CMake at a location that I choose

I'm trying to learn how to create archives with CMake. I wrote this piece of code:
cmake_minimum_required(VERSION 3.5.1)
project(hello)
message("Creating archieve in: " ${CMAKE_CURRENT_BINARY_DIR})
message("Source dir is: " ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(hello main.cpp)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(create_tar ALL COMMAND
${CMAKE_COMMAND} -E tar "cfvz" "archieve.tgz")
add_dependencies(create_tar hello)
My project structure is like this:
I have a main folder in which I have a CMakeLists.txt, a main.cpp and a build folder. I go into build and run the cmake file above by 'cmake ..' and then make. My archive is created in the build folder but as you can see I have specified that I want it in the CMAKE_CURRENT_SOURCE_DIR which is along with the main, cmakelists and build folder not in the actual build folder.
Please explain to me why is that happening and how can I make the archive be created in the CMAKE_CURRENT_SOURCE_DIR and not CMAKE_CURRENT_BINARY_DIR. Thanks.
Turning my comment into an answer
That would be WORKING_DIRECTORY parameter of the add_custom_target() command:
add_custom_target(
create_tar ALL
COMMAND ${CMAKE_COMMAND} -E tar cfvz "archieve.tgz"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
The CMAKE_ARCHIVE_OUTPUT_DIRECTORY is for changing the output directory of add_library(... STATIC ...)` targets.
And you can either run the cmake -E tar either the correct (sub-)directory by changing the WORKING_DIRECTORY accordingly (like "${CMAKE_CURRENT_SOURCE_DIR}/Dir") or give a list of files after -- command line option (see documentation of CMake Command Line Tool Mode).

How to Run PC-Lint on only locally modified files(Not commited on Server of SVN)

I am trying to write script to run PC-Lint Static analyzer tool on only locally modified files by user and not on whole project.
For that I need to run Lint command on all locally modified files
using svn status
svn status -u | grep -w M
command I get list of locally modified files with its full path
For Example if locally modified file is asn1_common_elements.c, the above svn command will give output as
M 10014 \Implementations\asn1der\src\asn1_common_elements.c
now I need to take only filename asn1_common_elements.c and put it with LINT command as LINT asn1_common_elements.log (instead of .c need to change to .log)
How can I achieve this?
You could use a Makefile's ability to only let the compiler to compile only the changed files.
Do something like this in the Makefile:
# Create object from C source code
file.o: file.c
gcc -c $(CFLAGS) -o $#
wine lint-nt.exe file.c
Now the file.c will get analysed only when it is changed.

Error fatal - No such file or directory

I have installed the cds library with command ./build.sh -b 64 -z '-std=c++0x' -l '-L /usr/lib/x86_64-linux-gnu' --with-boost /usr/include/boost --amd64-use-128bit at build folder.
After I tried to compile the example init.cpp of src folder, I typed this in terminal: g++ init.cpp -o init, and terminal showed: fatal error: cds/init.h: No such file or directory.
What should I do for compilation command in this case?
Thanks.
For general troubleshooting in cases like this, i would recommend finding where on the system the file got installed (if your build.sh actually installed the file). You would be able to find the missing header file using
find / -path '*/cds/init.h' 2>/dev/null
Then you need to supply two parameters to g++:
First one gets the compiler to know about the include files from the install directory
-I path_to_folder_one_step_above_cds_folder
Second one gets the linker to know about the librarys location. If the library file is called libcds.so, you can find it by running
find / -name libcds.so 2>/dev/null
So for linking, you supply the flag
-L path_to_folder_one_step_above_libcds.so
In your case you might not need the -L flag, since most of your library supposedly is header only.
UPDATE: the build.sh script is printing out important information at the top, starting with "Building with the following options:". The important bits will be "Compile options:" and "Link options:". Those should be enough to solve your specific option.
UPDATE2: build.sh also exports some flags which might include more options. You can print them out directly after running build.sh by running
echo LDFLAGS=$LDFLAGS
echo CFLAGS=$CFLAGS
echo CXXFLAGS=$CXXFLAGS
you are likely to need to pass all these options to g++ when compiling and linking against that library. LDFLAGS are specific to the linker only. Both the other ones are needed for compiling c++ files.

gfortran returns `*.f90: No such file or directory` when compiling multiple files

I have a folder with 354 .f90 modules (and the main file). In the readme this is suggested:
The best approach is to unzip the archive source.zip extracting all
354 program files into a directory of your choice. Then you can
compile with the command
gfortran *.f90 -o app.exe
I'm on Mac so i installed gfortran but doing the command written above doesn't work:
gfortran: *.f90: No such file or directory
So I suppose that a bash script is needed (or at least a makefile).
I'm not used to doing this so what should I do? Does there exist some automatic makefile generator?
It was just a stupidity issue. The extension of the files was .F90 and not .f90. With:
gfortran -o app *.F90
it worked.

How can CMake be used to generate Makefiles with personalized commands?

I like to keep my Makefiles flexible and multifunctional. One of the tasks I usually add to make command is tar, for example the following instruction does the job:
tar:
tar -cvf $(PROGNAME).tar $(SRCS) Makefile
My question is: How can CMake be used to generate personalized commands like tar?
I would like to see some code samples.
For the full functionality it would be useful to create project's components and be able to use them as parameters.
(Exempli gratia: archive only header files or some specific library).
Thanks in advance for your answers!
The literal translation of your tar example would be:
ADD_CUSTOM_TARGET(tar
tar -cvf ${CMAKE_CURRENT_BINARY_DIR}/${PROGNAME}.tar ${SRCS} Makefile
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
This adds a new target "tar" that always executes the given command whenever it is requested as a command line target, i.e. whenever you run make tar it will create a new tar file. The WORKING_DIRECTORY argument will ensure that the source files are taken from the source directory, while CMAKE_CURRENT_BINARY_DIR ensures the output goes in the current build directory.
A slightly better iteration would be to replace tar with ${CMAKE_COMMAND} -E tar, as this doesn't depend on the command line tar program being available. So something like this would tar up all the header files when you run make tar:
SET(HEADER_FILES my.h another.h)
SET(PROGNAME myprog)
ADD_CUSTOM_TARGET(tar ${CMAKE_COMMAND} -E tar -czvf
${CMAKE_CURRENT_BINARY_DIR}/${PROGNAME}.tar.gz ${HEADER_FILES}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
An even better iteration would be to use the CPack features to create source or binary tar files, but that's quite a bit more work and may not be what you need anyway.

Resources