]> git.lyx.org Git - lyx.git/blob - development/cmake/modules/LyXMacros.cmake
Initial cmake support.
[lyx.git] / development / cmake / modules / LyXMacros.cmake
1
2 macro(lyx_add_path _list _prefix)
3         set(_tmp)
4         foreach(_current ${${_list}})
5                 set(_tmp ${_tmp} ${_prefix}/${_current})
6                 #message( ${_prefix}/${_current})
7         endforeach(_current)     
8         set(${_list} ${_tmp})  
9 endmacro(lyx_add_path _out _prefix)
10
11
12 #create the implementation files from the ui files and add them to the list of sources
13 #usage: LYX_ADD_QT4_UI_FILES(foo_SRCS ${ui_files})
14 macro (LYX_ADD_QT4_UI_FILES _sources )
15    foreach (_current_FILE ${ARGN})
16
17       get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
18       get_filename_component(_basename ${_tmp_FILE} NAME_WE)
19       set(_header ${CMAKE_CURRENT_BINARY_DIR}/ui/${_basename}.h)
20
21       # we need to run uic and replace some things in the generated file
22       # this is done by executing the cmake script kde4uic.cmake
23       add_custom_command(OUTPUT ${_header}
24          COMMAND ${CMAKE_COMMAND}
25          ARGS
26          -DKDE4_HEADER:BOOL=ON
27          -DKDE_UIC_EXECUTABLE:FILEPATH=${QT_UIC_EXECUTABLE}
28          -DKDE_UIC_FILE:FILEPATH=${_tmp_FILE}
29          -DKDE_UIC_H_FILE:FILEPATH=${_header}
30          -DKDE_UIC_BASENAME:STRING=${_basename}
31          -P ${CMAKE_MODULE_PATH}/LyXuic.cmake
32          MAIN_DEPENDENCY ${_tmp_FILE}
33       )
34       set(${_sources} ${${_sources}} ${_header})
35    endforeach (_current_FILE)
36 endmacro (LYX_ADD_QT4_UI_FILES)
37
38
39
40 MACRO (LYX_AUTOMOC)
41    QT4_GET_MOC_INC_DIRS(_moc_INCS)
42
43    set(_matching_FILES )
44    foreach (_current_FILE ${ARGN})
45
46       get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
47       # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
48       # here. this is required to make bouic work correctly:
49       # we need to add generated .cpp files to the sources (to compile them),
50       # but we cannot let automoc handle them, as the .cpp files don't exist yet when
51       # cmake is run for the very first time on them -> however the .cpp files might
52       # exist at a later run. at that time we need to skip them, so that we don't add two
53       # different rules for the same moc file
54       get_source_file_property(_skip ${_abs_FILE} SKIP_AUTOMOC)
55
56       if (EXISTS ${_abs_FILE} AND NOT _skip)
57
58          file(READ ${_abs_FILE} _contents)
59
60          get_filename_component(_abs_PATH ${_abs_FILE} PATH)
61
62          string(REGEX MATCHALL "#include +[^ ]+_moc\\.cpp[\">]" _match "${_contents}")
63          if (_match)
64             foreach (_current_MOC_INC ${_match})
65                string(REGEX MATCH "[^ <\"]+_moc\\.cpp" _current_MOC "${_current_MOC_INC}")
66
67                get_filename_component(_basename ${_current_MOC} NAME_WE)               
68                         
69                                 string(LENGTH ${_basename} _length)
70                                 MATH(EXPR _mocless_length ${_length}-4)
71                                 STRING(SUBSTRING  ${_basename} 0 ${_mocless_length} _mocless_name )
72    
73           set(_header ${_abs_PATH}/${_mocless_name}.h)
74           
75           #message(STATUS "moc : ${_header}")
76
77
78
79                #set(_header ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.h)
80                #set(_header ${_abs_PATH}/${_basename}.h)
81                set(_moc    ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
82                
83    #set(_moc    ${_abs_PATH}/${_current_MOC})
84        add_custom_command(OUTPUT ${_moc}
85         COMMAND ${QT_MOC_EXECUTABLE}
86         ARGS ${_moc_INCS} ${_header} -o ${_moc}
87         MAIN_DEPENDENCY ${_header}
88      )
89                macro_add_file_dependencies(${_abs_FILE} ${_moc})
90
91             endforeach (_current_MOC_INC)
92          else(_match)
93                 #message(STATUS "moc not found : ${_abs_FILE} ")
94          endif (_match)
95
96       endif (EXISTS ${_abs_FILE} AND NOT _skip)
97    endforeach (_current_FILE)
98 endmacro (LYX_AUTOMOC)
99