cmake_modules/utils.cmake
author nemo
Sun, 23 Jun 2013 17:11:29 -0400
changeset 9249 7b8c82785145
parent 9227 c02e081ba481
child 9244 bb95e351270c
permissions -rw-r--r--
Configuration for tag display default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8686
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
     1
9225
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
     2
#find package helpers
8686
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
     3
macro(find_package_or_fail _PKG_NAME)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
     4
    find_package(${_PKG_NAME})
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
     5
    string(TOUPPER ${_PKG_NAME} _PKG_NAME_UP)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
     6
    if(NOT ${_PKG_NAME_UP}_FOUND)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
     7
        message(SEND_ERROR "Missing ${_PKG_NAME}! Please install it and rerun cmake.")
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
     8
    endif(NOT ${_PKG_NAME_UP}_FOUND)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
     9
endmacro(find_package_or_fail _PKG_NAME)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
    10
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
    11
macro(find_package_or_disable _PKG_NAME _VAR_NAME)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
    12
    find_package(${_PKG_NAME})
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
    13
    string(TOUPPER ${_PKG_NAME} _PKG_NAME_UP)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
    14
    if(NOT ${_PKG_NAME_UP}_FOUND)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
    15
        message(SEND_ERROR "Missing ${_PKG_NAME}! Rerun cmake with -D${_VAR_NAME}=1 to build without it.")
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
    16
    endif(NOT ${_PKG_NAME_UP}_FOUND)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
    17
endmacro(find_package_or_disable _PKG_NAME _VAR_NAME)
d303da4568b7 introduce find_package_or_fail/disable to group together similar cmake code
koda
parents:
diff changeset
    18
8688
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    19
macro(find_package_or_disable_msg _PKG_NAME _VAR_NAME _MSG)
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    20
    if(NOT ${_VAR_NAME})
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    21
        find_package_or_disable(${_PKG_NAME} ${_VAR_NAME})
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    22
    else(NOT ${_VAR_NAME})
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    23
        message(STATUS "${_PKG_NAME} disabled. ${_MSG}")
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    24
        string(TOUPPER ${_PKG_NAME} _PKG_NAME_UP)
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    25
        set(${_PKG_NAME_UP}_FOUND false)
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    26
    endif(NOT ${_VAR_NAME})
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    27
endmacro(find_package_or_disable_msg _PKG_NAME _VAR_NAME _MSG)
88a6114a318c even more wrapping with find_package_or_disable_msg
koda
parents: 8686
diff changeset
    28
9225
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    29
#variable manipulation macros
8772
c9583cf8e10d utility macros for adding compiler flags
koda
parents: 8688
diff changeset
    30
macro(add_flag_append _VAR_NAME _FLAG)
c9583cf8e10d utility macros for adding compiler flags
koda
parents: 8688
diff changeset
    31
    set(${_VAR_NAME} "${${_VAR_NAME}} ${_FLAG}")
c9583cf8e10d utility macros for adding compiler flags
koda
parents: 8688
diff changeset
    32
endmacro(add_flag_append _VAR_NAME _FLAG)
c9583cf8e10d utility macros for adding compiler flags
koda
parents: 8688
diff changeset
    33
c9583cf8e10d utility macros for adding compiler flags
koda
parents: 8688
diff changeset
    34
macro(add_flag_prepend _VAR_NAME _FLAG)
8794
koda
parents: 8772
diff changeset
    35
    set(${_VAR_NAME} "${_FLAG} ${${_VAR_NAME}}")
8772
c9583cf8e10d utility macros for adding compiler flags
koda
parents: 8688
diff changeset
    36
endmacro(add_flag_prepend _VAR_NAME _FLAG)
c9583cf8e10d utility macros for adding compiler flags
koda
parents: 8688
diff changeset
    37
9225
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    38
macro(add_linker_flag _FLAG)
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    39
    list(APPEND haskell_flags "-optl" "${_FLAG}")
9227
c02e081ba481 this should resolve a few issues on clean builds
koda
parents: 9225
diff changeset
    40
    add_flag_append(CMAKE_Pascal_FLAGS "-k${_FLAG}")
c02e081ba481 this should resolve a few issues on clean builds
koda
parents: 9225
diff changeset
    41
    add_flag_append(CMAKE_EXE_LINKER_FLAGS "-Wl,${_FLAG}")
c02e081ba481 this should resolve a few issues on clean builds
koda
parents: 9225
diff changeset
    42
    add_flag_append(CMAKE_SHARED_LIBRARY_C_FLAGS "-Wl,${_FLAG}")
c02e081ba481 this should resolve a few issues on clean builds
koda
parents: 9225
diff changeset
    43
    add_flag_append(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-Wl,${_FLAG}")
9225
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    44
endmacro(add_linker_flag _FLAG)
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    45
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    46
#TODO: find_package_or_bundle
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    47
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    48
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    49