Compiling the latest version of CMake from sources on Ubuntu

I was unable to add QML resources to a QT Quick application with CMake 2.8 installed on my machine, so I built the latest version of CMake with the following commands:

cd ~/examples
mkdir tools
cd tools
mkdir install
tar -xf ~/Downloads/cmake-3.9.1.tar.gz
cd cmake-3.9.1/
./configure --prefix=/home/dmitry/examples/tools/install/
make -j4
make install

Now my QT application is compiled and run successfully:

~/examples/tools/install/bin/cmake ../../OsgQmlTest/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MODULE_PATH=/home/user/3rdpart/osg/CMakeModules/ -DCMAKE_INSTALL_PREFIX=/home/dmitry/examples/install
make -j4
make install

Its CMake file is:

cmake_minimum_required(VERSION 2.8.12)
project(OsgQmlTest)

# Tell CMake to run moc when necessary:
set(CMAKE_AUTOMOC ON)
# As moc files are generated in the binary dir, tell CMake
# to always look for includes there:
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#The rcc tool is used to embed resources into a Qt application during the build process.
set(CMAKE_AUTORCC ON)

# Widgets finds its own dependencies.
find_package(Qt5Core  REQUIRED)
find_package(Qt5Gui   REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Qml REQUIRED)

qt5_add_resources(RESOURCES qml.qrc)

set(CPP_FILES ${CMAKE_SOURCE_DIR}/main.cpp)

#file(GLOB_RECURSE QML_FILES "${CMAKE_SOURCE_DIR}/*.qml")
#add_custom_target(qml_files SOURCES ${QML_FILES})

add_executable(${PROJECT_NAME} ${CPP_FILES} ${RESOURCES})

qt5_use_modules(${PROJECT_NAME} Core Gui Widgets Quick Qml)

install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

When I replaced the commented lines with qtquick_add_resources macro, I built the application with CMake 2.8.12 as well as with CMake 3.9.1. See also CMake manual.

On Windows CMAKE_PREFIX_PATH is used instead of CMAKE_MODULE_PATH:

cmake ..\..\geoviewer -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:\Repos\install -DCMAKE_PREFIX_PATH=C:\Qt\5.8\msvc2015\lib\cmake
msbuild GeoViewer.sln

this build 32-bit application in Debug folder that requires PATH to be set to C:\Qt\5.8\msvc2015\bin (where 32-bit DLLs are located).

The following command with -LAH option shows all the variables set by CMake:

cmake ..\..\examples\src\LinesGame\LinesGameQt\ --no-warn-unused-cli -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:\Repos\install -DCMAKE_PREFIX_PATH=C:\Qt\5.8\msvc2015\lib\cmake -LAH
cmake ..\..\examples\src\LinesGame\LinesGameQt\ -DCMAKE_INSTALL_PREFIX=D:\Repos\install -DCMAKE_PREFIX_PATH=C:\Qt\5.8\msvc2015\lib\cmake
"C:\Program Files\CMake\bin\cmake.exe" ..\..\examples\src\LinesGame\LinesGameQt -DCMAKE_PREFIX_PATH=C:\Qt\Qt5.9.1\5.9.1\msvc2015\lib\cmake
msbuild LinesGameQt.sln /property:Configuration=Debug
msbuild LinesGameQt.sln /property:Configuration=RelWithDebInfo
msbuild LinesGameQt.sln /property:Configuration=Release
msbuild LinesGameQt.sln /p:Configuration="Debug"

Looks like DCMAKE_BUILD_TYPE option does not make a sense witn MSVS.

Compiling with a specific version of GCC:

~/examples/tools/install/bin/cmake ../../Awl/ -DCMAKE_C_COMPILER=/usr/bin/gcc-7 -DCMAKE_CXX_COMPILER=/usr/bin/g++-7
~/examples/tools/install/bin/cmake -DCMAKE_C_COMPILER=/usr/bin/gcc-7 -DCMAKE_CXX_COMPILER=/usr/bin/g++-7 -DCMAKE_BUILD_TYPE=Debug -- -j4 --build ../../Awl/

2 Responses to Compiling the latest version of CMake from sources on Ubuntu

  1. superadmin says:

    Compiling with a specific version of GCC: cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++

Leave a Reply

Your email address will not be published. Required fields are marked *