Skip to content

Instantly share code, notes, and snippets.

@Raymo111
Created March 29, 2022 23:00
Show Gist options
  • Save Raymo111/dc7d61dc1226e1cb4a621a7d269e2480 to your computer and use it in GitHub Desktop.
Save Raymo111/dc7d61dc1226e1cb4a621a7d269e2480 to your computer and use it in GitHub Desktop.
CS 136 CMakeLists
cmake_minimum_required(VERSION 3.16)
project(CS_136 C)
##################################################
set(ASSIGNMENT Final)
##################################################
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
MACRO(QNLIST res assign)
FILE(GLOB qns CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/${assign}/q*)
SET(qnlst)
FOREACH(qn ${qns})
IF(IS_DIRECTORY ${qn})
get_filename_component(qnname ${qn} NAME)
LIST(APPEND qnlst ${qnname})
ENDIF()
ENDFOREACH()
SET(${res} ${qnlst})
ENDMACRO()
QNLIST(QUESTIONS ${ASSIGNMENT})
message(STATUS "Assignment folder: ${ASSIGNMENT}")
message(STATUS "Questions: ${QUESTIONS}")
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_FLAGS "-std=c99 -fno-omit-frame-pointer -fno-common -O0 -lm -Wno-override-module -Wno-unused-command-line-argument -Werror=incompatible-pointer-types -Werror=import-preprocessor-directive-pedantic -Werror=return-type -Werror=int-to-pointer-cast -Werror=int-conversion -Wall")# -fsanitize=address")
set(COMMON_LOC ${ASSIGNMENT}/common)
include_directories(${COMMON_LOC})
file(GLOB ASSIGN_LLVM_IR LIST_DIRECTORIES false CONFIGURE_DEPENDS ${COMMON_LOC}/*.ll)
foreach(question ${QUESTIONS})
set(QNDIR ${ASSIGNMENT}/${question})
include_directories(${QNDIR})
file(GLOB files LIST_DIRECTORIES false CONFIGURE_DEPENDS ${QNDIR}/*.h ${QNDIR}/*.c)
add_executable(${question} ${files})
file(GLOB QN_LLVM_IR LIST_DIRECTORIES false CONFIGURE_DEPENDS ${QNDIR}/*.ll)
target_link_libraries(${question} ${ASSIGN_LLVM_IR} ${QN_LLVM_IR})
endforeach(question)
set(rand rand)
set(COMMON_LOC Random/common)
include_directories(${COMMON_LOC})
file(GLOB files CONFIGURE_DEPENDS Random/*.h Random/*.c)
add_executable(${rand} Random/main.c Random/bst.c Random/bst.h)
file(GLOB QN_LLVM_IR LIST_DIRECTORIES false ${CMAKE_SOURCE_DIR}/${COMMON_LOC}/*.ll)
target_link_libraries(${rand} ${QN_LLVM_IR})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment