Skip to content

Commit 5348eb0

Browse files
committed
Add more info on external libraries
1 parent ffa2728 commit 5348eb0

File tree

479 files changed

+1109
-32233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

479 files changed

+1109
-32233
lines changed

CMake_Cheatsheet.pdf

8.78 KB
Binary file not shown.

CMake_Cheatsheet.tex

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ \section*{CMake Cheatsheet -- A gentle introduction to CMake} % Title
9292

9393
This cheatsheet will give you an idea how CMake works and how it can be used to configure software projects.
9494

95-
The document is available at \url{https://github.com/mortennobel/CMake-Cheatsheet}.
95+
The document and the CMake examples are available at \url{https://github.com/mortennobel/CMake-Cheatsheet}.
9696

9797
\sectiontitle{CMake - Creating a simple C++ project}
9898

@@ -218,7 +218,7 @@ \section*{CMake Cheatsheet -- A gentle introduction to CMake} % Title
218218
219219
\lstinputlisting[language=bash]{examples/example6/somelib/CMakeLists.txt}
220220
221-
Finally, the executable Hello is compiled and linked to the Foo library. Since the main.cpp references to header file Foo.hpp the somelib directory is added to the header search path:
221+
Finally, the executable Hello is compiled and linked to the Foo library - note that the target name is used here - not the actual path. Since the main.cpp references to header file Foo.hpp the somelib directory is added to the header search path:
222222
223223
\lstinputlisting[language=bash]{examples/example6/someexe/CMakeLists.txt}
224224
@@ -245,6 +245,35 @@ \section*{CMake Cheatsheet -- A gentle introduction to CMake} % Title
245245
246246
Note: One problem with this approach is if you modify the original resources, then you need to run CMake again.
247247
248+
\sectiontitle{External libraries}
249+
250+
External libraries basically come in two flavors; dynamically linked libraries (DLLs) which are linked with the binary at runtime and statical linked libraries which are linked at compile time.
251+
252+
Static libraries have the most simple setup. To use one, the compiler needs to know the location of where to locate the header files and the linker need to know the location of the actual library. Unless the external libraries are distributed along with the project it is usually not possible to know their location - for this reason, it is common to use cached variables, where the CMake user can change the location. Static libraries have the file ending .lib on Windows and .a on most other platforms.
253+
254+
\lstinputlisting[language=bash]{examples/example8/CMakeLists.txt}
255+
256+
Dynamically linked libraries work similar to statical linked libraries. On Windows, it is still needed to link to a library at compile time, but the actual linking to the DLL happens at compile time. The executable file needs to be able to find the DLL file in the runtime linkers search path. If the DLL is not a system library, an easy solution is to copy the DLL next to the executable. Working with DLL often requires platform specific actions, which CMake support using the built-in variables \codeword{WIN32}, \codeword{APPLE}, \codeword{UNIX}.
257+
258+
\lstinputlisting[language=bash]{examples/example9/CMakeLists.txt}
259+
260+
\sectiontitle{Automatically locating libraries}
261+
262+
CMake also contains a feature to automatically find libraries (based on a number of suggested locations) using the command \codeword{find_package()}. However, this feature works best on macOS and Linux.
263+
264+
\url{https://cmake.org/Wiki/CMake:How_To_Find_Libraries}.
265+
266+
\sectiontitle{C++ version}
267+
268+
The C++ version can be set using the commands:
269+
270+
\begin{lstlisting}[language=bash]
271+
set(CMAKE_CXX_STANDARD 14)
272+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
273+
set(CMAKE_CXX_EXTENSIONS OFF)
274+
\end{lstlisting}
275+
276+
248277
\vspace{\baselineskip} % Whitespace before the next section
249278
250279
%----------------------------------------------------------------------------------------

examples/cmake-build-debug/CMakeCache.txt

Lines changed: 0 additions & 340 deletions
This file was deleted.

examples/cmake-build-debug/CMakeFiles/3.8.2/CMakeCCompiler.cmake

Lines changed: 0 additions & 68 deletions
This file was deleted.

examples/cmake-build-debug/CMakeFiles/3.8.2/CMakeCXXCompiler.cmake

Lines changed: 0 additions & 70 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.

examples/cmake-build-debug/CMakeFiles/3.8.2/CMakeSystem.cmake

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)