introducción a cmake en inglés
TRANSCRIPT
![Page 1: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/1.jpg)
Introduccion Ejecutando CMake Ejemplos Final
CMake: Sistema de Compilacion para C/C++
Daniel Molina
Universidad of Cadiz, Departamento de Lenguaje y Sistemas Informaticos,OSLUCA
29 de Junio 2009, Cadiz
![Page 2: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/2.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Presentacion
1 Introduccion
2 Ejecutando CMake
3 Ejemplos
![Page 3: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/3.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Que es CMake
CMake:
Genera ficheros de compilacion.
Unix/Linux → Makefiles.Windows → Proyectos Visual Studio.Apple → Xcode.
Multiplataforma.Software Libre :-).
Pero si mi aplicacion no es multiplataforma
Mas sencillo que Makefiles a mano.
¿Para eso no estan las autotools?
![Page 4: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/4.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Que es CMake
CMake:
Genera ficheros de compilacion.
Unix/Linux → Makefiles.Windows → Proyectos Visual Studio.Apple → Xcode.
Multiplataforma.Software Libre :-).
Pero si mi aplicacion no es multiplataforma
Mas sencillo que Makefiles a mano.
¿Para eso no estan las autotools?
![Page 5: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/5.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Que es CMake
CMake:
Genera ficheros de compilacion.
Unix/Linux → Makefiles.Windows → Proyectos Visual Studio.Apple → Xcode.
Multiplataforma.
Software Libre :-).
Pero si mi aplicacion no es multiplataforma
Mas sencillo que Makefiles a mano.
¿Para eso no estan las autotools?
![Page 6: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/6.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Que es CMake
CMake:
Genera ficheros de compilacion.
Unix/Linux → Makefiles.Windows → Proyectos Visual Studio.Apple → Xcode.
Multiplataforma.Software Libre :-).
Pero si mi aplicacion no es multiplataforma
Mas sencillo que Makefiles a mano.
¿Para eso no estan las autotools?
![Page 7: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/7.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Que es CMake
CMake:
Genera ficheros de compilacion.
Unix/Linux → Makefiles.Windows → Proyectos Visual Studio.Apple → Xcode.
Multiplataforma.Software Libre :-).
Pero si mi aplicacion no es multiplataforma
Mas sencillo que Makefiles a mano.
¿Para eso no estan las autotools?
![Page 8: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/8.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Que es CMake
CMake:
Genera ficheros de compilacion.
Unix/Linux → Makefiles.Windows → Proyectos Visual Studio.Apple → Xcode.
Multiplataforma.Software Libre :-).
Pero si mi aplicacion no es multiplataforma
Mas sencillo que Makefiles a mano.
¿Para eso no estan las autotools?
![Page 9: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/9.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Que es CMake
CMake:
Genera ficheros de compilacion.
Unix/Linux → Makefiles.Windows → Proyectos Visual Studio.Apple → Xcode.
Multiplataforma.Software Libre :-).
Pero si mi aplicacion no es multiplataforma
Mas sencillo que Makefiles a mano.
¿Para eso no estan las autotools?
![Page 10: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/10.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ventajas frente a Makefile y Autotools
CMake Versus Makefile
Mas comodo y facil.
¿He dicho que es mas facil?
Portable.
Mas opciones(busqueda de librerıas, . . .).
CMake Versus Autotools
Menor curva de aprendizaje.
No usa M4 :-).
Mas portable.
Mas facil de extender.
Mejor documentado.
![Page 11: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/11.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ventajas frente a Makefile y Autotools
CMake Versus Makefile
Mas comodo y facil.
¿He dicho que es mas facil?
Portable.
Mas opciones(busqueda de librerıas, . . .).
CMake Versus Autotools
Menor curva de aprendizaje.
No usa M4 :-).
Mas portable.
Mas facil de extender.
Mejor documentado.
![Page 12: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/12.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ventajas frente a Makefile y Autotools
CMake Versus Makefile
Mas comodo y facil.
¿He dicho que es mas facil?
Portable.
Mas opciones(busqueda de librerıas, . . .).
CMake Versus Autotools
Menor curva de aprendizaje.
No usa M4 :-).
Mas portable.
Mas facil de extender.
Mejor documentado.
![Page 13: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/13.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ventajas frente a Makefile y Autotools
CMake Versus Makefile
Mas comodo y facil.
¿He dicho que es mas facil?
Portable.
Mas opciones(busqueda de librerıas, . . .).
CMake Versus Autotools
Menor curva de aprendizaje.
No usa M4 :-).
Mas portable.
Mas facil de extender.
Mejor documentado.
![Page 14: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/14.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ventajas frente a Makefile y Autotools
CMake Versus Makefile
Mas comodo y facil.
¿He dicho que es mas facil?
Portable.
Mas opciones(busqueda de librerıas, . . .).
CMake Versus Autotools
Menor curva de aprendizaje.
No usa M4 :-).
Mas portable.
Mas facil de extender.
Mejor documentado.
![Page 15: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/15.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Caracterısticas de CMake
Utilizado en entornos complejos (VTK+, KDE4, . . . ).
Flexible y Extensible.
Soporte de macros (buscar/configurar software).
Ejecutar programar externos.
Syntaxis Intuitiva.
Modos de compilacion (Debug, Release, . . . ).
Admite jerarquıa de directorios complejas, y detecta librerıas.
![Page 16: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/16.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Quien lo esta usando
Kitware, http://www.kitware.com/
The Visualization ToolKit (VTK), http://www.vtk.org/
ParaView, http://www.paraview.org/
KDE 4, https://lwn.net/Articles/188693/
![Page 17: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/17.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Estructura
CMakefiles.txt: Formato del fichero, define el flujo de controlen sintaxis CMake.
Modulos CMake: Modulos que extienden la funcionalidad deCMake, principalmente en buscar aplicaciones/herramientas.
Ejemplo: FindQt4.cmake, FindJava.cmake
![Page 18: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/18.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejecutando CMake
Preparar el fichero CMakeLists.txt:
Con editor favorito.Visualmente: cmake-gui.
Ejecutar cmake . → Makefile
Compilar (make)
![Page 19: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/19.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejemplo: “Hello, World”
Estructura
hello src
hello.cCMakeLists.txt
Makefile
CMakeFiles
CMakeCache.txt
cmake install.cmake
hello
CMakeLists.txt
PROJECT(hello C)SET(SRC
hello.c)
ADD EXECUTABLE(hello ${SRC})
![Page 20: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/20.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejemplo: “Hello, World”
Estructura
hello src
hello.cCMakeLists.txt
Makefile
CMakeFiles
CMakeCache.txt
cmake install.cmake
hello
CMakeLists.txt
PROJECT(hello C)SET(SRC
hello.c)
ADD EXECUTABLE(hello ${SRC})
![Page 21: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/21.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejemplo: “Hello, World”
Estructura
hello src
hello.cCMakeLists.txt
Makefile
CMakeFiles
CMakeCache.txt
cmake install.cmake
hello
CMakeLists.txt
PROJECT(hello C)SET(SRC
hello.c)
ADD EXECUTABLE(hello ${SRC})
![Page 22: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/22.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejemplo: “Hello, World”
Estructura
hello src
hello.cCMakeLists.txt
Makefile
→ Fichero autogenerado
CMakeFiles
→ Directorio con ficheros objeto (.o)
CMakeCache.txt
→ Fichero cache (evitar recompilarinnecesariamente)
cmake install.cmake
→ Fichero de instalacion/desistalacion(cuando se usa)
hello → Ejecutable
![Page 23: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/23.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejemplo: “Hello, World”
Estructura
hello src
hello.cCMakeLists.txt
Makefile → Fichero autogenerado
CMakeFiles
→ Directorio con ficheros objeto (.o)
CMakeCache.txt
→ Fichero cache (evitar recompilarinnecesariamente)
cmake install.cmake
→ Fichero de instalacion/desistalacion(cuando se usa)
hello → Ejecutable
![Page 24: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/24.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejemplo: “Hello, World”
Estructura
hello src
hello.cCMakeLists.txt
Makefile → Fichero autogenerado
CMakeFiles → Directorio con ficheros objeto (.o)
CMakeCache.txt
→ Fichero cache (evitar recompilarinnecesariamente)
cmake install.cmake
→ Fichero de instalacion/desistalacion(cuando se usa)
hello → Ejecutable
![Page 25: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/25.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejemplo: “Hello, World”
Estructura
hello src
hello.cCMakeLists.txt
Makefile → Fichero autogenerado
CMakeFiles → Directorio con ficheros objeto (.o)
CMakeCache.txt → Fichero cache (evitar recompilarinnecesariamente)
cmake install.cmake
→ Fichero de instalacion/desistalacion(cuando se usa)
hello → Ejecutable
![Page 26: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/26.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejemplo: “Hello, World”
Estructura
hello src
hello.cCMakeLists.txt
Makefile → Fichero autogenerado
CMakeFiles → Directorio con ficheros objeto (.o)
CMakeCache.txt → Fichero cache (evitar recompilarinnecesariamente)
cmake install.cmake → Fichero de instalacion/desistalacion(cuando se usa)
hello → Ejecutable
![Page 27: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/27.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Ejemplo: “Hello, World”
Otra alternativa:
mkdir buildcd buildcmake ..
Ası, todos los ficheros adicionales estan en bin
Tambien se puede hacer configurando adecuadamenteCMakeLists.txt
![Page 28: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/28.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Otras versiones
hellolib.c
#i n c l u d e <s t d i o . h>#i n c l u d e <s t r i n g . h>
v o i d get msg ( c h a r ∗msg ) {s t r c p y ( msg , ” h e l l o , w o r l d\n ” ) ;
}
hellolib.h
#i f n d e f HELLO LIB H
#d e f i n e HELLO LIB H 1
v o i d get msg ( c h a r ∗msg ) ;
#e n d i f
hello.c
/∗ h e l l o . c : d i s p l a y a messageon t h e s c r e e n ∗/
#i n c l u d e <s t d i o . h>#i n c l u d e ” h e l l o l i b . h”
i n t main ( v o i d ) {c h a r msg [ 3 0 ] ;
get msg ( msg ) ;p r i n t f ( msg ) ;r e t u r n 0 ;
}
![Page 29: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/29.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Usando Librerıa Dinamica Versus Sin Usar
Sin ibrerıa
PROJECT( h e l l o C)SET(SRC
h e l l oh e l l o l i b )
ADD EXECUTABLE( h e l l o ${SRC})
Con Librerıa Dinamica
PROJECT( h e l l o C)SET( LIBSRC
h e l l o l i b )
SET(SRCh e l l o )
ADD LIBRARY( h e l l o l i b SHARED ${LIBSRC})
ADD EXECUTABLE( h e l l o ${SRC})
TARGET LINK LIBRARIES ( h e l l o h e l l o l i b )
![Page 30: Introducción a CMake en inglés](https://reader033.vdocuments.site/reader033/viewer/2022051816/546b496faf79597b298b4b9a/html5/thumbnails/30.jpg)
Introduccion Ejecutando CMake Ejemplos Final
Espero que esta introduccionmotive para el taller
¿Empezamos? :-)