cmake

How to get a relative path for CMake unit tests?

心已入冬 提交于 2020-07-23 06:02:10
问题 I have a project built with CMake that uses Catch2 for unit tests. Some of the unit tests exercise code that loads data from a file like this: std::string resource_dir = "TEST_CWD/resources/"; std::ifstream infile{resource_dir + "datafile.txt"} The question is how to properly get the value of TEST_CWD . The directory structure is simple (and not set in stone): my_project/ test/ resources/datafile.txt loader_test.cpp Leaving TEST_CWD blank sometimes works, but breaks when running tests through

How to fix compiler identification unknown - Visual Studio 19

这一生的挚爱 提交于 2020-07-22 21:34:18
问题 When I try to load a open source project in Visual Studio cmake is asking to generate cache and getting the following error: CMake generation started for configuration: 'x64-Debug'. 1> The toolchain file has changed (CMAKE_TOOLCHAIN_FILE). 1> Command line: "cmd.exe" /c ""C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="G:\Reference's\libiec61850-1.4.0\out\install\x64-Debug"

CMake: Cross-compiling linux-to-windows with MinGW does not find some system headers

倖福魔咒の 提交于 2020-07-22 09:28:34
问题 I am trying to cross-compile from Linux to Windows with MinGW a project configured with CMake, and some of the system headers are not found. This is the kind of errors I am getting: [ 1%] Building C object src/CMakeFiles/exiv2lib_int.dir/localtime.c.obj cd /home/luis/programming/buildExiv2Mingw/src && /usr/bin/x86_64-w64-mingw32-gcc-posix -Dexiv2lib_STATIC @CMakeFiles/exiv2lib_int.dir/includes_C.rsp -o CMakeFiles/exiv2lib_int.dir/localtime.c.obj -c /home/luis/programming/exiv2/src/localtime.c

Cannot generate 32 bit configuration for Visual Studio 2019 with host=x86 or -A Win32

谁都会走 提交于 2020-07-22 06:13:11
问题 I am trying to configure cmake to build for 32bit and 64bit separately... So far 64bit is easy as I just need to add -A x64 cmake -G "Visual Studio 16 2019" -A x64 But I am not able to set 32bit arch. Official documentation suggest -A Win32 or -T host=x86 https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2016%202019.html Even with them I am not able to set x86 host What I have tried: cmake -G "Visual Studio 16 2019" -DCMAKE_GENERATOR_PLATFORM=x86 cmake -G "Visual Studio 16 2019"

How to pass a variable from command line to a CMake Toolhain file?

前提是你 提交于 2020-07-19 11:12:46
问题 Is there a way to pass a variable to a toolchain file when invoking cmake? For example, I have the following toolchain file: message("FOO = ${FOO}") I have tried the following, but it did not work. The variable is not set in the toolchain file. cmake <src-dir> -DCMAKE_TOOLCHAIN_FILE=<toolchain-file> -DFOO="bar" -B <build-dir> What I am actually trying to achieve is passing a path to the toolchain file. And I can't modify the main CMakeLists.txt in . 回答1: You have to set the path to your

How to pass a variable from command line to a CMake Toolhain file?

坚强是说给别人听的谎言 提交于 2020-07-19 11:11:43
问题 Is there a way to pass a variable to a toolchain file when invoking cmake? For example, I have the following toolchain file: message("FOO = ${FOO}") I have tried the following, but it did not work. The variable is not set in the toolchain file. cmake <src-dir> -DCMAKE_TOOLCHAIN_FILE=<toolchain-file> -DFOO="bar" -B <build-dir> What I am actually trying to achieve is passing a path to the toolchain file. And I can't modify the main CMakeLists.txt in . 回答1: You have to set the path to your

CMake: how to clear target compile options

让人想犯罪 __ 提交于 2020-07-19 04:37:05
问题 In my project I have defined some general compile options using CMAKE_CXX_FLAGS globally. Some other options, that in common case should be applied to all targets, are specified using add_compile_options() in my main CMakeLists file. For example I want the flag -Wconversion be applied to all targets. But I have one external library that produces to many warnings with this option enabled. So I want to disable option only for this particular lib: get_target_property(EXTLIB_COMPILE_FLAGS ext_lib

How to use CHECK_INCLUDE_FILES macro in cmake?

 ̄綄美尐妖づ 提交于 2020-07-18 10:27:34
问题 I need link my program against Kerberos authentication library ( gssapi_krb5 ) with the corresponding headers gssapi/gssapi.h and gssapi/gssapi_krb5.h included in the source file. Currently, the compilation will continue if headers are absent and stop with a compile time error saying header files not found. What I want to implement in the cmake file is to check the existence of the header file and stop compiling if not found. I add the following code into my CMakeList.txt file. INCLUDE

Android, CMake and Static Linking

◇◆丶佛笑我妖孽 提交于 2020-07-18 05:22:06
问题 In converting a library project build from Android.mk to CMakeLists.txt following the Google hello-libs example and I have encountered problems avoiding undefined references. I'm using an open source project called DCMTK and compiling DCMTK and ICONV to static libraries that I then link in. Building using the Android.mk works via ndk-build and building them with gradle and the following CMakeLists.txt works when I add each static library to the target_link_libraries . However, I wanted to use

How to run SFML in CLion, Error undefined reference to?

不问归期 提交于 2020-07-17 10:47:31
问题 I'm new to C++ and try to learn game programming, I choose SFML and run on CLion by Jetbrain and using Ubuntu machine. I following this tutorial SFML and Linux here my code : #include <SFML/Graphics.hpp> using namespace sf; int main() { RenderWindow window(sf::VideoMode(200, 200), "SFML Work!"); CircleShape shape(100.f); shape.setFillColor(Color::Green); while (window.isOpen()) { Event event; while (window.pollEvent(event)) { if (event.type == Event::Closed) { window.close(); } } window.clear