CMake Basics: Compiling Static and Dynamic Libraries, Customizing Library Output Paths

CMake Basics: Compiling Static and Dynamic Libraries, Customizing Library Output Paths

1. Generate a static library for third-party useIn Linux, the name of a static library is composed of: lib + library name + .a, where the library name needs to be specified, and lib and .a are generated automatically. The Windows system is similar.Project file structure:CMakeLists.txt # Set the minimum required CMake version to 3.15 … Read more

CMake Basics: Compiling Multiple Source Files Together

CMake Basics: Compiling Multiple Source Files Together

1. Multiple source files add.c and subtract.c are in one folder, the file structure is as follows:head.h #ifndef _HEAD_H #define _HEAD_H // Add int add(int a, int b); // Subtract int subtract(int a, int b); #endif add.c #include <stdio.h> #include "head.h" // Add int add(int a, int b) { return a + b; } subtract.c … Read more

Basic Usage of CMake: A Must for Native Cross-Platform Development

Basic Usage of CMake: A Must for Native Cross-Platform Development

CMake is an open-source, cross-platform suite of tools for building, testing, and packaging software. CMake controls the software compilation process using simple platform and compiler-independent configuration files (CMakeLists.txt) and generates native build files and workspaces that can be used in your chosen build environment. The CMake suite was created by Kitware in response to the … Read more

CMake Tips: Do You Really Understand add_dependencies and find_package?

CMake Tips: Do You Really Understand add_dependencies and find_package?

In the world of CMake, mastering dependency management is an essential skill for every developer. Today, we will discuss the two commands add_dependencies and find_package, exploring their differences and how to use them correctly. 🔧 add_dependencies is used to set target dependencies. For example, if you have a custom target or executable that needs to … Read more

Building and Linking Dynamic and Static Libraries with CMake Made Simple!

Building and Linking Dynamic and Static Libraries with CMake Made Simple!

Click the blue textFollow the author 1. Introduction In slightly more complex projects, we often encounter situations where we need to build multiple executable files, each potentially composed of different source files. More commonly, the project’s source code is distributed across multiple subdirectories rather than being concentrated in a single directory. ProjectRoot ├── CMakeLists.txt (Top-level … Read more

How to Solve 90% of Build Problems with CMake Using Conditions and Loops?

How to Solve 90% of Build Problems with CMake Using Conditions and Loops?

Click the blue textFollow the author 1. Introduction So far, the CMake examples we have encountered follow a straightforward process: starting from a series of source files, ultimately building into a single executable program or generating static/dynamic libraries. This linear process is simple and easy to understand, but often proves inadequate in more complex projects. … Read more

CMake Compilation Optimization – Precompiled Header Files

CMake Compilation Optimization - Precompiled Header Files

<span>target_precompile_headers</span> is a feature introduced in CMake 3.16, used to generate precompiled header files (Precompiled Headers, PCH) for specific targets (such as executables or libraries). Precompiled header files can significantly speed up compilation, especially when there are many repeated header file inclusions in the project. 1. The Role of Precompiled Header Files Reduce Redundant Compilation: … Read more

CMake vs qmake: Which One Should You Choose?

CMake vs qmake: Which One Should You Choose?

CMake vs qmake: Which One Should You Choose? 🔥 Today, let’s discuss CMake and qmake, two tools used for managing project builds, but they have significant differences! 💡 Design Philosophy • CMake: It is a cross-platform build system generator that supports various compilers and build tools, such as Make, Ninja, Visual Studio, etc. It handles … Read more