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>>")
endif()

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

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

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

set(Boost_USE_STATIC_LIBS_ON)
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})

project(<Project name>)
add_executable(<Project name>
    main.cc
)
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.

How to assess your level of preparation for the tech interviews

PREPARATION. PREPARATION. PREPARATION. Preparation is the key to be successful in any interview and land that job or internship that you always wanted. When you decide you need a job, the first thing you do is evaluate your preparation level. Self-assessment can be tricky. Sometimes we are over confident, and sometimes we are under confident. Knowing what you know is the key. Before we proceed further, I am assuming that you are well familiar with Computer Science fundamentals and can at least solve how to reverse a linked list using two pointers and using recursion without any hints. If you are not sure you can answer these directly, go to the section ‘Prepare from scratch’ explained below first and then come back and continue with the rest of the sections. Continue reading “How to assess your level of preparation for the tech interviews”