天道酬勤,学无止境

cmake

How to build and link google benchmark using cmake in windows

I am trying to build google-benchmark and use it with my library using cmake. I have managed to build google-benchmark and run all its tests successfully using cmake. I am unfortunately unable to link it properly with my c++ code in windows using cmake or cl. the problem I think is that google-benchmark builds the library inside the src folder, i.e it is build in src/Release/benchmark.lib now i cannot point to it in cmake if I use ${benchmark_LIBRARIES} it looks for the library in the Release folder outside src, as this is the usual place all the libraries are build. and it is difficult to

2021-06-15 15:38:34    分类:问答    c++   cmake   benchmarking   microbenchmark   google-benchmark

CMake building for Windows (clang-cl) using Ninja Generator

I am trying to build a simple application on a Windows machine using CMake as the main build tool. Once CMake is invoked on the project the is an error on configuration phase: > cmake -H. -G Ninja -Bbuild -DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" -DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" -- The C compiler identification is Clang 7.0.0 -- The CXX compiler identification is Clang 7.0.0 -- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe --broken CMake Error

2021-06-15 15:01:50    分类:问答    cmake   ninja   clang-cl

How to download a toolchain for cross compilation in cmake from separate file?

I have a project with a CMakeLists.txt files in the root and the project compiles fine on Linux and OSX. Now I want to cross compile it for MIPS OpenWRT. I would like to automate it as much as possible, so I would use following code to download the toolchain and set the compiler variables: ExternalProject_Add(ar71xx-toolchain PREFIX "${PROJECT_BINARY_DIR}/external/openwrt" URL "http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/OpenWrt-Toolchain-ar71xx-for-mips_34kc-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2" UPDATE_COMMAND "" PATCH_COMMAND "" BUILD_COMMAND "" CONFIGURE_COMMAND ""

2021-06-15 14:33:02    分类:问答    cmake   cross-compiling

CMake: execute a macro/function as the command of add_custom_command

I'm using an external library which provides a CMake function for automatic code generation, to be used in my CMakeLists. The problem is that whenever I modify a CMakeLists then the function is run again, triggering the recompilation of the newly generated but unchanged sources. I'd need something like add_custom_command with the possibility to specify the CMake function as COMMAND instead of an executable, so that the function is run only if the automatically generated files are not already present. Is this feasible? If not, does it exist another way to obtain the same result? Thanks.

2021-06-15 13:56:21    分类:问答    cmake   add-custom-command

Run Command after generation step in CMake

I have a command line tool that should be run after CMake created my .sln-file. Is there any way to do that using CMake? Using execute_process(COMMAND ..) at the end of the CMakeLists.txt does not help because this is executed after the Configure step, however, the .sln-file is created in the generation step. Thanks a lot!

2021-06-15 13:44:01    分类:问答    cmake

Hide automatically generated CTest targets

I'm using CMake and CTest in CLion. Annoyingly, CTest generates a load of targets that I don't care about: Continuous ContinuousBuild ContinuousConfigure ContinuousCoverage ContinuousMemCheck ContinuousStart ContinuousSubmit ContinuousTest ContinuousUpdate Experimental ExperimentalBuild ExperimentalConfigure ExperimentalCoverage ExperimentalMemCheck ExperimentalStart ExperimentalSubmit ExperimentalTest ExperimentalUpdate Nightly NightlyBuild NightlyConfigure NightlyCoverage NightlyMemCheck NightlyStart NightlySubmit NightlyTest NightlyUpdate These all show up in CLion. Quite annoying as I'm

2021-06-15 12:14:34    分类:问答    c++   cmake   clion   ctest

CMake RequireAdministrator

I'm trying to set the RequireAdministrator manifest flag on an executable I'm building with CMake and Visual Studio. Any ideas on how to direct CMake to set that option? Thanks! Billy3

2021-06-15 12:08:45    分类:问答    c++   visual-studio-2008   cmake

Android NDK Cmake Linking .a (Static) Libs

I am using Android Studio 2.2.2 with cmake and Android NDK. I have a problem linking .a library (Static lib). Here is my cmake: # Sets the minimum version of CMake required to build the native # library. You should either keep the default value or only pass a # value of 3.4.0 or lower. cmake_minimum_required(VERSION 3.4.1) set(CMAKE_VERBOSE_MAKEFILE on) # Creates and names a library, sets it as either STATIC # or SHARED, and provides the relative paths to its source code. # You can define multiple libraries, and CMake builds it for you. # Gradle automatically packages shared libraries with

2021-06-15 11:49:31    分类:问答    android   android-ndk   linker   cmake   linker-errors

CMake JNI error

I've written a binding C++ class that calls java from C++. I am trying to compile the binding class using CMake (because the tool that will use the binding class uses CMake). However I receive the following error: CMakeFiles/JNIWrapper.dir/JNIWrapper.cpp.o: In function `createVM(JavaVM_**)': JNIWrapper.cpp:(.text+0x52): undefined reference to `JNI_CreateJavaVM' collect2: ld returned 1 exit status make[2]: *** [JNIWrapper] Error 1 make[1]: *** [CMakeFiles/JNIWrapper.dir/all] Error 2 make: *** [all] Error 2 Here is my CMakeLists.txt: cmake_minimum_required(VERSION 2.8.6) project(AProject) FIND

2021-06-15 11:24:30    分类:问答    java-native-interface   cmake

How can I add a flag at the end of the linking command line using CMake?

I've got an issue where CMake can't detect pthread. As a work-around I tried: set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread") However, this inserts -lpthread in the wrong place: /usr/bin/c++ -std=c++11 -D_GNU_SOURCE -Wall [manyflags ...] -lpthread \ CMakeFiles/connectivity_tool.dir/connectivity_tool/conn_tool.cpp.o \ -o connectivity_tool -rdynamic -lboost_system [many libraries...] This results in: /usr/bin/ld: /tmp/ccNvRifh.ltrans3.ltrans.o: undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5' /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO

2021-06-15 09:47:55    分类:问答    c++   compilation   linker   makefile   cmake