Installing cmake with home-brew

Typing brew install cmake as you did installs cmake. Now you can type cmake and use it. If typing cmake doesn’t work make sure /usr/local/bin is your PATH. You can see it with echo $PATH. If you don’t see /usr/local/bin in it add the following to your ~/.bashrc: export PATH=”/usr/local/bin:$PATH” Then reload your shell session … Read more

How do I initialize a CMake variable with the result of a shell command

You want the execute_process command. In your case, on Windows: execute_process(COMMAND CMD /c echo bar OUTPUT_VARIABLE FOO) or on Linux, simply: execute_process(COMMAND echo bar OUTPUT_VARIABLE FOO) In this particular case, CMake offers a cross-platform solution. CMake can itself be used to run commands that can be used on all systems, one of which is echo. … Read more

CMake and finding other projects and their dependencies

Easy. Here is the example from the top of my head: The top level CMakeLists.txt: cmake_minimum_required(VERSION 2.8.10) # You can tweak some common (for all subprojects) stuff here. For example: set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) set(CMAKE_DISABLE_SOURCE_CHANGES ON) if (“${CMAKE_SOURCE_DIR}” STREQUAL “${CMAKE_BINARY_DIR}”) message(SEND_ERROR “In-source builds are not allowed.”) endif () set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_COLOR_MAKEFILE ON) # Remove ‘lib’ prefix for … Read more

Compile with /MT instead of /MD using CMake

You can modify the CMAKE_<LANG>_FLAGS_<CONFIG> variables: set(CMAKE_CXX_FLAGS_RELEASE “${CMAKE_CXX_FLAGS_RELEASE} /MT”) set(CMAKE_CXX_FLAGS_DEBUG “${CMAKE_CXX_FLAGS_DEBUG} /MTd”) If your CMake flags already contain /MD, you can ensure that the above commands are executed after the point at which /MD is inserted (the later addition of /MT overrides the conflicting existing option), or you can set the flags from scratch: set(CMAKE_CXX_FLAGS_RELEASE … Read more

How do I debug CMakeLists.txt files?

There is no interactive debugger for CMake, however there are also the flags -Wdev, –debug-output and –trace which might help. Also remember to check the log files CMakeFiles\CMakeOutput.log and CMakeFiles\CMakeError.log which mainly collect outputs of processes called by CMake (for example while checking for presence of a type or header). Since version 3.7, CMake now … Read more

Function vs. Macro in CMake

I wrote a sample code below: set(var “ABC”) macro(Moo arg) message(“arg = ${arg}”) set(arg “abc”) message(“# After change the value of arg.”) message(“arg = ${arg}”) endmacro() message(“=== Call macro ===”) Moo(${var}) function(Foo arg) message(“arg = ${arg}”) set(arg “abc”) message(“# After change the value of arg.”) message(“arg = ${arg}”) endfunction() message(“=== Call function ===”) Foo(${var}) and … Read more

What is the modern method for setting general compile flags in CMake?

For modern CMake (versions 2.8.12 and up) you should use target_compile_options, which uses target properties internally. CMAKE_<LANG>_FLAGS is a global variable and the most error-prone to use. It also does not support generator expressions, which can come in very handy. add_compile_options is based on directory properties, which is fine in some situations, but usually not … Read more

Set CFLAGS and CXXFLAGS options using CMake

You need to set the flags after the project command in your CMakeLists.txt. Also, if you’re calling include(${QT_USE_FILE}) or add_definitions(${QT_DEFINITIONS}), you should include these set commands after the Qt ones since these would append further flags. If that is the case, you maybe just want to append your flags to the Qt ones, so change … Read more

What is the proper way to use `pkg-config` from `cmake`?

First of, the call: include(FindPkgConfig) should be replaced with: find_package(PkgConfig) The find_package() call is more flexible and allows options such as REQUIRED, that do things automatically that one would have to do manually with include(). Secondly, manually calling pkg-config should be avoid when possible. CMake comes with a rich set of package definitions, found in … Read more

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