2 cmake_minimum_required(VERSION 2.6)
5 # Detect native platform
7 set(BUILD_SHARED_LIBS ON)
8 if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM")
9 set(TCC_NATIVE_TARGET "WinCE")
10 elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
11 set(TCC_NATIVE_TARGET "Win64")
13 set(TCC_NATIVE_TARGET "Win32")
16 if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
17 set(TCC_NATIVE_TARGET "ARM")
18 if(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv5")
19 set(TCC_ARM_VERSION_DEFAULT 5)
20 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv6")
21 set(TCC_ARM_VERSION_DEFAULT 6)
22 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv7")
23 set(TCC_ARM_VERSION_DEFAULT 7)
25 set(TCC_ARM_VERSION_DEFAULT 4)
27 elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
28 set(TCC_NATIVE_TARGET "x86_64")
29 set(TCC_ARCH_DIR "x86_64-linux-gnu")
31 set(TCC_NATIVE_TARGET "i386")
32 set(TCC_ARCH_DIR "i386-linux-gnu")
43 set(TCC_LIB_PATH lib/tcc)
44 set(NATIVE_LIB_PATH lib)
45 set(DOC_PATH share/doc/tcc)
49 if(EXISTS /usr/lib/${TCC_ARCH_DIR}/crti.o)
50 set(CONFIG_LDDIR lib/${TCC_ARCH_DIR})
51 set(CONFIG_MULTIARCHDIR ${TCC_ARCH_DIR})
52 elseif(EXISTS /usr/lib64/crti.o)
53 set(CONFIG_LDDIR lib64)
57 # Use two variables to keep CMake configuration variable names consistent
58 set(TCC_BCHECK OFF CACHE BOOL "Enable bounds checking")
59 set(CONFIG_TCC_BCHECK ${TCC_BCHECK})
60 set(TCC_ASSERT OFF CACHE BOOL "Enable assertions")
61 set(CONFIG_TCC_ASSERT ${TCC_ASSERT})
63 set(TCC_BUILD_NATIVE ON CACHE BOOL "Build native compiler")
64 set(TCC_BUILD_I386 OFF CACHE BOOL "Build i386 cross compiler")
65 set(TCC_BUILD_X64 OFF CACHE BOOL "Build x86-64 cross compiler")
66 set(TCC_BUILD_WIN32 OFF CACHE BOOL "Build Windows i386 cross compiler")
67 set(TCC_BUILD_WIN64 OFF CACHE BOOL "Build Windows x86-64 cross compiler")
68 set(TCC_BUILD_WINCE OFF CACHE BOOL "Build Windows CE cross compiler")
69 set(TCC_BUILD_ARM_FPA OFF CACHE BOOL "Build arm-fpa cross compiler")
70 set(TCC_BUILD_ARM_FPA_LD OFF CACHE BOOL "Build arm-fpa-ld cross compiler")
71 set(TCC_BUILD_ARM_VFP OFF CACHE BOOL "Build arm-vfp cross compiler")
72 set(TCC_BUILD_ARM_EABI OFF CACHE BOOL "Build ARM EABI cross compiler")
73 set(TCC_BUILD_ARM_EABIHF OFF CACHE BOOL "Build ARM EABI hardware float cross compiler")
74 set(TCC_BUILD_ARM OFF CACHE BOOL "Build ARM cross compiler")
75 set(TCC_BUILD_C67 OFF CACHE BOOL "Build C67 cross compiler")
77 set(TCC_ARM_VERSION ${TCC_ARM_VERSION_DEFAULT} CACHE STRING "ARM target CPU version")
78 set_property(CACHE TCC_ARM_VERSION PROPERTY STRINGS 4 5 6 7)
81 set(CONFIG_TCCDIR ${CMAKE_INSTALL_PREFIX})
83 set(CONFIG_TCCDIR ${CMAKE_INSTALL_PREFIX}/lib/tcc)
86 file(STRINGS "VERSION" TCC_VERSION)
87 list(GET TCC_VERSION 0 TCC_VERSION)
88 include_directories(${CMAKE_BINARY_DIR})
89 configure_file(config.h.in config.h)
90 configure_file(config.texi.in config.texi)
93 set(I386_SOURCES i386-gen.c i386-asm.c i386-asm.h i386-tok.h)
94 set(X86_64_SOURCES x86_64-gen.c i386-asm.c x86_64-asm.h)
95 set(ARM_SOURCES arm_gen.c)
97 set(LIBTCC1_I386_SOURCES lib/alloca86.S lib/alloca86-bt.S)
98 set(LIBTCC1_WIN_SOURCES win32/lib/crt1.c win32/lib/wincrt1.c win32/lib/dllcrt1.c win32/lib/dllmain.c win32/lib/chkstk.S)
100 set(LIBTCC1_I386_SOURCES ${LIBTCC1_I386_SOURCES} lib/bcheck.c)
104 add_executable(tiny_impdef win32/tools/tiny_impdef.c)
106 add_executable(tiny_libmaker_32 win32/tools/tiny_libmaker.c)
107 set_target_properties(tiny_libmaker_32 PROPERTIES COMPILE_DEFINITIONS TCC_TARGET_I386)
108 add_executable(tiny_libmaker_64 win32/tools/tiny_libmaker.c)
109 set_target_properties(tiny_libmaker_64 PROPERTIES COMPILE_DEFINITIONS TCC_TARGET_X86_64)
111 macro(make_libtcc1 prefix xcc xar defs includes sources)
113 if("${prefix}" STRGREATER "")
114 set(libtcc1_prefix ${prefix}-)
116 set(libtcc1_flags -I${CMAKE_SOURCE_DIR}/include)
118 set(libtcc1_flags ${libtcc1_flags} -D${i})
120 foreach(i ${includes})
121 set(libtcc1_flags ${libtcc1_flags} -I${CMAKE_SOURCE_DIR}/${i})
124 foreach(libtcc1_c lib/libtcc1.c ${sources})
125 string(REGEX MATCH "[^/]+$" libtcc1_o ${libtcc1_c})
126 string(REGEX MATCH "^[^.]+" libtcc1_o ${libtcc1_o})
127 set(libtcc1_o ${libtcc1_prefix}${libtcc1_o}.o)
128 add_custom_command(OUTPUT ${libtcc1_o}
129 COMMAND ${xcc} ${libtcc1_flags} -c ${CMAKE_SOURCE_DIR}/${libtcc1_c} -o ${libtcc1_o}
130 DEPENDS ${xcc} ${CMAKE_SOURCE_DIR}/${libtcc1_c}
132 list(APPEND libtcc1_objects ${libtcc1_o})
134 add_custom_command(OUTPUT ${libtcc1_prefix}libtcc1.a
135 COMMAND ${xar} ${libtcc1_prefix}libtcc1.a ${libtcc1_objects}
136 DEPENDS ${xar} ${libtcc1_objects}
138 add_custom_target(${libtcc1_prefix}libtcc1 ALL DEPENDS ${libtcc1_prefix}libtcc1.a)
139 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${libtcc1_prefix}libtcc1.a
140 DESTINATION ${TCC_LIB_PATH}/${prefix} RENAME libtcc1.a)
143 macro(make_tcc native_name cross_name cross_enabled definitions tcc_sources libtcc_ar libtcc_sources libtcc_includes)
144 if (xx${native_name} STREQUAL xx${TCC_NATIVE_TARGET})
145 set(TCC_NATIVE_DEFINITIONS ${definitions})
146 if("${CONFIG_MULTIARCHDIR}" STRGREATER "")
147 set(TCC_NATIVE_DEFINITIONS ${TCC_NATIVE_DEFINITIONS} CONFIG_MULTIARCHDIR="${CONFIG_MULTIARCHDIR}")
149 if("${CONFIG_LDDIR}" STRGREATER "")
150 set(TCC_NATIVE_DEFINITIONS ${TCC_NATIVE_DEFINITIONS} CONFIG_LDDIR="${CONFIG_LDDIR}")
153 set(TCC_NATIVE_FLAGS)
154 foreach(make_tcc_def ${TCC_NATIVE_DEFINITIONS})
155 set(TCC_NATIVE_FLAGS ${TCC_NATIVE_FLAGS} -D${make_tcc_def})
158 if (TCC_BUILD_NATIVE)
171 set_target_properties(libtcc PROPERTIES OUTPUT_NAME tcc PREFIX lib)
173 set_target_properties(libtcc PROPERTIES LINK_FLAGS "-Wl,--output-def,libtcc.def")
175 add_executable(tcc tcc.c)
176 target_link_libraries(tcc libtcc)
178 target_link_libraries(tcc dl)
180 install(TARGETS tcc libtcc RUNTIME DESTINATION ${EXE_PATH} LIBRARY DESTINATION ${NATIVE_LIB_PATH} ARCHIVE DESTINATION ${NATIVE_LIB_PATH})
181 set_target_properties(tcc libtcc PROPERTIES COMPILE_DEFINITIONS "${TCC_NATIVE_DEFINITIONS}")
183 if("${libtcc_sources}" STRGREATER "")
184 make_libtcc1("" tcc "${libtcc_ar}" "${TCC_NATIVE_DEFINITIONS}" "${libtcc_includes}" "${libtcc_sources}")
187 elseif(${cross_enabled})
188 add_executable(${cross_name}-tcc tcc.c)
189 set_target_properties(${cross_name}-tcc PROPERTIES COMPILE_DEFINITIONS "ONE_SOURCE;${definitions}")
190 install(TARGETS ${cross_name}-tcc RUNTIME DESTINATION ${EXE_PATH})
192 if("${libtcc_sources}" STRGREATER "")
193 make_libtcc1(${cross_name} "${cross_name}-tcc" "${libtcc_ar}" "${definitions}" "${libtcc_includes}" "${libtcc_sources}")
198 make_tcc("Win32" i386-win32 TCC_BUILD_WIN32
199 "TCC_TARGET_I386;TCC_TARGET_PE"
200 "${I386_SOURCES};tccpe.c"
201 tiny_libmaker_32 "${LIBTCC1_I386_SOURCES};${LIBTCC1_WIN_SOURCES}" "win32/include;win32/include/winapi"
203 make_tcc("Win64" x86_64-win32 TCC_BUILD_WIN64
204 "TCC_TARGET_X86_64;TCC_TARGET_PE"
205 "${X86_64_SOURCES};tccpe.c"
206 tiny_libmaker_64 "lib/alloca86_64.S;${LIBTCC1_WIN_SOURCES}" "win32/include;win32/include/winapi"
208 make_tcc("WinCE" arm-win32 TCC_BUILD_WINCE
209 "TCC_TARGET_ARM;TCC_ARM_VERSION=${TCC_ARM_VERSION};TCC_TARGET_PE"
210 "${ARM_SOURCES};tccpe.c"
213 make_tcc("i386" i386 TCC_BUILD_I386
216 tiny_libmaker_32 "${LIBTCC1_I386_SOURCES}" ""
218 make_tcc("x86_64" x86_64 TCC_BUILD_X64
221 tiny_libmaker_64 "lib/alloca86_64.S" ""
223 set(ARM_DEFINITIONS TCC_TARGET_ARM TCC_ARM_VERSION=${TCC_ARM_VERSION})
224 make_tcc("ARM" arm TCC_BUILD_ARM
225 "${ARM_DEFINITIONS};WITHOUT_LIBTCC"
229 make_tcc("" arm-eabihf TCC_BUILD_ARM_EABIHF
230 "${ARM_DEFINITIONS};TCC_ARM_EABI;TCC_ARM_HARDFLOAT"
234 make_tcc("" arm-eabi TCC_BUILD_ARM_EABI
235 "${ARM_DEFINITIONS};TCC_ARM_EABI"
239 make_tcc("" arm-fpa TCC_BUILD_ARM_FPA
244 make_tcc("" arm-fpa-ld TCC_BUILD_ARM_FPA_LD
245 "${ARM_DEFINITIONS};LDOUBLE_SIZE=12"
249 make_tcc("" arm-vfp TCC_BUILD_ARM_VFP
250 "${ARM_DEFINITIONS};TCC_ARM_VFP"
254 make_tcc("" c67 TCC_BUILD_C67
256 "c67-gen.c;tcccoff.c"
260 add_subdirectory(tests)
262 find_program(MAKEINFO NAMES makeinfo PATHS C:/MinGW/MSYS/1.0/bin)
264 add_custom_command(OUTPUT tcc-doc.html
265 COMMAND ${MAKEINFO} --no-split --html -o tcc-doc.html ${CMAKE_CURRENT_SOURCE_DIR}/tcc-doc.texi
266 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tcc-doc.texi
268 set(TCC_DOC_FILES tcc-doc.html)
270 add_custom_command(OUTPUT tcc-doc.info
271 COMMAND ${MAKEINFO} -o tcc-doc.info ${CMAKE_CURRENT_SOURCE_DIR}/tcc-doc.texi
272 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tcc-doc.texi
274 set(TCC_DOC_FILES ${TCC_DOC_FILES} tcc-doc.info)
275 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tcc-doc.info DESTINATION share/info)
277 add_custom_target(tcc-doc ALL DEPENDS ${TCC_DOC_FILES})
278 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tcc-doc.html DESTINATION ${DOC_PATH})
282 file(GLOB WIN32_DEFS win32/lib/*.def)
283 install(FILES ${WIN32_DEFS} DESTINATION lib)
284 install(FILES tcclib.h DESTINATION include)
285 install(DIRECTORY include/ DESTINATION include)
286 install(DIRECTORY win32/include/ DESTINATION include)
287 install(DIRECTORY win32/examples/ DESTINATION examples)
288 install(FILES win32/tcc-win32.txt DESTINATION doc)
289 install(FILES ${CMAKE_BINARY_DIR}/libtcc.def DESTINATION libtcc)
290 install(FILES ${CMAKE_BINARY_DIR}/libtcc.dll.a DESTINATION libtcc RENAME libtcc.a)
291 install(FILES libtcc.h DESTINATION libtcc)
293 install(FILES libtcc.h tcclib.h DESTINATION include)
294 install(DIRECTORY include/ DESTINATION lib/tcc/include)
295 install(DIRECTORY win32/include/ DESTINATION lib/tcc/win32/include)
296 install(DIRECTORY include/ DESTINATION lib/tcc/win32/include)