lccrt/CMakeLists.txt

109 lines
3.1 KiB
CMake

cmake_minimum_required( VERSION 3.16)
project( lccrt)
# Function cat for concatenation files.
function(cat IN_VALUE OUT_FILE)
file(APPEND ${OUT_FILE} "${IN_VALUE}\n")
endfunction()
# Define main library source files.
set( lccrt_SOURCE
lib/common/lccrt_ctx.c
lib/common/lccrt_fs.c
lib/common/lccrt_hash.c
lib/irv/lccrt_asmout.c
lib/irv/lccrt_func.c
lib/irv/lccrt_irreader.c
lib/irv/lccrt_irwriter.c
lib/irv/lccrt_link.c
lib/irv/lccrt_metadata.c
lib/irv/lccrt_module.c
lib/irv/lccrt_oper.c
lib/irv/lccrt_type.c
lib/irv/lccrt_var.c
)
# Define main library include directories.
set( lccrt_INCLUDE include include/internal)
# Define main target.
add_library( lccrt SHARED ${lccrt_SOURCE})
target_include_directories( lccrt PRIVATE ${lccrt_INCLUDE})
set_target_properties( lccrt PROPERTIES PUBLIC_HEADER "include/lccrt.h")
# Define main library install directories.
install( TARGETS lccrt
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include
RUNTIME DESTINATION bin
)
# Define runtime-support library source files.
set( lccrt_s_SOURCE
${CMAKE_SOURCE_DIR}/tools/lccrt_s/src/lccrt.c
${CMAKE_SOURCE_DIR}/tools/lccrt_s/src/lccrt_n.c
${CMAKE_SOURCE_DIR}/tools/lccrt_s/src/lccrt_overflow.c
${CMAKE_SOURCE_DIR}/tools/lccrt_s/src/lccrt_vec.c
)
# Define runtime-support library include directories.
set( lccrt_s_INCLUDE ${CMAKE_SOURCE_DIR}/tools/lccrt_s/include)
# Define C-backend library source files.
set( lcbe_SOURCE
${CMAKE_SOURCE_DIR}/tools/lcbe/src/lcbe_driver.cpp
${CMAKE_SOURCE_DIR}/tools/lcbe/src/lcbe_emit.cpp
)
# Define C-backend library include directories.
set( lcbe_INCLUDE ${CMAKE_SOURCE_DIR}/tools/lcbe/include/internal)
# Prepare a temporary file to "cat" backend-plugins.
set( ASM_PLUGIN_CONF ${CMAKE_BINARY_DIR}/asm.plugin.conf)
file( WRITE ${ASM_PLUGIN_CONF} "")
if( NOT DEFINED LCCRT_ARCHS )
set( LCCRT_ARCHS "${CMAKE_SYSTEM_PROCESSOR}")
endif()
# Define targets for every architecture from build-set.
foreach ( X_ARCH IN LISTS LCCRT_ARCHS)
set(X_SUFF "-${X_ARCH}")
set(X_CC_VAR "CC_${X_ARCH}")
if(NOT DEFINED "${X_CC_VAR}")
if("${X_ARCH}" STREQUAL "${CMAKE_SYSTEM_PROCESSOR}")
set( X_CC_ARCH ${CMAKE_C_COMPILER})
else()
message(FATAL_ERROR "compiler for arch '${X_ARCH}' must be specified as '-D${CC_VAR}=...'")
endif()
else()
set(X_CC_ARCH "${${X_CC_VAR}}")
endif()
message("lccrt_s target:${X_ARCH} compiler:${X_CC_ARCH}")
# Define target for runtime-support library under current architecture.
add_subdirectory(cmake/targets/${X_ARCH})
# Define target for C-backend library under current architecture.
add_library( lcbe${X_SUFF} SHARED ${lcbe_SOURCE})
target_include_directories( lcbe${X_SUFF} PRIVATE include tools/lcbe/include/internal)
install( TARGETS lcbe${X_SUFF}
DESTINATION lib/lccrt/plugin/asm
)
# Update plugin.conf for asm backend plugins.
cat( "liblcbe${X_SUFF}.so" ${ASM_PLUGIN_CONF})
endforeach()
# Install plugin.conf for asm backend plugins.
install( FILES ${ASM_PLUGIN_CONF} DESTINATION lib/lccrt/plugin/asm/ RENAME plugin.conf)