cmake学习06 - 链接第三方库
链接第三方库
windows下下载 https://www.libsdl.org/release/SDL2-devel-2.0.9-VC.zip
解压后工程目录如下:
cmake3/
|-- build
| |-- airplane.bmp
| |-- auto_build.bat
| `-- nature.bmp
|-- cmake3.cpp
|-- CMakeLists.txt
|-- Readme.txt
`-- SDL2-2.0.9
|-- BUGS.txt
|-- COPYING.txt
|-- docs
| |-- doxyfile
| |-- README-android.md
| |-- README-cmake.md
| |-- README-directfb.md
| |-- README-dynapi.md
| |-- README-emscripten.md
| |-- README-gesture.md
| |-- README-hg.md
| |-- README-ios.md
| |-- README-linux.md
| |-- README-macosx.md
| |-- README.md
| |-- README-nacl.md
| |-- README-pandora.md
| |-- README-platforms.md
| |-- README-porting.md
| |-- README-psp.md
| |-- README-raspberrypi.md
| |-- README-touch.md
| |-- README-wince.md
| |-- README-windows.md
| `-- README-winrt.md
|-- include
| |-- begin_code.h
| |-- close_code.h
| |-- SDL_assert.h
| |-- SDL_atomic.h
| |-- SDL_audio.h
| |-- SDL_bits.h
| |-- SDL_blendmode.h
| |-- SDL_clipboard.h
| |-- SDL_config_android.h
| |-- SDL_config.h
| |-- SDL_config.h.cmake
| |-- SDL_config.h.in
| |-- SDL_config_iphoneos.h
| |-- SDL_config_macosx.h
| |-- SDL_config_macosx.h.orig
| |-- SDL_config_minimal.h
| |-- SDL_config_pandora.h
| |-- SDL_config_psp.h
| |-- SDL_config_windows.h
| |-- SDL_config_winrt.h
| |-- SDL_config_wiz.h
| |-- SDL_copying.h
| |-- SDL_cpuinfo.h
| |-- SDL_egl.h
| |-- SDL_endian.h
| |-- SDL_error.h
| |-- SDL_events.h
| |-- SDL_filesystem.h
| |-- SDL_gamecontroller.h
| |-- SDL_gesture.h
| |-- SDL.h
| |-- SDL_haptic.h
| |-- SDL_hints.h
| |-- SDL_joystick.h
| |-- SDL_keyboard.h
| |-- SDL_keycode.h
| |-- SDL_loadso.h
| |-- SDL_log.h
| |-- SDL_main.h
| |-- SDL_messagebox.h
| |-- SDL_mouse.h
| |-- SDL_mutex.h
| |-- SDL_name.h
| |-- SDL_opengles2_gl2ext.h
| |-- SDL_opengles2_gl2.h
| |-- SDL_opengles2_gl2platform.h
| |-- SDL_opengles2.h
| |-- SDL_opengles2_khrplatform.h
| |-- SDL_opengles.h
| |-- SDL_opengl_glext.h
| |-- SDL_opengl.h
| |-- SDL_pixels.h
| |-- SDL_platform.h
| |-- SDL_power.h
| |-- SDL_quit.h
| |-- SDL_rect.h
| |-- SDL_render.h
| |-- SDL_revision.h
| |-- SDL_rwops.h
| |-- SDL_scancode.h
| |-- SDL_sensor.h
| |-- SDL_shape.h
| |-- SDL_stdinc.h
| |-- SDL_surface.h
| |-- SDL_system.h
| |-- SDL_syswm.h
| |-- SDL_test_assert.h
| |-- SDL_test_common.h
| |-- SDL_test_compare.h
| |-- SDL_test_crc32.h
| |-- SDL_test_font.h
| |-- SDL_test_fuzzer.h
| |-- SDL_test.h
| |-- SDL_test_harness.h
| |-- SDL_test_images.h
| |-- SDL_test_log.h
| |-- SDL_test_md5.h
| |-- SDL_test_memory.h
| |-- SDL_test_random.h
| |-- SDL_thread.h
| |-- SDL_timer.h
| |-- SDL_touch.h
| |-- SDL_types.h
| |-- SDL_version.h
| |-- SDL_video.h
| `-- SDL_vulkan.h
|-- lib
| |-- x64
| | |-- SDL2.dll
| | |-- SDL2.lib
| | |-- SDL2main.lib
| | `-- SDL2test.lib
| `-- x86
| |-- SDL2.dll
| |-- SDL2.lib
| |-- SDL2main.lib
| `-- SDL2test.lib
|-- README-SDL.txt
|-- README.txt
`-- WhatsNew.txt
备注:这里先讨论Windows下的CMake的使用方法,Linux请参考类似的做法
cmake3/CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
PROJECT(cmake3)
message(${CMAKE_SOURCE_DIR})
message(${PROJECT_SOURCE_DIR})
#add all source current dir
aux_source_directory(. DIR_SRCS)
include_directories(${CMAKE_SOURCE_DIR}/SDL2-2.0.9/include)
link_directories(${CMAKE_SOURCE_DIR}/SDL2-2.0.9/lib/x64)
add_executable(cmake3 MACOSX_BUNDLE ${DIR_SRCS})
target_link_libraries(cmake3 SDL2 SDL2main)
通过 include_directories 指定SDL2库所在的头文件的位置
通过 link_directories 指定SDL2库所在的库文件的位置
通过 target_link_libraries 指定参与链接的库