/[zanavi_public1]/navit/cmake/navit_macros.cmake
ZANavi

Contents of /navit/cmake/navit_macros.cmake

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56 - (show annotations) (download)
Sun Mar 19 08:44:36 2017 UTC (5 years, 6 months ago) by zoff99
File size: 4561 byte(s)
updates
1 macro(set_feature_switch_default VARIABLE REASON ENABLE)
2 if ((NOT DEFINED ${VARIABLE}) # variable not in cache (first run)
3 OR ((DEFINED ${VARIABLE}_AUTODETECTED_VALUE) AND # variable in cache -> different from autodetected value?
4 ((${VARIABLE}_AUTODETECTED_VALUE AND ${VARIABLE}) OR # poor man's boolean equal
5 (NOT ${VARIABLE}_AUTODETECTED_VALUE AND NOT ${VARIABLE}))))
6 set(${VARIABLE}_REASON ${REASON})
7 set(${VARIABLE} ${ENABLE} CACHE BOOL "feature switch" FORCE)
8 else()
9 set(${VARIABLE}_REASON "User defined")
10 endif()
11 set(${VARIABLE}_AUTODETECTED_VALUE ${ENABLE} CACHE INTERNAL "value autodetected by build script")
12 endmacro()
13
14 macro(set_with_reason VARIABLE REASON ENABLE)
15 if (DEFINED ${VARIABLE}_REASON AND NOT ${VARIABLE}_REASON STREQUAL "User defined")
16 set(${VARIABLE} ${ENABLE} CACHE BOOL "feature switch" FORCE)
17 set(${VARIABLE}_REASON ${REASON})
18 endif()
19 string(REPLACE "/" "_" VARIABLE_NAMES ${VARIABLE})
20 set(${VARIABLE_NAMES}_LIBS ${ARGN})
21 set(${VARIABLE}_AUTODETECTED_VALUE ${ENABLE} CACHE INTERNAL "value autodetected by build script")
22 endmacro()
23
24 macro(add_feature FEATURE REASON ENABLE)
25 list(APPEND ALL_FEATURES ${FEATURE})
26 set_feature_switch_default(${FEATURE} ${REASON} ${ENABLE})
27 endmacro()
28
29 macro(cfg_feature FEATURE REASON ENABLE)
30 set(${FEATURE} ${ENABLE})
31 if (${FEATURE}_REASON STREQUAL "User defined")
32 set(${FEATURE}_REASON "${REASON} *user setting overridden*")
33 else()
34 set(${FEATURE}_REASON ${REASON})
35 endif()
36 endmacro()
37
38 macro(add_module MODULE_PATH REASON ENABLE)
39 list(APPEND ALL_MODULES ${MODULE_PATH})
40 set_feature_switch_default(${MODULE_PATH} ${REASON} ${ENABLE})
41 endmacro()
42
43 # plugins are always linked static
44 macro(add_plugin PLUGIN_PATH REASON ENABLE)
45 list(APPEND ALL_PLUGINS ${PLUGIN_PATH})
46 set_feature_switch_default(${PLUGIN_PATH} ${REASON} ${ENABLE})
47 endmacro()
48
49 # module plugins are always linked static
50 macro(add_module_plugin PLUGIN_PATH REASON ENABLE)
51 list(APPEND ALL_MODULE_PLUGINS ${PLUGIN_PATH})
52 set_feature_switch_default(${PLUGIN_PATH} ${REASON} ${ENABLE})
53 endmacro()
54
55 macro(module_add_library MODULE_NAME )
56 LINK_DIRECTORIES(${${MODULE_NAME}_LIBRARY_DIRS})
57 add_library(${MODULE_NAME} ${MODULE_BUILD_TYPE} ${ARGN})
58 SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES COMPILE_DEFINITIONS "MODULE=${MODULE_NAME}")
59 TARGET_LINK_LIBRARIES(${MODULE_NAME} ${${MODULE_NAME}_LIBS})
60 SET_TARGET_PROPERTIES( ${MODULE_NAME} PROPERTIES COMPILE_FLAGS "${NAVIT_COMPILE_FLAGS} ${${MODULE_NAME}_FLAGS}")
61 INCLUDE_DIRECTORIES(${${MODULE_NAME}_INCLUDES})
62 if (USE_PLUGINS)
63 if (ANDROID)
64 TARGET_LINK_LIBRARIES(${MODULE_NAME} ${NAVIT_LIBNAME})
65 endif()
66 if (APPLE)
67 set_target_properties( ${MODULE_NAME} PROPERTIES LINK_FLAGS "-Wl,-undefined -Wl,dynamic_lookup")
68 endif()
69 # workaround to be compatible with old paths
70 set_target_properties( ${MODULE_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/.libs")
71
72 install(TARGETS ${MODULE_NAME}
73 DESTINATION ${LIB_DIR}/navit/${${MODULE_NAME}_TYPE}
74 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
75 endif()
76 endmacro(module_add_library)
77
78 macro(supportlib_add_library LIB_NAME )
79 add_library(${LIB_NAME} ${ARGN})
80 TARGET_LINK_LIBRARIES(${LIB_NAME} ${${LIB_NAME}_LIBS})
81 SET_TARGET_PROPERTIES( ${LIB_NAME} PROPERTIES COMPILE_FLAGS "${NAVIT_COMPILE_FLAGS}")
82 SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES COMPILE_DEFINITIONS "MODULE=${LIB_NAME}")
83 endmacro(supportlib_add_library)
84
85 macro(message_error)
86 set(NAVIT_DEPENDENCY_ERROR 1)
87 message( SEND_ERROR ${ARGN})
88 endmacro(message_error)
89
90 include(CheckCCompilerFlag)
91 include(CheckCXXCompilerFlag)
92 function(add_compiler_flag_if_available FLAG)
93 set(VAR_FLAG_AVAILABLE_C "FLAG_AVAILABLE_C_${FLAG}")
94 check_c_compiler_flag(${FLAG} ${VAR_FLAG_AVAILABLE_C})
95 if (${${VAR_FLAG_AVAILABLE_C}})
96 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG} ")
97 endif()
98 if(CMAKE_CXX_COMPILER_LOADED) # C++ compiler is optional
99 set(VAR_FLAG_AVAILABLE_CXX "FLAG_AVAILABLE_CXX_${FLAG}")
100 check_cxx_compiler_flag(${FLAG} ${VAR_FLAG_AVAILABLE_CXX})
101 if (${${VAR_FLAG_AVAILABLE_CXX}})
102 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG} ")
103 endif()
104 endif()
105 endfunction(add_compiler_flag_if_available)

   
Visit the ZANavi Wiki