I have a question related to cmake and make in Windows. As we already knows that in windows we can use
cmake -G"Visual Studio 12" ..
cmake --build . --target INSTALL --config Release
to compile and install the target using command lines. In linux, we can use
cmake -DCMAKE_BUILD_TYPE=Release ..
make
make install
to do the same job. Then how about mac? In mac, I tried to use:
cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 ../ -G Xcode
make
make install
but failed. Any ideas? Thanks.
You can use cmake --build on any platform as it
abstracts a native build tool's command-line interface
Related
I need to build my CMake based project under MSVC 2013 and MSVC 2019.
With MSVC 2019 using Ninja generator I build it successfully with following commands:
cmake -S . -B build -GNinja "-DCMAKE_BUILD_TYPE:STRING=Release"
cmake --build build --target all
On MSVC 2013 I have no Ninja available, so I tried the following:
cmake -S . -B build -DCMAKE_BUILD_TYPE:STRING=Release
cmake --build build --target all
Anyway I am getting following error and nothing is built:
MSBUILD : error MSB1009: Project file does not exist.
Switch: all.vcxproj
Any idea how to build it without ninja? (I cannot install it, since I am building it on a build server.)
In contrast to other generators (like Makefiles or Ninja) CMake does not generate an all target for Visual Studio solution but an ALL_BUILD target.
So cmake --build build --target ALL_BUILD --config Release should succeed.
I've been trying to compile my code with CMake using the "MSYS Makefiles" generator. I wrote the following command:
cmake -S . -B build/ -G "MSYS Makefiles
But I was presented with the following error:
CMake Error: CMake was unable to find a build program corresponding to "MSYS Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MSYS Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_AR was not found, please set to archive program.
After some investigation, I found that I had to install something called "mingw-make" to do this. Apparently this "mingw-make" can be installed in the "MinGW gui". Note that I checked if I already have "mingw-make" installed and I don't.
I'm confused because I can't seem to find this "MinGW gui" anywhere. I installed MinGW, and only have an application on my computer called "Modify or Remove MinGW". I searched the install options, and couldn't find "mingw-make" anywhere.
Where can I download this "mingw-make" from? Thanks.
Use mingw32-make only with cmake -G"MinGW Makefiles".
Use make only with cmake -G"MSYS Makefiles".
But if you want the best performance you should get Ninja and use ninja with cmake -G"Ninja".
MinGW is all command line, though there are some GUI installers for it. MinGW-w64 is the successor to MinGW which also supports 64-bit Windows.
There are standalone MinGW-w64 Windows releases available from https://winlibs.com/ that don't require installation steps, just extract. This also includes mingw32-make
I'm a Linux user who's trying to set up a dev environment on Windows. I've cloned the fmt repo and built it the way I'm used to on Linux:
C:\Users\me\Development> git clone https://github.com/fmtlib/fmt.git
C:\Users\me\Development> cd fmt
C:\Users\me\Development> mkdir build
C:\Users\me\Development> cd build
C:\Users\me\Development> cmake ..
C:\Users\me\Development> cmake --build . --config Release
Now I want to install it so that I can include it in projects. Normally I would $ sudo make install but I'm not sure what to do on Windows and the fmt doc page has nothing for Windows installation.
When I did this same set of steps with FLTK there was a variable that I had to set to help me find things:
# CMakeLists.txt
set(FLTK_DIR "Path/to/installation")
find_package(FLTK REQUIRED NO_MODULE)
But it seems to be looking for the installation point, not the build dir. How can I get this to work?
You can run:
cmake --install . [--prefix <install-dir>]
The prefix is optional. On Windows, the default CMAKE_INSTALL_PREFIX is set to:
C:/Program Files (x86)/<project name>
Which in the case fmtlib would be:
C:/Program Files (x86)/FMT
Another option is to use vcpkg on Windows, which will install fmtlib locally in its own vcpkg install prefix. Then you can use it via:
find_package(fmt REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE fmt::fmt)
You just have to pass the vcpkg cmake toolchain file to your cmake invocation:
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
I'm trying to build this
https://github.com/patrikhuber/eos
but I'm having troubles.
The instructions are pretty simple, as it says on gitHub
To build:
git clone --recursive https://github.com/patrikhuber/eos.git
mkdir build && cd build # creates a build directory next to the 'eos' folder
cmake -G "<your favourite generator>" ../eos -DCMAKE_INSTALL_PREFIX=../install/
make && make install # or open the project file and build in an IDE like Visual Studio
I'm using "Ninja" as generator and it looks like the cmake part goes through successfully as I get
-- Configuring done
-- Generating done
-- Build files have been written to: /home/francesco/eos/build
That's where things stop "working" for me, or where I fail to understand what's next. Following the instructions, I type
make && make install
and I get this message
make: *** No targets specified and no makefile found. Stop.
I looked around for solutions but I don't really understand what I am supposed to do: I tried
./configure
but I'm getting
bash: ./configure: No such file or directory
Anyone can please help?
Thanks
It always depends on your CMake "Generator". The 'make' is linux/mingw tool/command. For VisualStudio you can use nmake or sln/proj generated stuff.
More reliable could be utilize CMake for building i.e. for "NMake Makefiles" generator:
cmake --build <build folder> --target install
or
cmake --build <build folder> --config release --target install
for VisualStudio generator
I had the same problem, and solved by tinkering with locations for cmake and make. Here's what I used:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local
make
I believe /usr/local is the default location (see here)
To be honest, I recently started working with find_package in CONFIG-mode... Is there an easy way to install packages globally on Windows 10?
Or I must manually set -DCMAKE_INSTALL_PREFIX and build all stuff by my hand?:
cmake . -Bbuild/debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=d -DCMAKE_INSTALL_PREFIX="install"
cmake --build build/debug --target install
cmake . -Bbuild/release -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="install"
cmake --build build/release --target install
All I want is - register the package once and forget about it. After the package is registered all commands like find_package(X CONFIG REQUIRED) must work well... Do all paths must be determined manually?