I'm trying to use the NPM copyfiles package, which I used many times. But I'm trying to copy the content of a dist folder in a destination folder without creating a dist but I can't find the correct way of doing it. I basically just want the content of the dist (not the folder in itself).
So what I have is
-- dist
|
-- bundles
-- lib
package.json
I want this result
-- destination
|
-- bundles
-- lib
package.json
but I always get the dist in the destination which is unwanted
-- destination
|
-- dist
|
-- bundles
-- lib
package.json
I tried
cross-env copyfiles dist/**/*.* ../dest
I also tried with the --up 1
cross-env copyfiles --up 1 dist/**/*.* ../dest
The only thing that works is with the -f (flatten) flag but I lose the folder structure.
cross-env -f copyfiles dist/**/*.* ../dest
Am I missing something or is it just not possible?
Firstly, given the examples shown in your question there is no need to use copyfiles with the additional package cross-env. The package copyfiles will work cross platforms.
cross-env is used for setting and using environment variables, e.g. NODE_ENV=production.
Using the --up 1 argument, (or its shorthand equivalent -u 1), with copyfiles is the correct way to omit the dist directory. So just use the following instead:
copyfiles --up 1 dist/**/*.* ../dest
I.e. remove the initial cross-env part to resolve the issue.
Got this working with ncp npm package.
ncp ./dist/ dest --filter **/*.*
Related
I have the following directory structure for a project I'm working on:
application
package.json
client
package.json
server
package.json
Additionally, some of the dependencies used in the project have a similar client/server hierarchy with a base-level package.json. The reasoning here is beside the point. What I'm trying to do is find the installed version(s) of a given lib within this project wherever it may be getting pulled in. I had hoped npm ls would do this, but it appears to only inspect the base-level package.json files.
I'm considering writing a bash script or something that recursively finds all node_modules directories starting in the root directory and then using npm ls in each directory, but am also hoping to find an easier answer. Any thoughts would be appreciated.
I ended up defining an alias as follows:
alias npm-ls-lib='_npm-ls-lib(){ \find . -type d -name "$1" -exec npm --prefix {} ls . \; | grep -v \(empty\); }; _npm-ls-lib'
and now I can call it like this: npm-ls-lib lib-name
I need to find a way to link additional names to an installed executable, after installing it.
The below example is close, except for two problems. One, the linking is done after every target, not just the install. Two, the links are created in the build directory, not in the install directory (I can probably add the paths necessary to do that, but it would then error out if done before the install.)
cmake_minimum_required(VERSION 2.8.4)
add_executable(gr gr.c)
install(TARGETS gr DESTINATION bin)
add_custom_command(
TARGET gr
POST_BUILD
COMMAND ln;-f;gr;grm
COMMAND ln;-f;gr;grs
COMMAND ln;-f;gr;grh
)
What's simple, clean way to do what I want?
In case it's not clear, the Makefile equivalent is:
gr: gr.c
cc -o gr gr.c
install:
install gr ${BINDIR}
ln -f ${BINDIR}/gr ${BINDIR}/grm
ln -f ${BINDIR}/gr ${BINDIR}/grs
ln -f ${BINDIR}/gr ${BINDIR}/grh
What I have done in similar situations is use the custom command similar to what you have done, but add an additional install command to install the links in the final bin directory alongside the target. So after your add_custom_command:
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/grm
${CMAKE_CURRENT_BINARY_DIR}/grs
${CMAKE_CURRENT_BINARY_DIR}/grh
DESTINATION bin
)
Of course, this will probably only do what you expect if you change your links to symbolic links (ln -s).
I'm using CMake to genenerate my Makefile's however I cannot generate the .clang_complete using the standard
make CC='~/.vim/bin/cc_args.py gcc' CXX='~/.vim/bin/cc_args.py g++' -B
nothing gets generated...
the tree structure looks like so
Root
|
|_core
| |_src
| | |_main.cpp
| | |_CMakeLists.txt (1)
| |_inc
| |_CMakeLists.txt (2)
|
|_lib
| |_rtaudio
|
|_CMakeLists.txt (3)
CMakeLists.txt (1) file:
include_directories("${Dunkel_SOURCE_DIR}/core/inc")
include_directories("${Dunkel_SOURCE_DIR}/lib/")
link_directories("${Dunkel_SOURCE_DIR}/lib/rtaudio")
add_executable(Dunkel main.cpp)
target_link_libraries(Dunkel rtaudio)
CMakeLists.txt (2) file:
subdirs(src)
CMakeLists.txt (3) file:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(Dunkel)
SUBDIRS(core)
set(CMAKE_CXX_FLAGS "-g")
What am I doing wrong here?
Looks like contrary to make cmake doesn't expand tilde, hence it treats is as part of the path. To make it work as expected either use absolute path to the cc_args.py script or do two simple changes in the command:
Replace the tilde with $HOME.
Replace single quotes with double quotes.
After the changes your command should look like this:
CXX="$HOME/.vim/bin/cc_args.py g++" cmake ..
And it should work.
You should run (in your build directory)
CXX='~/.vim/bin/cc_args.py g++' cmake ..
and then run make as usual. Note that this will run the cc_args.py script every time you build the project with make, if you want to disable this, re-run cmake again.
The file .clang_complete will be created in the build directory, move it if needed.
See also Vim: Creating .clang_complete using CMake
It is important to use $HOME/.vim/bin/cc_args.py and not ~/.vim/bin/cc_args.py, because ~ might not get expanded when quoted.
Also, verify the presence of the python script with:
$ ls -l $HOME/.vim/bin/cc_args.py
-rwxr-xr-x 1 myself staff 2270 Sep 19 16:11 /home/myself/.vim/bin/cc_args.py
if not found, adjust the python script path as necessary.
Run make clean in the build dir.
As suggested by #xaizek, start with an empty build directory (assuming the build directory is a subdir of the source dir):
CXX="$HOME/.vim/bin/cc_args.py g++" cmake ..
followed by:
make
at this point, make will be building the project, but calling cc_args.py (which will call g++), instead of directly calling g++.
However this part for me is failing to work, and no .clang_complete file is created in the build directory or anywhere else.
In fact, there is no occurrence of "cc_args" in the generated CMakeCache.txt / Makefile, so I suspect CXX is not the correct variable name to pass to cmake.
When finished, copy .clang_complete to the parent dir.
Here is what worked for me
sudo chmod a+x $HOME/.vim/bin/cc_args.py
CXX="$HOME/.vim/bin/cc_args.py g++" sudo cmake ..
sudo make
and then ls -a shows my .clang_complete file but still emtyp though.
I have a problem with the global environmental variable CMAKE_PREFIX_PATH. I already set this and I can see it is set when I type env, but when I run cmake . to build HipHop, it tells me that the variable isn't set.
Is there a way I can hard-code this into the makefiles?
Try to run cmake -DCMAKE_PREFIX_PATH=/your/path .
CMAKE_PREFIX_PATH works as a build directive, rather than as an environment variable. Moreover, you may perform the build into a dedicated temporary directory (it's cleaner, because when done, you can remove that temporary directory and you get back a clean pristine source tree).
$ mkdir -p tmpbuild && cd tmpbuild
$ cmake -DCMAKE_PREFIX_PATH=~/deliveries/hiphop ..
$ make install
$ cd ..
On MacOS it's different. I had to use:
make -i CMAKE_PREFIX_PATH="/the/path"
This was while installing VMQT, and this error was shown:
CMake Error at CMakeLists.txt:87 (find_package): By not providing
"FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has asked CMake
to find a package configuration file provided by "OpenCV", but CMake
did not find one.
Could not find a package configuration file provided by "OpenCV"
with any of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If
"OpenCV" provides a separate development package or SDK, be sure it
has been installed.
Used this to solve it: make -i CMAKE_PREFIX_PATH="/opt/homebrew/Cellar/opencv/4.6.0_1/lib/cmake/opencv4/"
I do cmake . && make all install. This works, but installs to /usr/local.
I need to install to a different prefix (for example, to /usr).
What is the cmake and make command line to install to /usr instead of /usr/local?
You can pass in any CMake variable on the command line, or edit cached variables using ccmake/cmake-gui. On the command line,
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr . && make all install
Would configure the project, build all targets and install to the /usr prefix. The type (PATH) is not strictly necessary, but would cause the Qt based cmake-gui to present the directory chooser dialog.
Some minor additions as comments make it clear that providing a simple equivalence is not enough for some. Best practice would be to use an external build directory, i.e. not the source directly. Also to use more generic CMake syntax abstracting the generator.
mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && cmake --build . --target install --config Release
You can see it gets quite a bit longer, and isn't directly equivalent anymore, but is closer to best practices in a fairly concise form... The --config is only used by multi-configuration generators (i.e. MSVC), ignored by others.
The ":PATH" part in the accepted answer can be omitted. This syntax may be more memorable:
cmake -DCMAKE_INSTALL_PREFIX=/usr . && make all install
...as used in the answers here.
Note that in both CMake and Autotools you don't always have to set the installation path at configure time. You can use DESTDIR at install time (see also here) instead as in:
make DESTDIR=<installhere> install
See also this question which explains the subtle difference between DESTDIR and PREFIX.
This is intended for staged installs and to allow for storing programs in a different location from where they are run e.g. /etc/alternatives via symbolic links.
However, if your package is relocatable and doesn't need any hard-coded (prefix) paths set via the configure stage you may be able to skip it.
So instead of:
cmake -DCMAKE_INSTALL_PREFIX=/usr . && make all install
you would run:
cmake . && make DESTDIR=/usr all install
Note that, as user7498341 points out, this is not appropriate for cases where you really should be using PREFIX.
The way I build CMake projects cross platform is the following:
/project-root> mkdir build
/project-root> cd build
/project-root/build> cmake -G "<generator>" -DCMAKE_INSTALL_PREFIX=stage ..
/project-root/build> cmake --build . --target=install --config=Release
The first two lines create the out-of-source build directory
The third line generates the build system specifying where to put the installation result (which I always place in ./project-root/build/stage - the path is always considered relative to the current directory if it is not absolute)
The fourth line builds the project configured in . with the buildsystem configured in the line before. It will execute the install target which also builds all necessary dependent targets if they need to be built and then copies the files into the CMAKE_INSTALL_PREFIX (which in this case is ./project-root/build/stage. For multi-configuration builds, like in Visual Studio, you can also specify the configuration with the optional --config <config> flag.
The good part when using the cmake --build command is that it works for all generators (i.e. makefiles and Visual Studio) without needing different commands.
Afterwards I use the installed files to create packages or include them in other projects...
Starting with CMake 3.15, the correct way of achieving this would be using:
cmake --install <dir> --prefix "/usr"
Official Documentation
Starting with CMake 3.21 you can use the --install-prefix option instead of manually setting CMAKE_INSTALL_PREFIX.
The modern equivalent of configure --prefix=DIR && make all install would now be:
cmake -B build --install-prefix=DIR
cmake --build build
cmake --install build
Regarding Bruce Adams answer:
Your answer creates dangerous confusion. DESTDIR is intended for
installs out of the root tree. It allows one to see what would be
installed in the root tree if one did not specify DESTDIR.
PREFIX is the base directory upon which the real installation is
based.
For example, PREFIX=/usr/local indicates that the final destination
of a package is /usr/local. Using DESTDIR=$HOME will install the files
as if $HOME was the root (/). If, say DESTDIR, was /tmp/destdir, one
could see what 'make install' would affect. In that spirit, DESTDIR
should never affect the built objects.
A makefile segment to explain it:
install:
cp program $DESTDIR$PREFIX/bin/program
Programs must assume that PREFIX is the base directory of the final
(i.e. production) directory. The possibility of symlinking a program
installed in DESTDIR=/something only means that the program does not
access files based upon PREFIX as it would simply not work. cat(1)
is a program that (in its simplest form) can run from anywhere.
Here is an example that won't:
prog.pseudo.in:
open("#prefix#/share/prog.db")
...
prog:
sed -e "s/#prefix#/$PREFIX/" prog.pseudo.in > prog.pseudo
compile prog.pseudo
install:
cp prog $DESTDIR$PREFIX/bin/prog
cp prog.db $DESTDIR$PREFIX/share/prog.db
If you tried to run prog from elsewhere than $PREFIX/bin/prog,
prog.db would never be found as it is not in its expected location.
Finally, /etc/alternatives really does not work this way. There are
symlinks to programs installed in the root tree (e.g. vi -> /usr/bin/nvi,
vi -> /usr/bin/vim, etc.).
It is considered bad practice to invoke the actual build system (e.g. via the make command) if using CMake. It is highly recommended to do it like this:
Configure + Generation stages:
cmake -S foo -B _builds/foo/debug -G "Unix Makefiles" -D CMAKE_BUILD_TYPE:STRING=Debug -D CMAKE_DEBUG_POSTFIX:STRING=d -D CMAKE_INSTALL_PREFIX:PATH=/usr
Build and Install stages:
cmake --build _builds/foo/debug --config Debug --target install
When following this approach, the generator can be easily switched (e.g. -G Ninja for Ninja) without having to remember any generator-specific commands.
Note that the CMAKE_BUILD_TYPE variable is only used by single-config generators and the --config argument of the build command is only used by multi-config generators.
Lots of answer, but I figured I'd do a summary to properly group them and explain the differences.
First of all, you can define that prefix one of two ways: during configuration time, or when installing, and that's really up to your needs.
During configuration time
Two options:
cmake -S $src_dir -B $build_dir -D CMAKE_INSTALL_PREFIX=$install_dir
cmake -S $src_dir -B $build_dir --install-prefix=$install_dir # Since CMake 3.21
During install time
Advantage: no need to reconfigure if you want to change it.
Two options:
cmake DESTDIR=$install_dir --build $build_dir --target=install # Makefile only
cmake --install $build_dir --prefix=$install_dir