conanfile.txt //i am using local repo
[requires]
libxml2/2.9.0#conan/stable
[generators]
cmake
CMakeLists.txt
cmake_minimum_required(VERSION 3.4)
project(testlibxml)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(test_xml_lib test_xml.cpp)
test_xml.cpp
#include <libxml/xlink.h>
int main(){
return 0;
}
I expect includes to be resolved properly, but i am getting below error
error: libxml/xlink.h: No such file or directory.
It works if i add below line in CmakeLists.txt
include_directories(${CONAN_INCLUDE_DIRS}/libxml2)
I don't know where are you getting that version of the libxml2 package, because it is not in conan-center:
$ conan search libxml* -r=conan-center
Existing package recipes:
libxml2/2.9.3#bincrafters/stable
libxml2/2.9.8#bincrafters/stable
So what you are using might be an old, stale, or broken version from somewhere else. Changing your conanfile.txt:
[requires]
libxml2/2.9.8#bincrafters/stable
[generators]
cmake
And I have checked it works (at least in Windows)
Related
I am about to change to conan, in the hope that is will simplify installing my package by my users. It was OK, until I started to add gtest to my package.
During install, I receive messages
gtest/1.8.1#bincrafters/stable: Package installed
conanfile.txt imports(): Copied 4 '.a' files: libgmockd.a, libgtestd.a, libgmock_maind.a, libgtest_maind.a
However, during build I receive:
/usr/bin/ld: cannot find -lgmock_maind
/usr/bin/ld: cannot find -lgmockd
/usr/bin/ld: cannot find -lgtestd
My CMakeLists.txt file contains
target_link_libraries(
${PROJECT_NAME}_GTEST
Modules
${CONAN_LIBS}
)
What is missing? Shall I provide some
link_directories(?)
argument?
(In the meantime, after some trials, I succeeded: Not only
link_directories(${CONAN_LIB_DIRS_GTEST})
is needed, but also conan's .data must be cleared.)
What generator are you using?
I have this in my conanfile.txt requires section
gtest/[~=1.8]#bincrafters/stable
This is what I have for generators in that section
cmake_find_package
cmake_paths
And in the CMakeLists.txt
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
find_package(gtest REQUIRED)
add_dependencies(something gtest::gtest)
target_link_libraries(something gtest::gtest)
Note that FindGTest is a built in module, but Findgtest.cmake is a file generated by conan in the build directory.
The Bincrafters package for gtest is marked as obsolete, you should use the one in the conan center.
For that, simply add the conan recipe to the conanfile.txt/py.
Let's say you use a plain conanfile.txt:
# conanfile.txt
[requires]
gtest/1.10.0
[generators]
cmake
Then you can run conan install
Then add the conan instructions to your project's CMakeLists.txt:
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
You may print a message to see the included libraries:
message("-- Conan libs: ${CONAN_LIBS}").
This should include both gtest and gmock.
Finally, just include the header, and use the framework:
#include "gtest/gtest.h"
TEST(TestName, Foo)
{
EXPECT_TRUE(true);
}
I've tried playing with the idea to compile my mixed swift/objective-c/c++ based project using CMake. So as a starter, I went to SwiftMix example and run the following CMakeList.txt file :
cmake_minimum_required(VERSION 3.3)
project(SwiftMix C Swift)
add_executable(SwiftMix CMain.c ObjCMain.m SwiftMain.swift ObjC-Swift.h)
set_property(TARGET SwiftMix PROPERTY XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER "ObjC-Swift.h")
After running cmake on the file above, I got the following error :
CMake Error: CMAKE_Swift_COMPILER not set, after EnableLanguage
However, it looks like inside CMake installation (version 3.9.1), there's a file/files which handle the swift support and define the missing variable from the error message :
/usr/local/Cellar/cmake/3.9.1//share/cmake/Modules/CMakeSwiftCompiler.cmake.in
Any idea how can I change the "CMakeLists.txt" to support swift ?
First, Swift language not supported by "Unix Makefiles" generator. So, you have to use cmake -G Xcode .
Then, generator the Xcode project, if it does not work, you can try the sudo xcode-select --reset or upgrade your cmake version.
Final, try cmake -G Xcode . again.
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
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.