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

Common Syntax of CMake (List)

Common Syntax of CMake (List)

Previous Highlights:CMake Hello, WorldCMake VariablesCMake Official Tutorial (Basic Project Setup)CMake Official Tutorial (Library Creation)CMake Official Tutorial (Usage Requirements)CMake Official Tutorial (Installation and Testing)CMake Common Syntax (if Statement)CMake Common Syntax (Cache Variables)CMake Common Syntax (Environment Variables)CMake Common Syntax (Mathematical Calculations)CMake Common Syntax (Strings) In CMake, a list is a collection of strings separated by semicolons, and … Read more

Using CMake: Static and Dynamic Libraries

Using CMake: Static and Dynamic Libraries

When compiling a new program, we will use third-party compiled library files or library files that we compiled ourselves. Here we will use the static and dynamic libraries that have been compiled previously.1. Using Static LibrariesThe file structure is as follows. Here we have deleted add.c and subtract.c from the src folder, keeping only main.c, … Read more

Common Syntax of CMake (Strings)

Common Syntax of CMake (Strings)

Previous Highlights:CMake Hello, WorldCMake VariablesCMake Official Tutorial (Basic Project Setup)CMake Official Tutorial (Library Creation)CMake Official Tutorial (Usage Requirements)CMake Official Tutorial (Installation and Testing)CMake Common Syntax (if Statements)CMake Common Syntax (Cache Variables)CMake Common Syntax (Environment Variables)CMake Common Syntax (Mathematical Calculations) In mainstream programming languages, strings are a fundamental and core data type, which is crucial, and … Read more

CMake Tutorial

CMake Tutorial

1. Introduction to CMake CMake is a cross-platform build tool, which can generate: Makefile for Linux/Unix Project files for <span>Visual Studio</span> on Windows Project files for <span>Xcode</span> on macOS without manually writing build scripts for different platforms. 2. Installing CMake Windows: Download the installer from cmake.org/download Linux: <span>sudo apt install cmake</span> (Debian/Ubuntu) macOS: <span>brew install … Read more

Different Linking Methods for CMake Libraries

Different Linking Methods for CMake Libraries

1. Different Libraries Have Different Linking Methods OpenCV uses ${OpenCV_LIBS} target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}) protobuf uses ${PROTOBUF_LIBRARIES} target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARIES}) jpeg-turbo uses the target name libjpeg-turbo::turbojpeg-static target_link_libraries(${PROJECT_NAME} libjpeg-turbo::turbojpeg-static) 2. How to Determine Which Method to Use Generally, the following methods can be used: Check the CMake file for usage instructions. (Well-written CMake files usually include usage instructions) Look … Read more