I want to compile with cmake+MinGW. The command is 'cmake . -B build -G "MinGW Makefiles" '. a Makefile file is generated. However, Chinese characters also appear in the Makefile file due to the existence of Chinese characters in the path.
The Makefile generated by cmake uses UTF-8 encoding, while mingw32-make uses ANSI (GBK) encoding, so mingw32-make cannot work properly.
I tried to convert the Makefile file to GBK code and then run mingw32-make, but it was still not feasible because Makefile still tried to call cmake.
I tried to see all the cmake commands (cmake --help-full). Only in a few cases did I mention the encoding settings, but there seemed to be no case I needed.
Related
My makefile consists of one line
cmake_minimum_required(VERSION 3.6)
There are no leading spaces, line ending is UNIX-style. I'm out of ideas.
You cannot run input files for cmake with make.
A makefile is input for make command.
A CMakeLists.txt is input for cmake command.
CMake is a build system generator, i.e. it will create a makefile from a CMakeLists.txt for you, that can later be run with make.
I'd like to run a command on a target after installing it. I see "cmake run script for install target?", which appears to be about running a single script after installing everything. My question is a per-target script.
What I want to do is to run patchelf on an installed binary to change the interpreter. This is much like how cmake will change the RPATH on the installed binary. Looking into how this is done, I see stuff this in cmake_install.cmake (edited for brevity):
file(INSTALL DESTINATION "/bin" TYPE EXECUTABLE FILES "program")
file(RPATH_CHANGE
FILE "$ENV{DESTDIR}/bin/program"
OLD_RPATH "build-dir"
NEW_RPATH "")
if(CMAKE_INSTALL_DO_STRIP)
execute_process(COMMAND "/usr/bin/strip" "$ENV{DESTDIR}/bin/program")
endif()
This is changing the rpath and also stripping the binary after it is installed. It seems like all I need to do is get one more execute_process put in there to run my patchelf command. Yet I can't find any way to get cmake to do that.
It appears add_custom_command(POST_BUILD ...) is very close, but I do not want to modify the binary in the build directory, only after install, like how cmake modifies the rpath.
I'm trying to make Ninja work with CMake on FreeBSD 10.3:
cmake -GNinja ..
-- Configuring done
CMake Error:
The detected version of Ninja () is less than the version of Ninja required
by CMake (1.3).
-- Build files have been written to: /home/me/pj/_build
I have put a locally compiled (from Git tag v1.8.2) Ninja in ~/bin/ninja (which is in my $PATH).
$ cmake -version
cmake version 3.4.1
$ ninja --version
1.8.2
I also tried to add -DCMAKE_MAKE_PROGRAM=ninja and -DCMAKE_MAKE_PROGRAM=~/bin/ninja without effect.
I also tried to see if Ninja was really called (by putting a script writing a new file), and it looks like it's never called.
Is there a way to see which commands are used to to check the Ninja version?
By inspecting the generated CMakeCache.txt file, you should be able to tell which Ninja version is picked by CMake.
In CMakeCache.txt you should have something similar to:
// Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/ninja
which could tell which Ninja version is picked by default and whether -DCMAKE_MAKE_PROGRAM is respected or from some reason ignored.
Also, it is worth looking into the generated CMakeOutput.log and CMakeError.log files.
I would also suggest adding ninja to your PATH, hoping CMake would pick it from there.
I came across this question while getting the same error message. What I forgot to do was delete the CMakeCache.txt file before I ran cmake with the -GNinja or -DCMAKE_GENERATOR=Ninja options. So cmake was pulling the cached variable.
You can also get this error message when forgetting to call project(my_project) before calling add_library or add_executable.
In order to ensure that my Linux builds are identical regardless of the distribution the build host uses, I have packaged up my compiler and the sysroot files into a relocatable tar file and checked that into source control.
So the first step in any build (or at least, a step that must be invoked before any compile step) must be to extract this tar file.
If I was using a makefile, this would be simple to do. However, the project is using cmake and I can't figure out any way to do it with cmake. It might even be that I need this extract step invoked before cmake starts to detect the compiler: I can hard-code the compiler name but if cmake fails if it can't find the compiler then I need the unpack to happen before that test.
Is this possible with cmake?
You can use execute_process to invoke cmake's cross-platform command mode (cmake -E tar). The command would be something like:
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf MyCompiler.bz2)
The command which causes CMake to check for a valid compiler is project, so as long as you have your execute_process call before the project call, the unpacking will be done before the compiler check.
I am trying to compile (on FreeBSD, if that matters) a program that uses cmake. The CMakeLists.txt contains the lines
find_package(GLUT REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${OPENGL32_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS})
and cmake does not report any errors, but when I run make afterwards, I get
[…]
/usr/bin/c++ -fopenmp -I/path/build -o CMakeFiles/scriptbots.dir/GLView.cpp.o -c /path/GLView.cpp
[…]
In file included from /path/GLView.cpp:2:
/path/GLView.cpp:10:21: error: GL/glut.h: No such file or directory
[…]
GL/glut.h exists in /usr/local/include, which is not given as -I argument to /usr/bin/c++.
Compiling works when I explicitly add -I/usr/local/include to CMakeFiles/scriptbots.dir/flags.make. What do I need to change to make the project compile without manually changing the flags file?
As per its documentation, FindGLUT sets variable GLUT_INCLUDE_DIR, not GLUT_INCLUDE_DIRS. Change this in your CMakeList and it should work.