cmake_modules/utils.cmake
author Periklis Ntanasis <pntanasis@gmail.com>
Sat, 10 Aug 2013 20:44:26 +0300
branchspacecampaign
changeset 9512 9686c9116020
parent 9339 14f5f3a1e2f7
permissions -rw-r--r--
fix bug that make precise key not responding
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)
9274
9749524d1767 restore the GLUT check
koda
parents: 9253
diff changeset
    15
        message(SEND_ERROR "Missing ${_PKG_NAME}! Rerun cmake with -D${_VAR_NAME}=1 to skip this error.")
8686
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)
9253
90ea56f4f2f5 oops, fix setting linker flags for haskell executables
koda
parents: 9227
diff changeset
    39
    list(APPEND haskell_flags "-optl" "-Wl,${_FLAG}")
9339
14f5f3a1e2f7 some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents: 9274
diff changeset
    40
    #executables
14f5f3a1e2f7 some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents: 9274
diff changeset
    41
    add_flag_append(CMAKE_C_LINK_FLAGS "-Wl,${_FLAG}")
14f5f3a1e2f7 some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents: 9274
diff changeset
    42
    add_flag_append(CMAKE_CXX_LINK_FLAGS "-Wl,${_FLAG}")
14f5f3a1e2f7 some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents: 9274
diff changeset
    43
    add_flag_append(CMAKE_Pascal_LINK_FLAGS "-k${_FLAG}")
14f5f3a1e2f7 some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents: 9274
diff changeset
    44
    #libraries
9227
c02e081ba481 this should resolve a few issues on clean builds
koda
parents: 9225
diff changeset
    45
    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
    46
    add_flag_append(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-Wl,${_FLAG}")
9339
14f5f3a1e2f7 some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents: 9274
diff changeset
    47
    #CMAKE_SHARED_LIBRARY_Pascal_FLAGS is already set by CMAKE_Pascal_LINK_FLAGS
9225
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    48
endmacro(add_linker_flag _FLAG)
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    49
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    50
#TODO: find_package_or_bundle
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    51
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    52
d8d929f92633 use target name instead of the resulting library, use more macros around
koda
parents: 9224
diff changeset
    53