-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCmakeLists.txt
80 lines (69 loc) · 3.97 KB
/
CmakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
cmake_minimum_required (VERSION 3.1)
project(CommonLibraries)
include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
include(ExternalProject)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "Default Targets")
set(EXTERNAL_CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}")
# Set a default build type if none was specified
set(default_build_type "Release")
# If we have a multi config generator only set the first type
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES_LENGTH)
list(LENGTH CMAKE_CONFIGURATION_TYPES CMAKE_CONFIGURATION_TYPES_LENGTH)
if(CMAKE_CONFIGURATION_TYPES_LENGTH GREATER "1")
set(CONF_TYPE)
list(GET CMAKE_CONFIGURATION_TYPES 0 CONF_TYPE)
set(CMAKE_CONFIGURATION_TYPES ${CONF_TYPE} CACHE STRING "Choose the type of build (only one is allowed), options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
endif()
set(EXTERNAL_PROJECT_BUILD_TYPE "Unknown")
if(CMAKE_CONFIGURATION_TYPES)
list(GET CMAKE_CONFIGURATION_TYPES 0 CONF_TYPE)
set(EXTERNAL_PROJECT_BUILD_TYPE ${CONF_TYPE})
elseif(CMAKE_BUILD_TYPE)
set(EXTERNAL_PROJECT_BUILD_TYPE ${CMAKE_BUILD_TYPE})
endif()
# Some helper vars to detect if debug or release
if(EXTERNAL_PROJECT_BUILD_TYPE STREQUAL "Debug")
set(EXTERNAL_PROJECT_IS_DEBUG true)
elseif(EXTERNAL_PROJECT_BUILD_TYPE STREQUAL "Release")
set(EXTERNAL_PROJECT_IS_RELEASE true)
endif()
# The generator as a string without spaces
set(EXTERNAL_PROJECT_GENERATOR "unknown")
string(REPLACE " " "-" EXTERNAL_PROJECT_GENERATOR ${CMAKE_GENERATOR})
# What cmake binary are we using
message(STATUS "Used cmake binary: ${CMAKE_COMMAND}")
set(EXTERNAL_PKG_CONFIG_PATH "")
# A macro used to include the lib build scripts ans set some basic vars
macro(include_and_prepare script)
get_filename_component(EXTERNAL_PROJECT_NAME ${script} NAME_WE)
set(EXTERNAL_PROJECT_PREFIX ${EXTERNAL_PROJECT_NAME}_${EXTERNAL_PROJECT_GENERATOR}_${EXTERNAL_PROJECT_BUILD_TYPE})
set(EXTERNAL_PROJECT_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/${EXTERNAL_PROJECT_PREFIX})
set(EXTERNAL_PROJECT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${EXTERNAL_PROJECT_NAME})
unset(EXTERNAL_PROJECT_PKG_CONFIG_PATH)
include(${script})
set(EXTERNAL_CMAKE_PREFIX_PATH "${EXTERNAL_CMAKE_PREFIX_PATH};${EXTERNAL_PROJECT_INSTALL_DIR}")
set(EXTERNAL_LIB_PATH "${EXTERNAL_LIB_PATH};${EXTERNAL_PROJECT_INSTALL_DIR}/lib;${EXTERNAL_PROJECT_INSTALL_DIR}/bin")
set(EXTERNAL_BIN_PATH "${EXTERNAL_BIN_PATH};${EXTERNAL_PROJECT_INSTALL_DIR}/bin")
set(EXTERNAL_INCLUDE_PATH "${EXTERNAL_INCLUDE_PATH};${EXTERNAL_PROJECT_INSTALL_DIR}/include")
if(EXTERNAL_PROJECT_PKG_CONFIG_PATH)
set(EXTERNAL_PKG_CONFIG_PATH "${EXTERNAL_PKG_CONFIG_PATH};${EXTERNAL_PROJECT_PKG_CONFIG_PATH}")
endif()
set(${EXTERNAL_PROJECT_NAME}_EXTERNAL_PATH "${EXTERNAL_PROJECT_INSTALL_DIR}")
set(${EXTERNAL_PROJECT_NAME}_EXTERNAL_LIB_PATH "${EXTERNAL_PROJECT_INSTALL_DIR}/lib")
set(${EXTERNAL_PROJECT_NAME}_EXTERNAL_BIN_PATH "${EXTERNAL_PROJECT_INSTALL_DIR}/bin")
set(${EXTERNAL_PROJECT_NAME}_EXTERNAL_INCLUDE_PATH "${EXTERNAL_PROJECT_INSTALL_DIR}/include")
set(EXTERNAL_CMAKE_PREFIX_PATH_REL "${EXTERNAL_CMAKE_PREFIX_PATH_REL};${EXTERNAL_PROJECT_PREFIX}")
set(EXTERNAL_LIB_PATH_REL "${EXTERNAL_LIB_PATH_REL};${EXTERNAL_PROJECT_PREFIX}/lib;${EXTERNAL_PROJECT_PREFIX}/bin")
set(EXTERNAL_BIN_PATH_REL "${EXTERNAL_BIN_PATH_REL};${EXTERNAL_PROJECT_PREFIX}/bin")
set(EXTERNAL_INCLUDE_PATH_REL "${EXTERNAL_INCLUDE_PATH_REL};${EXTERNAL_PROJECT_PREFIX}/include")
endmacro(include_and_prepare)
include(mkspecs/mkspecs.cmake)
set(CMAKE_INSTALL_DIR "cmake")
configure_package_config_file("${CMAKE_SOURCE_DIR}/commonLibsConfig.cmake.in" "${CMAKE_BINARY_DIR}/commonLibsConfig.cmake" INSTALL_DESTINATION cmake
PATH_VARS CMAKE_INSTALL_DIR)
configure_file("${CMAKE_SOURCE_DIR}/commonLibs.cmake.in" "${CMAKE_BINARY_DIR}/commonLibs_${EXTERNAL_PROJECT_BUILD_TYPE}.cmake" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/commonLibsConfig.cmake" "${CMAKE_BINARY_DIR}/commonLibs_${EXTERNAL_PROJECT_BUILD_TYPE}.cmake" DESTINATION cmake)