Use CMake to build and run cross-platform (WIN32 and LINUX) code. (Part 1)

CMake is a build configuration tool. In other words, CMake generates Makefiles. This post gives an example on how to configure CMake (the actual content of CMakeLists.txt) to build and run C++ code in Windows as well as in Linux. Here it goes:

cmake_minimum_required(VERSION 3.22.1)

# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
  cmake_policy(SET CMP0141 NEW)
  set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")

message(STATUS "Checking target system...")

   message(STATUS "Target system is Windows")
   set(BOOST_ROOT <Path to your boost directory in Windows>)
   set(Boost_INCLUDE_DIR ${BOOST_DIR})

   message(STATUS "Target system is Linux")
   set(BOOST_ROOT <Path to your boost directory in Linux>)

find_package(Boost REQUIRED)

project(<Project name>)
add_executable(<Project name>
target_compile_features(<Project name>PUBLIC cxx_std_20)
target_link_libraries(<Project name> ${Boost_SYSTEM_LIBRARY})

The example above links only the headers and not the binaries. How to link binaries will come in the next part.

What to do after Ubuntu upgrade to get WordPress site work again?

Assuming a standard wordpress installation using nginx server, here are the steps to keep wordpress running after upgrading Ubuntu.

1. Edit nginx config file:

sudo vim /etc/nginx/sites-available/{YOUR_SITE}

and modify the line:

fastcgi_pass unix:/run/php/php7.2-fpm.sock;

with correct version of php7.x-fpm.sock (should be one higher than the one in nginx). If you don’t know the version of php-fpm use this command to find out:

sudo apt list --installed | grep php

and look for php<version>-fpm.

2. Install php libraries which were removed as obsolete.


sudo apt-get install php$PHP_VERSION-cli php$PHP_VERSION-cgi php$PHP_VERSION-fpm php$PHP_VERSION-mysql

PHP_VERSION should be the same in the one in nginx config file.

3. Restart php$PHP_VERSION-fpm:

sudo systemctl restart php7.2-fpm.service

4. Restart nginx:

sudo systemctl restart nginx.service