source: trunk/cmake/TrMacros.cmake @ 14350

Last change on this file since 14350 was 14350, checked in by mikedld, 8 years ago

#5828: Initial CMake build system support

File size: 2.9 KB
Line 
1macro(tr_auto_option_changed NAME ACC VAL FIL STK)
2    if(NOT ("${VAL}" STREQUAL "AUTO" OR "${VAL}" STREQUAL "ON" OR "${VAL}" STREQUAL "OFF"))
3        if("${VAL}" STREQUAL "0" OR "${VAL}" STREQUAL "NO" OR "${VAL}" STREQUAL "FALSE" OR "${VAL}" STREQUAL "N")
4            set_property(CACHE ${NAME} PROPERTY VALUE OFF)
5        elseif("${VAL}" MATCHES "^[-+]?[0-9]+$" OR "${VAL}" STREQUAL "YES" OR "${VAL}" STREQUAL "TRUE" OR "${VAL}" STREQUAL "Y")
6            set_property(CACHE ${NAME} PROPERTY VALUE ON)
7        else()
8            message(FATAL_ERROR "Option '${NAME}' set to unrecognized value '${VAL}'. Should be boolean or 'AUTO'.")
9        endif()
10    endif()
11endmacro()
12
13macro(tr_auto_option NAME DESC VAL)
14    set(${NAME} "${VAL}" CACHE STRING "${DESC}")
15    set_property(CACHE ${NAME} PROPERTY STRINGS "AUTO;ON;OFF")
16    variable_watch(${NAME} tr_auto_option_changed)
17endmacro()
18
19macro(tr_fixup_auto_option NAME ISFOUND ISREQ)
20    if(${ISFOUND})
21        set_property(CACHE ${NAME} PROPERTY VALUE ON)
22    elseif(NOT (${ISREQ}))
23        set_property(CACHE ${NAME} PROPERTY VALUE OFF)
24    endif()
25endmacro()
26
27macro(tr_get_required_flag IVAR OVAR)
28    set(${OVAR})
29    if (${IVAR} AND NOT ${IVAR} STREQUAL "AUTO")
30        set(${OVAR} REQUIRED)
31    endif()
32endmacro()
33
34function(tr_make_id INPUT OVAR)
35    string(TOUPPER "${INPUT}" ID)
36    string(REGEX REPLACE "[^A-Z0-9]+" "_" ID "${ID}")
37    string(REGEX REPLACE "^_+|_+$" "" ID "${ID}")
38    set(${OVAR} "${ID}" PARENT_SCOPE)
39endfunction()
40
41macro(tr_github_upstream ID REPOID RELID RELMD5)
42    set(${ID}_RELEASE "${RELID}")
43    set(${ID}_UPSTREAM URL "https://github.com/${REPOID}/archive/${RELID}.tar.gz" URL_MD5 "${RELMD5}")
44endmacro()
45
46macro(tr_add_external_auto_library ID LIBNAME)
47    if(USE_SYSTEM_${ID})
48        tr_get_required_flag(USE_SYSTEM_${ID} SYSTEM_${ID}_IS_REQUIRED)
49        find_package(${ID} ${${ID}_MINIMUM} ${SYSTEM_${ID}_IS_REQUIRED})
50        tr_fixup_auto_option(USE_SYSTEM_${ID} ${ID}_FOUND SYSTEM_${ID}_IS_REQUIRED)
51    endif()
52
53    if(USE_SYSTEM_${ID})
54        unset(${ID}_UPSTREAM_TARGET)
55    else()
56        set(${ID}_UPSTREAM_TARGET ${LIBNAME}-${${ID}_RELEASE})
57        set(${ID}_PREFIX "${CMAKE_BINARY_DIR}/third-party/${${ID}_UPSTREAM_TARGET}")
58
59        ExternalProject_Add(
60            ${${ID}_UPSTREAM_TARGET}
61            ${${ID}_UPSTREAM}
62            ${ARGN}
63            PREFIX "${${ID}_PREFIX}"
64            CMAKE_ARGS
65                "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
66                "-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}"
67                "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
68                "-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>"
69        )
70
71        set(${ID}_INCLUDE_DIR "${${ID}_PREFIX}/include" CACHE INTERNAL "")
72        set(${ID}_LIBRARY "${${ID}_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${LIBNAME}${CMAKE_STATIC_LIBRARY_SUFFIX}" CACHE INTERNAL "")
73
74        set(${ID}_INCLUDE_DIRS ${${ID}_INCLUDE_DIR})
75        set(${ID}_LIBRARIES ${${ID}_LIBRARY})
76    endif()
77endmacro()
Note: See TracBrowser for help on using the repository browser.