acc is now built with cmake instead of the old build script. This was mainly done to fix compilation on Puhti where I had problems linking flex even though it is available. As an added bonus the code is now safer to build since all dependencies are now rigorously tracked by cmake and make, and f.ex. change in the compiler now forces also the whole library to be rebuilt (which is the behaviour we want)

This commit is contained in:
jpekkila
2019-09-24 16:57:19 +03:00
parent a91da8388c
commit 72af2cf31d
5 changed files with 38 additions and 16 deletions

View File

@@ -28,13 +28,9 @@ option(BUILD_MPI_TEST "Builds a C program to test whether MPI works"
option(DOUBLE_PRECISION "Generates double precision code" OFF) option(DOUBLE_PRECISION "Generates double precision code" OFF)
option(MULTIGPU_ENABLED "If enabled, uses all the available GPUs" ON) option(MULTIGPU_ENABLED "If enabled, uses all the available GPUs" ON)
## Compile the Astaroth Code compiler ## Compile the Astaroth Code Compiler
find_package(FLEX) add_subdirectory(acc)
find_package(BISON)
execute_process (
COMMAND ./build_acc.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/acc
)
# NOTE: Manually defined DSL_MODULE_DIR must be set relative to the project root, not the actual # NOTE: Manually defined DSL_MODULE_DIR must be set relative to the project root, not the actual
# build directory! # build directory!
# NO! ../acc/mhd_solver # NO! ../acc/mhd_solver
@@ -50,12 +46,13 @@ set(DSL_HEADERS "${PROJECT_BINARY_DIR}/stencil_assembly.cuh"
"${PROJECT_BINARY_DIR}/stencil_process.cuh" "${PROJECT_BINARY_DIR}/stencil_process.cuh"
"${PROJECT_BINARY_DIR}/stencil_defines.h") "${PROJECT_BINARY_DIR}/stencil_defines.h")
add_custom_command ( add_custom_command (
COMMENT "Building AC objects ${DSL_MODULE_DIR}" COMMENT "Building ACC objects ${DSL_MODULE_DIR}"
COMMAND ${CMAKE_SOURCE_DIR}/scripts/compile_acc_module.sh ${DSL_MODULE_DIR} COMMAND ${CMAKE_SOURCE_DIR}/scripts/compile_acc_module.sh ${DSL_MODULE_DIR}
DEPENDS ${DSL_SOURCES} DEPENDS ${DSL_SOURCES}
OUTPUT ${DSL_HEADERS} OUTPUT ${DSL_HEADERS}
) )
add_custom_target(dsl_headers ALL DEPENDS ${DSL_HEADERS}) add_custom_target(dsl_headers ALL DEPENDS ${DSL_HEADERS})
add_dependencies(dsl_headers acc)
## Build types ## Build types
# Available types (case-sensitive): # Available types (case-sensitive):

12
acc/CMakeLists.txt Normal file
View File

@@ -0,0 +1,12 @@
## CMake settings
cmake_minimum_required (VERSION 3.5.1)
find_program(CMAKE_C_COMPILER NAMES $ENV{CC} gcc PATHS ENV PATH NO_DEFAULT_PATH)
## Project settings
project(acc C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
include_directories(src)
add_subdirectory(src)

View File

@@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
# Usage ./compile <source file> <gcc preprocessor flags, f.ex. -I some/path> # Usage ./compile <acc binary> <source file> <gcc preprocessor flags, f.ex. -I some/path>
ACC_DIR=`dirname $0` ACC_DIR=`dirname $0`
ACC_BINARY=$1
FULL_NAME=$(basename -- $1) FULL_NAME=$(basename -- $2)
FILENAME="${FULL_NAME%.*}" FILENAME="${FULL_NAME%.*}"
EXTENSION="${FULL_NAME##*.}" EXTENSION="${FULL_NAME##*.}"
@@ -25,4 +25,4 @@ else
exit exit
fi fi
${ACC_DIR}/preprocess.sh $@ | ${ACC_DIR}/build/acc ${COMPILE_FLAGS} > ${CUH_FILENAME} ${ACC_DIR}/preprocess.sh ${@:2} | ${ACC_BINARY} ${COMPILE_FLAGS} > ${CUH_FILENAME}

11
acc/src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,11 @@
## Compile the Astaroth Code compiler
find_package(BISON)
find_package(FLEX 2.5.5 REQUIRED)
bison_target(acc_parser acc.y ${CMAKE_CURRENT_BINARY_DIR}/acc.tab.c)
flex_target(acc_lexer acc.l ${CMAKE_CURRENT_BINARY_DIR}/acc.yy.c)
add_flex_bison_dependency(acc_lexer acc_parser)
add_executable(acc code_generator.c ${BISON_acc_parser_OUTPUTS} ${FLEX_acc_lexer_OUTPUTS})
target_include_directories(acc PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(acc ${FLEX_LIBRARIES})

View File

@@ -1,9 +1,11 @@
#!/bin/bash #!/bin/bash
ACC_DIR=$(readlink -f $(dirname $0)/../acc) ACC_DIR=$(readlink -f $(dirname $0)/../acc)
ACC_BINARY_DIR=$(pwd)/acc
MODULE_DIR=$(readlink -f $1) MODULE_DIR=$(readlink -f $1)
echo "-- Compiling project in "${MODULE_DIR} echo "-- ACC binary dir: ${ACC_BINARY_DIR}"
echo "-- ACC project dir: ${MODULE_DIR}"
for source in ${MODULE_DIR}/*.sas ${MODULE_DIR}/*.sps ${MODULE_DIR}/*.sdh for source in ${MODULE_DIR}/*.sas ${MODULE_DIR}/*.sps ${MODULE_DIR}/*.sdh
do do
${ACC_DIR}/compile.sh $source -I ${MODULE_DIR} ${ACC_DIR}/compile.sh ${ACC_BINARY_DIR}/acc $source -I ${MODULE_DIR}
done done