CMakeLists.txt 2.9 KB
Newer Older
1
#CMakelists for using EMBB as an external library in a project
2 3 4 5 6 7 8 9 10
project (EMBB_USER_PROJECT)
set(EXECUTABLE_NAME exec)
cmake_minimum_required (VERSION 2.8.9)

# Version number
set (EMBB_USER_PROJECT_BASE_VERSION_MAJOR 0)
set (EMBB_USER_PROJECT_BASE_VERSION_MINOR 0)
set (EMBB_USER_PROJECT_BASE_VERSION_PATCH 1)

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

# Make a browsable file hierarchy when opening
# the generated visual c++ solution project in visual studio
function(GroupSourcesMSVC directory)
   file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${directory} ${PROJECT_SOURCE_DIR}/${directory}/*)
   foreach(child ${children})
          if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${directory}/${child})
                  GroupSourcesMSVC(${directory}/${child})
          else()
                  string(REPLACE "/" "\\" groupname ${directory})
                  string(REPLACE "src" "Sources" groupname ${groupname})
                  string(REPLACE "include" "Includes" groupname ${groupname})
            source_group(${groupname} FILES ${PROJECT_SOURCE_DIR}/${directory}/${child})
          endif()
   endforeach()
endfunction()

####################
29
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
30
    
31 32
    set(INT_DIR "/${CMAKE_CFG_INTDIR}/")
    set(ADDITIONAL_LIBS "")
33
    GroupSourcesMSVC(src)
34
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
35
   
36 37 38 39 40 41
    set(INT_DIR "/")
    set(ADDITIONAL_LIBS "pthread" "rt")
else()
 message(FATAL_ERROR "Unsupported compiler ${CMAKE_CXX_COMPILER_ID}")
endif()

42 43 44 45 46 47 48 49 50
### begin external project
include(ExternalProject)
file(GLOB EMBB_LIB_FILE ${CMAKE_SOURCE_DIR}/external/embb*.tar.gz)
ExternalProject_Add(EMBB
  URL ${EMBB_LIB_FILE}
  CMAKE_ARGS -DBUILD_TESTS=OFF
  INSTALL_COMMAND ""
)

51

52 53 54 55 56 57
ExternalProject_Get_Property(EMBB source_dir)
ExternalProject_Get_Property(EMBB binary_dir)

set(EMBB_BINARY_DIR ${binary_dir})
set(EMBB_SOURCE_DIR ${source_dir})

58 59
set(EMBB_DIRS containers_cpp algorithms_cpp dataflow_cpp tasks_cpp mtapi_cpp base_cpp mtapi_c base_c) #link order matters for GNU compiler
set(EMBB_GENERATED_INCLUDE base_c base_cpp tasks_cpp) # modules with cmake generated header files
60 61 62 63
### end external project

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)

64 65


66 67 68 69 70 71 72

file(GLOB_RECURSE EMBB_USER_PROJECT_SOURCES "src/*.cpp" "src/*.h")
file(GLOB_RECURSE EMBB_USER_PROJECT_HEADERS "src/*.h")

add_executable(${EXECUTABLE_NAME} ${EMBB_USER_PROJECT_SOURCES} ${EMBB_USER_PROJECT_HEADERS})
add_dependencies(${EXECUTABLE_NAME} EMBB)

73 74 75 76
######################################
 set(pref ${CMAKE_STATIC_LIBRARY_PREFIX}embb_)
 set(suf ${CMAKE_STATIC_LIBRARY_SUFFIX})
 
77 78 79 80
foreach(dir ${EMBB_DIRS})
  include_directories ("${EMBB_SOURCE_DIR}/${dir}/include")
  list(APPEND LIBS "${EMBB_BINARY_DIR}/${dir}${INT_DIR}${pref}${dir}${suf}")
endforeach()
81

82 83 84
foreach(dir ${EMBB_GENERATED_INCLUDE})
    include_directories("${EMBB_BINARY_DIR}/${dir}/include")
endforeach()
85

86
target_link_libraries( ${EXECUTABLE_NAME} ${LIBS} ${ADDITIONAL_LIBS}   )
87 88