[F] Simplified build

This commit is contained in:
seleznevae 2018-03-18 19:02:53 +03:00
parent a864b6ab55
commit 5821ae7c39
3 changed files with 48 additions and 30 deletions

View File

@ -25,25 +25,37 @@ script:
- cmake --version - cmake --version
# Perform out-of-source build(CMake backend generation, build, and test) # Perform out-of-source build(CMake backend generation, build, and test)
# Test build without optimizations # Test build without optimizations and with asan
- mkdir -p build - mkdir -p build
- cd build - cd build
- cmake .. -DFORT_BUILD_TYPE=asan -DFORT_COMPILER=${FORT_COMPILER} - cmake .. -DFORT_BUILD_TYPE=asan
- cmake --build . --target all - cmake --build . --target all
- ls - ls
- ./libfort_example - ./libfort_example
- ./libfort_test - ./libfort_test
# Build for coveralls # Test build without optimizations and with ubsan
- if [ ${GCC_BUILD} == 'ON' ]; - cd ..
- rm -r build/*
- cd build
- cmake .. -DFORT_BUILD_TYPE=ubsan
- cmake --build . --target all
- ls
- ./libfort_example
- ./libfort_test
# Build for coveralls
- if [ ${FORT_COMPILER} == 'gcc' ];
then then
cd .. ; cd .. ;
rm -r build/* ; rm -r build/* ;
cd build ; cd build ;
cmake .. -DFORT_COVERALLS_BUILD=ON -DFORT_BUILD_TYPE=asan -DFORT_COMPILER=${FORT_COMPILER} ; cmake .. -DFORT_BUILD_TYPE=coveralls ;
cmake --build . --target all ; cmake --build . --target all ;
ls ; ls ;
./libfort_test ; ./libfort_test ;
fi fi
- cd .. - cd ..

View File

@ -4,14 +4,19 @@ project(libfort)
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
# Built options # Built options
#option(FORT_GCC_BUILD "Build with gcc" ON)
#option(FORT_MSVC_BUILD "Build with msvc" OFF)
option(FORT_CXX_BUILD "Compile with c++ compiler instead of c" OFF) option(FORT_CXX_BUILD "Compile with c++ compiler instead of c" OFF)
option(FORT_COVERALLS_BUILD "Build for coveralls" OFF) #option(FORT_COVERALLS_BUILD "Build for coveralls" OFF)
set(FORT_BUILD_TYPE "common" CACHE STRING "Built types (possible values: common, asan, ubsan, msan)") set(FORT_BUILD_TYPE "common" CACHE STRING "Built types (possible values: common, asan, ubsan, coveralls)")
set(FORT_COMPILER "gcc" CACHE STRING "Compiler (possible values: gcc, clang, msvc)") #set(FORT_COMPILER "gcc" CACHE STRING "Compiler (possible values: gcc, clang, msvc)")
# Determine compiler (pos. values Clang, GNU, Intel, MSVC, AppleClang... (https://cmake.org/cmake/help/v3.0/variable/CMAKE_LANG_COMPILER_ID.html)
if(FORT_CXX_BUILD)
set(FORT_COMPILER ${CMAKE_CXX_COMPILER_ID})
else(FORT_CXX_BUILD)
set(FORT_COMPILER ${CMAKE_C_COMPILER_ID})
endif(FORT_CXX_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_VERBOSE_MAKEFILE ON)
@ -21,18 +26,11 @@ include_directories(src)
# Turn on warnings # Turn on warnings
#if(FORT_MSVC_BUILD) if(FORT_COMPILER STREQUAL "MSVC")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4")
#else(FORT_MSVC_BUILD)
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
#endif(FORT_MSVC_BUILD)
if(FORT_COMPILER STREQUAL "msvc")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4")
else(FORT_COMPILER STREQUAL "msvc") else(FORT_COMPILER STREQUAL "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
endif(FORT_COMPILER STREQUAL "msvc") endif(FORT_COMPILER STREQUAL "MSVC")
@ -82,27 +80,35 @@ endif(FORT_CXX_BUILD)
# Adding sanitizers # Adding sanitizers
if(FORT_COMPILER STREQUAL "gcc" OR FORT_COMPILER STREQUAL "clang") if(FORT_COMPILER STREQUAL "GNU" OR FORT_COMPILER STREQUAL "Clang")
# asan case
if(FORT_BUILD_TYPE STREQUAL "asan") if(FORT_BUILD_TYPE STREQUAL "asan")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
if(FORT_COMPILER STREQUAL "gcc") if(FORT_COMPILER STREQUAL "GNU")
target_link_libraries(${PROJECT_NAME}_example asan) target_link_libraries(${PROJECT_NAME}_example asan)
target_link_libraries(${PROJECT_NAME}_test asan) target_link_libraries(${PROJECT_NAME}_test asan)
endif(FORT_COMPILER STREQUAL "gcc") endif(FORT_COMPILER STREQUAL "GNU")
endif(FORT_BUILD_TYPE STREQUAL "asan") endif(FORT_BUILD_TYPE STREQUAL "asan")
#ubsan case
if(FORT_BUILD_TYPE STREQUAL "ubsan") if(FORT_BUILD_TYPE STREQUAL "ubsan")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover") #to force fail set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover") #to force fail
if(FORT_COMPILER STREQUAL "gcc") if(FORT_COMPILER STREQUAL "GNU")
target_link_libraries(${PROJECT_NAME}_example ubsan) target_link_libraries(${PROJECT_NAME}_example ubsan)
target_link_libraries(${PROJECT_NAME}_test ubsan) target_link_libraries(${PROJECT_NAME}_test ubsan)
endif(FORT_COMPILER STREQUAL "gcc") endif(FORT_COMPILER STREQUAL "GNU")
endif(FORT_BUILD_TYPE STREQUAL "ubsan") endif(FORT_BUILD_TYPE STREQUAL "ubsan")
endif(FORT_COMPILER STREQUAL "gcc" OR FORT_COMPILER STREQUAL "clang") #coveralls case
if(FORT_BUILD_TYPE STREQUAL "coveralls")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage")
endif(FORT_BUILD_TYPE STREQUAL "coveralls")
endif(FORT_COMPILER STREQUAL "GNU" OR FORT_COMPILER STREQUAL "Clang")
# Coveralls support # Coveralls support
if(FORT_COVERALLS_BUILD) #if(FORT_COVERALLS_BUILD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage") # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage")
endif(FORT_COVERALLS_BUILD) #endif(FORT_COVERALLS_BUILD)

View File

@ -14,7 +14,7 @@ install:
before_build: before_build:
- mkdir build - mkdir build
- cd build - cd build
- cmake -G "Visual Studio 15 2017 Win64" .. -DFORT_COMPILER=msvc - cmake -G "Visual Studio 15 2017 Win64" ..
- dir - dir
build: build: