source: git/modules/SingularMacros.cmake @ fec53d

fieker-DuValspielwiese
Last change on this file since fec53d was 8cc501, checked in by Kai Krüger <krueger@…>, 14 years ago
Added files to compile with cmake. Still experimental. Might not work git-svn-id: file:///usr/local/Singular/svn/trunk@13240 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.1 KB
Line 
1# -*- mode: cmake; -*-
2#
3
4function(whereami MSG)
5  message(STATUS "====== ${MSG} ======")
6endfunction()
7
8#################################################################
9###  create the Singular version file version.h.tmp
10###  and copy it only if it has changed
11###  the reduces the number of recompiles
12###
13function(singular_mk_version GEN_H_FILE)
14  set(_filenameTmp ${CMAKE_CURRENT_BINARY_DIR}/version.h.tmp)
15  set(_GEN_H_FILE ${CMAKE_CURRENT_BINARY_DIR}/version.h)
16  message(STATUS "Creating version file '${_GEN_H_FILE}'")
17  #set(_CC_FLAGS  "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE} ${ADD_DEFS}")
18  #set(_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${ADD_DEFS}")
19  set(_CC_FLAGS  "${CMAKE_C_FLAGS} ${ADD_DEFS}")
20  set(_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADD_DEFS}")
21  set(_CC        "${CMAKE_C_COMPILER} ${_CC_FLAGS}")
22  set(_CXX       "${CMAKE_CXX_COMPILER} ${_CXX_FLAGS}")
23
24  set(_version_file "${CMAKE_CURRENT_SOURCE_DIR}/svnver")
25  if(EXISTS ${_version_file})
26    file(READ  ${_version_file} _data)
27    string(REGEX REPLACE "\n$" "" _version ${_data})
28  else(EXISTS ${_version_file})
29    set(_version "2009102101")
30  endif(EXISTS ${_version_file})
31
32  write_file(${_filenameTmp} "/* generated by cmake */\n")
33  write_file(${_filenameTmp} "#define feVersionId \"${_version}\"" APPEND)
34  write_file(${_filenameTmp} "#define CC        \"${_CC}\"" APPEND)
35  write_file(${_filenameTmp} "#define CXX       \"${_CXX}\"" APPEND)
36  write_file(${_filenameTmp} "#define CC_FLAGS  \"${_CC_FLAGS}\"" APPEND)
37  write_file(${_filenameTmp} "#define CXX_FLAGS \"${_CXX_FLAGS}\"" APPEND)
38  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different 
39    "${_filenameTmp}" "${_GEN_H_FILE}"
40    #OUTPUT_QUIET ERROR_QUIET
41    )
42  set(${GEN_H_FILE} ${${GEN_H_FILE}} PARENT_SCOPE)
43endfunction()
44
45#
46#
47#
48macro(singular_generate_incfile TARGET GEN_FILE GENCMD NAME )
49  message(STATUS "generate incfile ${NAME}.inc ...")
50  #set(_GEN_TARGET "${NAME}-inc")
51  set(_GEN_FILE   ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.inc)
52  message(STATUS "Generate ${GENCMD} to ${_GEN_FILE}.")
53
54  add_custom_command(OUTPUT ${_GEN_FILE}
55  #add_custom_target(${TARGET}
56    COMMAND ${GENCMD}
57    DEPENDS ${GENCMD}
58    COMMENT "Creating '${NAME}.inc'..."
59    )
60  add_custom_target(${TARGET}
61    DEPENDS ${_GEN_FILE}
62    )
63
64  #  add_custom_target(${TARGET} DEPENDS ${GEN_FILE})
65  set(${GEN_FILE}   ${_GEN_FILE})
66  #set(${GEN_TARGET} ${_GEN_TARGET} PARENT_SCOPE)
67endmacro()
68
69#
70#
71#
72function(add_index GEN_FILE FEOPT_CMD INFILE )
73  message(STATUS "add_index ${INFILE}...")
74  set(_GEN_FILE ${CMAKE_CURRENT_BINARY_DIR}/${INFILE}.inc)
75  #set(_GEN_CMD  ${CMAKE_CURRENT_BINARY_DIR}/${INFILE})
76  message(STATUS "Generate ${FEOPT_CMD}.")
77
78  #set(_cmd_srcs ${CMAKE_CURRENT_SOURCE_DIR}/feOpt.cc mod2.h)
79  #add_definitions( -DGENERATE_OPTION_INDEX ${ADDDEFINE} )
80  #include_directories(${CMAKE_SOURCE_DIR}/kernel)
81  #add_executable(${INFILE} ${_cmd_srcs})
82#  //-DGENERATE_OPTION_INDEX -I../kernel
83  add_custom_command(
84    OUTPUT ${_GEN_FILE}
85    COMMAND ${FEOPT_CMD}
86    DEPENDS ${FEOPT_CMD}
87    COMMENT "Compiling '${INFILE}'..."
88    )
89
90  set(${GEN_FILE} ${_GEN_FILE} PARENT_SCOPE)
91endfunction()
92
93#
94# generate iparith table
95#
96function(singular_gen_iparith GEN_TARGET GEN_FILE GEN_CMD )
97  message(STATUS "singular_gen_iparith ${INFILE}...")
98  set(_GEN_TARGET "iparith-inc")
99  set(_GEN_FILE "${CMAKE_CURRENT_BINARY_DIR}/iparith.inc")
100  set(_GEN_CMD "gentable")
101
102  message(STATUS "out: ${_GEN_FILE}")
103  message(STATUS "in: ${INFILES}")
104  #message(STATUS "dep: ${DEPENDENCIES}")
105  message(STATUS "argv: ${ARGV}")
106  message(STATUS "argn: ${ARGC}")
107  message(STATUS "argn: '${ARGN}'")
108  message(STATUS "cxxFlags: '${CXX_FLAGS}'")
109  set(_gen_srcs ${ARGN})
110
111  #  set(_gen_srcs claptmpl.cc iparith.cc ipconv.cc tok.h mpsr_Tok.cc grammar.h mod2.h)
112  #set(_gen_srcs ${ARGN})
113  #add_executable(${_GEN_CMD} ${_gen_srcs})
114  #set_target_properties(gentable PROPERTIES COMPILE_FLAGS "-DGENTABLE")
115  #
116  #     ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} -DGENTABLE \
117  #          -o gentable claptmpl.o iparith.cc tesths.cc mpsr_Tok.cc \
118  #          ${OBJS} ${LDFLAGS} ${LIBS} ../kernel/mmalloc.o
119  #     ./gentable
120  #     /bin/rm -f gentable gentable.exe
121
122  message(STATUS "src: '${_gen_srcs}'")
123  add_custom_command(
124    OUTPUT ${_GEN_FILE}
125    COMMAND ${GEN_CMD}
126    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
127    DEPENDS ${GEN_CMD}
128    MAIN_DEPENDENCY ${GEN_CMD} ${_gen_srcs}
129    COMMENT "generating arithmetic table '${_GEN_FILE}'...")
130
131  message(STATUS "src: '${_gen_srcs}'")
132  set(${GEN_FILE} ${_GEN_FILE} PARENT_SCOPE)
133  set(${GEN_TARGET} ${_GEN_TARGET} PARENT_SCOPE)
134endfunction()
135
136#################################################################
137### copy/install Singular(LIB)s -files
138###
139function(singular_copy_LIB FILES)
140
141  message(STATUS "Copying Singular library files.")
142  foreach(loop_var ${ARGV})
143    #message(STATUS "Copying ${loop_var}")
144    execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different 
145      "${loop_var}" "${CMAKE_CURRENT_BINARY_DIR}"
146      #OUTPUT_QUIET ERROR_QUIET
147      )
148    #configure_file(${loop_var} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
149  endforeach(loop_var ${ARGV})
150endfunction()
151
152#################################################################
153### create the Singular LIB file all.lib
154###
155macro(singular_mk_allLIB TARGET OUT_FILE LIBFILES)
156  #set(_GEN_TARGET "all.lib")
157  #set(${GEN_FILE} "all.lib")
158  set(_tmplFile "${CMAKE_CURRENT_SOURCE_DIR}/${OUT_FILE}.tmpl")
159  set(_tmpFile  "${CMAKE_CURRENT_BINARY_DIR}/${OUT_FILE}.tmp")
160  set(_outFile  "${CMAKE_CURRENT_BINARY_DIR}/${OUT_FILE}")
161
162  set(i 0)
163  file(WRITE ${_tmpFile} "")
164  message(STATUS "Creating '${OUT_FILE}' ${_tmpFile}")
165  execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${_tmplFile}" "${_tmpFile}")
166  foreach(loop_var ${ARGV})
167    math(EXPR i ${i}+1)
168    if( ${i} GREATER 3)
169      string(REGEX REPLACE "^.*/" "" filename ${loop_var})
170      write_file(${_tmpFile} "LIB \"${filename}\";" APPEND)
171    endif( ${i} GREATER 2)
172  endforeach(loop_var)
173
174  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different 
175    "${_tmpFile}" "${_outFile}"
176    )
177#COMMAND ${CMAKE_COMMAND} -E remove "${_tmpFile}"
178    add_custom_target(${TARGET})
179endmacro()
180
Note: See TracBrowser for help on using the repository browser.