tinycc/CMakeLists.txt
James Lyon 8a81f9e103 Added CMake build system (to facilitate Win64 builds)
Win32 build and tests work under CMake, however I haven't added
install code yet. Win64 build fails due to chkstk.S failing to
assemble.
2013-04-21 11:20:20 +01:00

130 lines
4.4 KiB
CMake

project(tcc C)
cmake_minimum_required(VERSION 2.6)
enable_testing()
set(CMAKE_USE_RELATIVE_PATHS ON)
if(WIN32)
set(BUILD_SHARED_LIBS ON)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM")
set(TCC_TARGET_DEFAULT "WinCE")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TCC_TARGET_DEFAULT "Win64")
else()
set(TCC_TARGET_DEFAULT "Win32")
endif()
else()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
set(TCC_TARGET_DEFAULT "ARM")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv5")
set(TCC_ARM_VERSION_DEFAULT 5)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv6")
set(TCC_ARM_VERSION_DEFAULT 6)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv7")
set(TCC_ARM_VERSION_DEFAULT 7)
else()
set(TCC_ARM_VERSION_DEFAULT 4)
endif()
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TCC_TARGET_DEFAULT "x86_64")
else()
set(TCC_TARGET_DEFAULT "i386")
endif()
endif()
set(TCC_TARGET_LIST "Win32" "Win64" "WinCE" "i386" "x86_64" "ARM" "C67")
set(TCC_TARGET ${TCC_TARGET_DEFAULT} CACHE STRING "Target OS")
set_property(CACHE TCC_TARGET PROPERTY STRINGS ${TCC_TARGET_LIST})
set(TCC_ARM_VERSION ${TCC_ARM_VERSION_DEFAULT} CACHE STRING "ARM target CPU version")
set_property(CACHE TCC_ARM_VERSION PROPERTY STRINGS 4 5 6 7)
set(TCC_ARM_EABI OFF CACHE BOOL "Enable EABI on ARM")
set(TCC_ARM_VFP OFF CACHE BOOL "Enable VFP on ARM")
set(TCC_ARM_HARDFLOAT OFF CACHE BOOL "Enable hardware floating point on ARM")
set(I386_SOURCES i386-gen.c i386-asm.c i386-asm.h i386-tok.h)
set(X86_64_SOURCES x86_64-gen.c i386-asm.c x86_64-asm.h)
if(TCC_TARGET STREQUAL "Win32")
set(TCC_TARGET_I386 ON)
set(TCC_TARGET_PE ON)
set(LIBTCC_TARGET_SOURCES ${I386_SOURCES} tccpe.c)
elseif(TCC_TARGET STREQUAL "Win64")
set(TCC_TARGET_PE ON)
set(TCC_TARGET_X86_64 ON)
set(LIBTCC_TARGET_SOURCES ${X86_64_SOURCES} tccpe.c)
elseif(TCC_TARGET STREQUAL "WinCE")
set(TCC_TARGET_ARM ON)
set(LIBTCC_TARGET_SOURCES arm-gen.c tccpe.c)
elseif(TCC_TARGET STREQUAL "i386")
set(TCC_TARGET_I386 ON)
set(LIBTCC_TARGET_SOURCES ${I386_SOURCES})
elseif(TCC_TARGET STREQUAL "x86-64")
set(TCC_TARGET_X86_64 ON)
set(LIBTCC_TARGET_SOURCES ${X86_64_SOURCES})
elseif(TCC_TARGET STREQUAL "ARM")
set(TCC_TARGET_ARM ON)
set(LIBTCC_TARGET_SOURCES arm-gen.c)
elseif(TCC_TARGET STREQUAL "C67")
set(TCC_TARGET_C67 ON)
set(LIBTCC_TARGET_SOURCES c67-gen.c tcccoff.c)
else()
message(FATAL_ERROR "Unrecognised target in TCC_TARGET, must be one of ${TCC_TARGET_LIST}")
endif()
file(STRINGS "VERSION" TCC_VERSION)
list(GET TCC_VERSION 0 TCC_VERSION)
include_directories(${CMAKE_BINARY_DIR})
configure_file(config.h.in config.h)
add_library(libtcc
libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
tcc.h config.h libtcc.h tcctok.h
${LIBTCC_TARGET_SOURCES}
)
set_target_properties(libtcc PROPERTIES PREFIX "")
add_executable(tcc tcc.c)
target_link_libraries(tcc libtcc)
set(TCC_CFLAGS -I${CMAKE_SOURCE_DIR}/include)
if(TCC_TARGET MATCHES "^Win")
set(TCC_CFLAGS ${TCC_CFLAGS} -I${CMAKE_SOURCE_DIR}/win32/include)
endif()
add_executable(tiny_impdef win32/tools/tiny_impdef.c)
add_executable(tiny_libmaker win32/tools/tiny_libmaker.c)
set(LIBTCC1_I386_SOURCES lib/alloca86.S lib/alloca86-bt.S lib/bcheck.c)
set(LIBTCC1_WIN_SOURCES win32/lib/crt1.c win32/lib/wincrt1.c win32/lib/dllcrt1.c win32/lib/dllmain.c win32/lib/chkstk.S)
if(TCC_TARGET STREQUAL "Win32")
set(LIBTCC1_SOURCES ${LIBTCC1_I386_SOURCES} ${LIBTCC1_WIN_SOURCES})
elseif(TCC_TARGET STREQUAL "Win64")
set(LIBTCC1_SOURCES lib/alloca86_64.S ${LIBTCC1_WIN_SOURCES})
elseif(TCC_TARGET STREQUAL "i386")
set(LIBTCC1_SOURCES ${LIBTCC1_I386_SOURCES})
elseif(TCC_TARGET STREQUAL "x86-64")
set(LIBTCC1_SOURCES lib/alloca86_64.S)
endif()
if (TCC_TARGET MATCHES "^Win")
set(XCC tcc ${TCC_CFLAGS} -B${CMAKE_SOURCE_DIR}/win32)
set(XAR tiny_libmaker${CMAKE_EXECUTABLE_SUFFIX})
set(XDEPENDS tiny_libmaker)
endif()
if(LIBTCC1_SOURCES)
list(APPEND LIBTCC1_SOURCES lib/libtcc1.c)
foreach(LIBTCC1_C ${LIBTCC1_SOURCES})
string(REGEX MATCH "[^/]+$" LIBTCC1_O ${LIBTCC1_C})
string(REGEX MATCH "^[^.]+" LIBTCC1_O ${LIBTCC1_O})
set(LIBTCC1_O ${LIBTCC1_O}.o)
add_custom_command(OUTPUT ${LIBTCC1_O} COMMAND ${XCC} -c ${CMAKE_SOURCE_DIR}/${LIBTCC1_C} -o ${LIBTCC1_O})
list(APPEND LIBTCC1_OBJECTS ${LIBTCC1_O})
endforeach()
add_custom_command(OUTPUT libtcc1.a COMMAND ${XAR} libtcc1.a ${LIBTCC1_OBJECTS} DEPENDS ${LIBTCC1_OBJECTS} ${XDEPENDS})
add_custom_target(libtcc1 ALL DEPENDS libtcc1.a)
endif()
add_subdirectory(tests)