How to run tests and debug Google Test project in VS Code?

Start with a clean directory: /home/user/Desktop/projects/cpp/ # your project lives here Add your cmake file(CMakeLists.txt), your source files, and test file. The directory now looks like this: └─cpp/ ├─ CMakeLists.txt ├─ myfunctions.h └─ mytests.cpp Clone and add googletest to this directory: └─cpp/ ├─ googletest/ ├─ CMakeLists.txt ├─ myfunctions.h └─ mytests.cpp Open your CMakeLists.txt and enter … Read more

How do I get the parent directory path of a path in CMake?

For CMake 3.20 and newer, the recommended way is to use cmake_path with a PARENT_PATH option: cmake_path(GET MYPROJECT_DIR PARENT_PATH PARENT_DIR) For older versions up to CMake 2.8.12, use the get_filename_component command with the DIRECTORY option: get_filename_component(PARENT_DIR ${MYPROJECT_DIR} DIRECTORY) For versions of CMake older than 2.8.12, use the PATH option: set (MYPROJECT_DIR /dir1/dir2/dir3/myproject/) get_filename_component(PARENT_DIR ${MYPROJECT_DIR} PATH)

How can I define a C++ preprocessor macro through the command line with CMake?

A good alternative would be to define a CMake option: OPTION(DEFINE_MACRO “Option description” ON) # Enabled by default Followed by a condition: IF(DEFINE_MACRO) ADD_DEFINITIONS(-DMACRO) ENDIF(DEFINE_MACRO) Then you can turn that option ON/OFF via the command line with CMake using the -D flag. Example: cmake -DDEFINE_MACRO=OFF .. To make sure the compiler is receiving the definition … Read more

Define a preprocessor macro through CMake

For a long time, CMake had the add_definitions command for this purpose. However, recently the command has been superseded by a more fine grained approach (separate commands for compile definitions, include directories, and compiler options). An example using the new add_compile_definitions: add_compile_definitions(OPENCV_VERSION=${OpenCV_VERSION}) add_compile_definitions(WITH_OPENCV2) Or: add_compile_definitions(OPENCV_VERSION=${OpenCV_VERSION} WITH_OPENCV2) The good part about this is that it circumvents … Read more

CMake Error: CMake was unable to find a build program corresponding to “MinGW Makefiles”

mingw32-make.exe can be installed with the standard MinGW32 installer via the appropriate checkbox: As rubenvb points out, you’ll still need to ensure that it makes it into your PATH. If you edit your environment variables via System Properties, be sure to close and reopen the CMake GUI. If you’re more accustomed to using make.exe, install … Read more

How can I decide what to put in my CMakeList.txt’s cmake_minimum_required call?

The cmake_minimum_required() function is used to avoid any cryptic error messages due to the CMakeLists.txt assuming a later version of CMake than the one installed on the current host. As an example, failing early, and with a clear message… CMake 3.2 or higher is required. You are running version 2.8.12.2 …is to be preferred over … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)