When I try to use cmake on the jsonCPP i get the following error
CMake Error at lib_json/CMakeLists.txt:73 (INSTALL):
install TARGETS given no ARCHIVE DESTINATION for static library target
"jsoncpp_lib_static"
I use the command from readme:
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../..
From the error, it looks as though you're pointing CMake to the CMakeLists.txt inside "/jsoncpp/src" rather than the root one at "/jsoncpp".
The root CMakeLists.txt defines the variable ARCHIVE_INSTALL_DIR at this point and it's used in the "/jsoncpp/src/lib_json/CMakeLists.txt" at this point to define the target's ARCHIVE DESTINATION.
Since you're skipping the root CMakeLists.txt, this variable never gets set.
The error message mentions the path lib_json/CMakeLists.txt:73, and this is relative to the "main" CMakeLists.txt - i.e. the one you pointed CMake to when you first executed it. So CMake thinks the root is "/jsoncpp/src" instead of the real root.
Basically, to fix your error, clean out your build folder then rerun CMake to point to the "/jsoncpp" folder.
By the way, although the docs don't specifically mention it, I think the CMAKE_BUILD_TYPE is case-sensitive. You should be doing -DCMAKE_BUILD_TYPE=Debug.
Related
I'm attempting to compile a program using cmake that gives me the following error(s):
CMake Error at /.../3dg.cmake:8 (enable_language):
The CMAKE_CXX_COMPILER:
CC
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
CMakeLists.txt:8 (include)
CMake Error at /.../3dg.cmake:8 (enable_language):
The CMAKE_C_COMPILER:
cc
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
I am setting both of these variables in my cmake file with:
set(CMAKE_C_COMPILER cc)
set(CMAKE_CXX_COMPILER CC)
Moreover, I can confirm that both of them are in my path and at the correct location.
>>which cc
/opt/cray/pe/craype/2.5.14/bin/cc
>>which CC
/opt/cray/pe/craype/2.5.14/bin/CC
And my path includes this directory!
>>echo $PATH
/opt/cray/rca/2.2.18-6.0.7.0_33.3__g2aa4f39.ari/bin:/opt/cray/alps/6.6.43-6.0.7.0_26.4__ga796da3.ari/sbin:/opt/cray/job/2.2.3-6.0.7.0_44.1__g6c4e934.ari/bin:/opt/cray/pe/hdf5/1.10.0.3/bin:/opt/cray/pe/craype/2.5.14/bin:/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:/usr/common/software/metis/5.1.0/bin:/usr/common/software/darshan/3.1.4/bin:/usr/common/software/altd/2.0/bin:/usr/common/software/bin:/usr/common/mss/bin:/usr/common/nsg/bin:/opt/cray/pe/mpt/7.7.0/gni/bin:/opt/ovis/bin:/opt/ovis/sbin:/usr/syscom/nsg/sbin:/usr/syscom/nsg/bin:/opt/cray/pe/modules/3.2.10.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/cray/pe/bin:
The cmake file sees the same path as the terminal. I have confirmed that this error goes away if I change my cmake code to:
set(CMAKE_C_COMPILER /opt/cray/pe/craype/2.5.14/bin/cc)
set(CMAKE_CXX_COMPILER /opt/cray/pe/craype/2.5.14/bin/CC)
But this is not a long term fix as the actual location of cc/CC depends on which modules I am using and the updated version of the compilers.
Does anyone know what is going on, and how to force cmake to recognize that these compilers are located in the correct location? Thanks.
Go to download page of glfw and download their source package. Now unzip it and enter into the directory.
Now generate the make file with sudo cmake -G "Unix Makefiles".
Now do sudo make and sudo cmake. The install process should be complete.
For more info take a look at here
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.
I am trying to debug my Makefile based project which I have imported in CLion. I created a simple CMake file as below
cmake_minimum_required(VERSION 2.8.4)
project(Project1)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
add_custom_target(myProject COMMAND make -j4 DEBUG=1
CLION_EXE_DIR=${PACKAGE_DIR})
CMake tool shows me error: CMake executable not specified. I tried adding add_executable(myProject ${SOURCE_FILES}) with correct source files, but still same error.
Where as on Edit Configurations page, I cannot select any Configuration. The drop down for Configuration is empty. At the bottom I get error Error: Configuration is not specified..
When I try to debug the program, I get a warning message Configuration is still incorrect. Do you want to edit it again? I click on Continue Anyway, which compiles the program as I expect and it generates the correct executable file as well. But it cannot run the executable because of the errors in the Configurations.
I assume "CMake executable" refers to the location of the executable cmake which is called to configure your project. Probably you have to search for a setting in CLion where you can define /usr/bin/cmake or whereever your cmake resides.
This solved the problem for me (Ubuntu):
sudo apt-get install cmake
I wrote a very simple HelloWorld.c program and ran Cmake. It created a cmake_install.cmake file in my build directory. Can somebody explain to me why CMake generated the file cmake_install.cmake? What is it's purpose and how can I use it?
CMakelists.txt :
cmake_minimum_required(VERSION 3.0)
PROJECT(FirstExample)
add_executable(prog first.c)
Thanks!
You generally don't use cmake_install.cmake directly. From the v3.12 page it states:
The install() command generates a file, cmake_install.cmake, inside
the build directory, which is used internally by the generated install
target and by CPack.
With your current CMakeLists.txt, the generated file doesn't do much. To create a useful install you would need to add more INSTALL commands to your CMakeLists.txt using the syntax below.
INSTALL(TARGETS targets... [EXPORT <export-name>]
[[ARCHIVE|LIBRARY|RUNTIME|FRAMEWORK|BUNDLE|
PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]
[DESTINATION <dir>]
[INCLUDES DESTINATION [<dir> ...]]
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>]
[OPTIONAL] [NAMELINK_ONLY|NAMELINK_SKIP]
] [...])
For further reading on this command, check out the documentation site and wiki.
If it's desired to manually execute the script as stated by Nic30g the 3.12 page states that cmake -P accepts the following variables:
COMPONENT
Set this variable to install only a single CPack component as opposed to all of them. For example, if you only want to install the Development component, run
cmake -DCOMPONENT=Development -P cmake_install.cmake
BUILD_TYPE
Set this variable to change the build type if you are using a multi-config generator. For example, to install with the Debug configuration, run
cmake -DBUILD_TYPE=Debug -P cmake_install.cmake.
DESTDIR
This is an environment variable rather than a CMake variable. It allows you to change the installation prefix on UNIX systems. See DESTDIR for details.
As previous answer tells, the cmake_install.cmake contains the commands generated by install command from your CMakeLists.txt.
You can execute it by cmake -P cmake_install.cmake and it performs the installation of your project even on windows.
https://cmake.org/pipermail/cmake/2007-April/013657.html
I would like to force CMake to use the "Unix Makefiles" generator from within CMakeLists.txt.
This is the command I use now.
cmake -G "Unix Makefiles" .
I would like it to be this.
cmake .
When running on windows with VC installed and a custom tool-chain.
I would expect to be-able to set the generator in the CMakeLists.txt file.
Maybe something like this.
set(CMAKE_GENERATOR "Unix Makefiles")
Here is what worked for me - create a file called PreLoad.cmake in your project dir containing this:
set (CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE)
It seems to me that the variable CMAKE_GENERATOR is set too late if set in the CMakeLists.txt. If you use (even at the beginning of CMakeLists.txt)
set(CMAKE_GENERATOR "Ninja")
message("generator is set to ${CMAKE_GENERATOR}")
you can see in the output something like
% cmake ../source
-- The C compiler identification is GNU 4.9.2
...
-- Detecting CXX compile features - done
generator is set to Ninja
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/build
So the variable is only set at the very end of the generation procedure. If you use something like
set(CMAKE_GENERATOR "Ninja" CACHE INTERNAL "" FORCE)
in CMakeLists.txt, then in the very first run of cmake ../source (without -G) the default generator is used. The variable CMAKE_GENERATOR is stored in the cache, though. So if you rerun cmake ../source afterwards, it will use the generator as specified in the CMAKE_GENERATOR variable in the cache.
This is surely not the most elegant solution, though ;-) Maybe use a batch file that will actually execute the cmake -G generator for the user...
This is not what I get, when I run the same command, cmake will look for a gcc compiler / make utility. If the PATH is not set up correctly it will fail with something like:
D:\Development\build>cmake -G "Unix Makefiles" ..\source
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set.
You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:D:/Development/build/CMakeFiles/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:D:/Development/build/CMakeFiles/CMakeCXXCompiler.cmake
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
when gcc / mingw is in the path then everything works fine. So could you provide more information as to your PATH variable or CMAKE version?
You need to set the generator at the Generate stage so it is written into the cache.
You only need to run this command once for the first configuration
cmake .. -DCMAKE_GENERATOR:INTERNAL=Ninja
This will configure Ninja as the default generator.
Later you can simply run
cmake ..
And it would use the Ninja generator as default
You can read more about it under Running CMake from the command line
When running cmake from the command line, it is possible to specify command line options to cmake that will set values in the cache. This is done with a -DVARIABLE:TYPE=VALUE syntax on the command line. This is useful for non-interactive nightly test builds.
CMake 3.19 introduces a new feature - presets. So, to select proper generator automatically, you can specify it name in CMakePresets.json.
Full description for these files available here: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html