cmake execute_process() always fails with “No such file or directory” when I call git

You have to pass the arguments as a second option like this: cmake_minimum_required (VERSION 2.8) set (git_cmd “git”) set (git_arg “–version”) message(STATUS “git cmd: ${git_cmd}”) execute_process(COMMAND ${git_cmd} ${git_arg} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} RESULT_VARIABLE git_result OUTPUT_VARIABLE git_ver) message(STATUS “git ver[${git_result}]: ${git_ver}”)

How can I add a minimum compiler version requisite?

AFAIK, there is no built-in support for something like this, but you could certainly write it yourself: if(CMAKE_CXX_COMPILER_ID STREQUAL “GNU”) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS “your.required.gcc.version”) message(FATAL_ERROR “Insufficient gcc version”) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL “MSVC”) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS “your.required.msvc.version”) message(FATAL_ERROR “Insufficient msvc version”) endif() elseif(…) # etc. endif() However, I suggest you actually consider a feature-detection approach instead. That is, … Read more

How to Trace CMakeLists.txt [duplicate]

There is no CMake debugger or similar¹. What you can do is: Read the output of CMake, sometimes it already gives hints like “missing INCLUDE_MYLIB_DIR”). Delete you CMakeCache.txt and/or remove the build directory, to be sure you don’t miss output because the result was cached. Repeat and check whether caching had an influence. You get … Read more

target_link_libraries and add_dependencies

In current CMake releases: After some error checking add_dependencies results in a call to Target->AddUtility(). x is added to the list of utilities for my-lib. target_link_libraries does not result in a call to AddUtility, but it does add the arguments to the LINK_LIBRARIES target property. Later, both the content of the LINK_LIBRARIES target property and … Read more

Can I install shared imported library?

CMake doesn’t allow to install IMPORTED libraries as TARGETS. Use install(FILES) instead. There are at least 2 reasons for such behavior: Š”itation of one of CMake developer from bug report Imported targets were originally designed for importing from an existing installation of some external package so installing did not make sense at the time. When … Read more

how to add prebuilt object files to executable in cmake

I’ve done this in my projects with target_link_libraries(): target_link_libraries( myProgram ${CMAKE_CURRENT_SOURCE_DIR}/libs/obj.o ) Any full path given to target_link_libraries() is assumed a file to be forwarded to the linker. For CMake version >= 3.9 there are the add_library(… OBJECT IMPORTED ..) targets you can use. See Cmake: Use imported object And – see also the answer … Read more

Difference between CMAKE_PROJECT_NAME and PROJECT_NAME?

From the documentation, I don’t get the difference between the two variables. The difference is that CMAKE_PROJECT_NAME is the name from the last project call from the root CMakeLists.txt, while PROJECT_NAME is from the last project call, regardless from the location of the file containing the command. The difference is recognizable from the following test. … Read more

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