在CMakeLists.txt中添加FLTK库

时间:2018-08-12 15:25:38

标签: c++ cmake fltk

我需要在我的CMakeLists.txt文件中添加FLTK作为依赖项。 基于<project_root/dist/FLTK>的库。 它内置在<project_root/dist/FLTK/build>目录中。

这是我的孔配置:

cmake_minimum_required(VERSION 2.8)

set(DIST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dist")
set(FLTK "${DIST_DIR}/FLTK")

if(NOT IS_DIRECTORY ${FLTK}) 
  message("Starting add FLTK library...")
  execute_process(COMMAND git submodule add https://github.com/IngwiePhoenix/FLTK.git "${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK") 
  execute_process(COMMAND git submodule update --init --recursive)
endif()

link_directories("${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/build")
add_library(fltk "${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/build/lib")


add_definitions(-Werror -std=c++17)
add_executable(main main.cpp)

怎么了? 谢谢。

1 个答案:

答案 0 :(得分:0)

感谢havogtTsyvarev,我找到了解决方案!我不是CMake的专家,但也许对某些人有帮助:

cmake_minimum_required(VERSION 2.8)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")

set(DIST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dist")
set(FLTK "${DIST_DIR}/FLTK")

if(NOT IS_DIRECTORY ${FLTK}) 
  message("Starting add FLTK library...")
  execute_process(COMMAND git clone https://github.com/fltk/fltk.git ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)
  execute_process(COMMAND make -C ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

add_executable(keyplay ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)

if(APPLE)
  find_library(COCOA Cocoa)
endif()

target_link_libraries(keyplay ${LibFltk} ${COCOA})