Skip to content

Commit

Permalink
Ditch fips. (#36)
Browse files Browse the repository at this point in the history
* Ditch fips.

* Upgrade Travis to Focal.

* Fix AppVeyor build.

* Fix Travis build.

* Fix Travis CMake.

* More work on Travis CMake.

* Try CMake apt repo.

* Another try at CMake apt repo.

* Go back to earlier CMake attempt.

* Fix Travis build commands.

* Fix LLVM commands.

* Fix a warning.
  • Loading branch information
tmadden committed Sep 3, 2020
1 parent ee20f1e commit a38f2f5
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 157 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.fips-*
.vscode
.venv
www
Expand Down
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
- env: CACHE_NAME=clang-4
install:
- sudo apt-get update -qy
- sudo apt-get install -y --upgrade lcov cmake git curl clang-4.0 llvm-4.0
- sudo apt-get install -y --upgrade lcov git curl clang-4.0 llvm-4.0
- sudo scripts/install-cmake.sh
- scripts/set-up-travis.sh
before_script:
- export CC=`which clang-4.0`
Expand All @@ -22,7 +23,8 @@ jobs:
- env: CACHE_NAME=clang-5
install:
- sudo apt-get update -qy
- sudo apt-get install -y --upgrade lcov cmake git curl clang-5.0 llvm-5.0
- sudo apt-get install -y --upgrade lcov git curl clang-5.0 llvm-5.0
- sudo scripts/install-cmake.sh
- scripts/set-up-travis.sh
before_script:
- export CC=`which clang-5.0`
Expand All @@ -36,7 +38,8 @@ jobs:
- env: CACHE_NAME=gcc-5
install:
- sudo apt-get update -qy
- sudo apt-get install -y --upgrade g++-5 gcc-5 cmake
- sudo apt-get install -y --upgrade g++-5 gcc-5
- sudo scripts/install-cmake.sh
- scripts/set-up-travis.sh
before_script:
- export CC=`which gcc-5`
Expand All @@ -56,8 +59,7 @@ jobs:
# GCC 7 testing job
- env: CACHE_NAME=gcc-7
install:
- sudo apt-get update -qy
- sudo apt-get install -y --upgrade cmake
- sudo scripts/install-cmake.sh
- scripts/set-up-travis.sh
before_script:
- export CC=`which gcc-7`
Expand All @@ -71,7 +73,7 @@ jobs:
- env: CACHE_NAME=emscripten
install:
- sudo add-apt-repository universe
- sudo apt update
- sudo apt-get update -qy
- sudo apt install graphviz
services:
- docker
Expand Down
173 changes: 64 additions & 109 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.14)
project(alia)

enable_testing()
include(FetchContent)

# Set up fips.
get_filename_component(FIPS_ROOT_DIR "../fips" ABSOLUTE)
include("${FIPS_ROOT_DIR}/cmake/fips.cmake")
set(FIPS_EXCEPTIONS ON)
set(FIPS_RTTI ON)
fips_setup()
fips_project(alia)
# Include Catch.
FetchContent_Declare(
catch
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.0
)
FetchContent_MakeAvailable(catch)

# Detect the compiler.
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(IS_CLANG true)
else()
set(IS_CLANG false)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(IS_GCC true)
else()
set(IS_GCC false)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(IS_MSVC true)
else()
set(IS_MSVC false)
endif()

# Decide if we should be using C++14 or C++17.
if(FIPS_GCC)
if(IS_GCC)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
set(CMAKE_CXX_STANDARD 14)
else()
set(CMAKE_CXX_STANDARD 17)
endif()
elseif(FIPS_CLANG)
elseif(IS_CLANG)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
set(CMAKE_CXX_STANDARD 14)
else()
Expand All @@ -28,85 +45,25 @@ else()
set(CMAKE_CXX_STANDARD 14)
endif()

# Run Conan to install external C++ libraries.
# Conan and fips disagree on various build options, so we need to override
# some of Conan's defaults.
set(CONAN_OPTIONS)
if(FIPS_MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CONAN_OPTIONS
-s compiler=Visual\ Studio -s build_type=Debug -s
compiler.runtime=MTd)
else()
set(CONAN_OPTIONS
-s compiler=Visual\ Studio -s build_type=Release -s
compiler.runtime=MT)
endif()
elseif(FIPS_GCC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CONAN_OPTIONS
-s compiler=gcc -s compiler.libcxx=libstdc++11 -s build_type=Debug)
else()
set(CONAN_OPTIONS
-s compiler=gcc -s compiler.libcxx=libstdc++11 -s
build_type=Release)
endif()
elseif(FIPS_CLANG)
string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" CLANG_MAJOR_MINOR_VERSION
${CMAKE_CXX_COMPILER_VERSION})
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CONAN_OPTIONS
-s compiler=clang -s compiler.version=${CLANG_MAJOR_MINOR_VERSION}
-s compiler.libcxx=libstdc++11 -s build_type=Debug)
else()
set(CONAN_OPTIONS
-s compiler=clang -s compiler.version=${CLANG_MAJOR_MINOR_VERSION}
-s compiler.libcxx=libstdc++11 -s build_type=Release)
endif()
endif()
execute_process(
COMMAND conan install ${PROJECT_SOURCE_DIR} ${CONAN_OPTIONS}
-e CONAN_IMPORT_PATH=${FIPS_PROJECT_DEPLOY_DIR} --build missing
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
RESULT_VARIABLE CONAN_RESULT)
if(NOT ${CONAN_RESULT} EQUAL 0)
message(FATAL_ERROR "Conan failed.")
endif()

# And now set up CMake to use those libraries.
# Note that Conan seems to insert flags that don't make sense and cause
# warnings.
set(ORIGINAL_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
include(${PROJECT_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
set(CMAKE_CXX_FLAGS "${ORIGINAL_CXX_FLAGS}")

# Register Conan's include directories with fips.
fips_include_directories(${CONAN_INCLUDE_DIRS}
"$<$<CONFIG:Release>:${CONAN_INCLUDE_DIRS_RELEASE}>"
"$<$<CONFIG:Debug>:${CONAN_INCLUDE_DIRS_DEBUG}>")
# And remember the libs that it wants to link against.
set(EXTERNAL_LIBS ${CONAN_LIBS})

fips_include_directories(${PROJECT_SOURCE_DIR}/src)

# Enable a high level of compiler warnings and treat them as errors.
if(FIPS_GCC)
if(IS_GCC)
add_compile_options(-Wall -Werror)
# Disable warnings that are too strict.
elseif(FIPS_MSVC)
# TODO: Remove these.
add_compile_options(-Wno-deprecated-declarations -Wno-deprecated-copy)
elseif(IS_MSVC)
# First strip out the old warning level.
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
add_compile_options(/W4 /WX)
# Disable "unreferenced local function has been removed".
# (As far as I can tell, this warning seems to be broken.)
add_compile_options(/wd4505)
elseif(FIPS_CLANG)
elseif(IS_CLANG)
add_compile_options(-Wall -Werror)
endif()

# Set build options for instrumenting test coverage.
if(FIPS_CLANG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
enable_testing()
if(IS_CLANG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Enabling gcov support")
add_compile_options(-DLLVM_USE_LINKER=gold -fprofile-instr-generate
-fcoverage-mapping)
Expand All @@ -115,27 +72,26 @@ if(FIPS_CLANG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
endif()

# Add the alia library.
fips_begin_lib(alia)
fips_src(src/alia)
fips_dir(.)
fips_end_lib()
target_link_libraries(alia ${EXTERNAL_LIBS})
include_directories(src)
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS "src/*.cpp")
add_library(alia STATIC ${SRC_FILES})

# Add the unit test runner.
fips_begin_app(unit_test_runner cmdline)
fips_deps(alia)
fips_src(unit_tests)
fips_end_app()
include_directories(src)
file(GLOB_RECURSE UNIT_TEST_FILES CONFIGURE_DEPENDS "unit_tests/*.cpp")
add_executable(unit_test_runner ${UNIT_TEST_FILES})
target_link_libraries(unit_test_runner alia Catch2::Catch2)
target_include_directories(unit_test_runner
PRIVATE ${PROJECT_SOURCE_DIR}/unit_tests)

# Create another version of the unit tests that run against the single-header
# version of the library.
# (Note that this comes as an empty test and requires some external setup to
# run properly. This is normally only done within Travis.)
fips_begin_app(single_header_tester cmdline)
fips_src(single_header_tests)
fips_end_app()
file(GLOB_RECURSE SINGLE_HEADER_TEST_FILES CONFIGURE_DEPENDS
"single_header_tests/*.cpp")
add_executable(single_header_tester ${SINGLE_HEADER_TEST_FILES})
target_link_libraries(single_header_tester alia Catch2::Catch2)
target_include_directories(single_header_tester
PRIVATE ${PROJECT_SOURCE_DIR}/single_header_tests)

Expand All @@ -158,21 +114,19 @@ foreach(TEST_FILE ${COMPILATION_TEST_FILES})
# to build those targets.

# This is the "control" case (which omits the error and should build).
fips_begin_lib(${TEST_NAME}_control)
fips_deps(alia)
fips_files(${TEST_FILE})
fips_end_lib()
set_target_properties(${TEST_NAME}_control PROPERTIES EXCLUDE_FROM_ALL 1
add_library(${TEST_NAME}_control ${TEST_FILE})
target_link_libraries(${TEST_NAME}_control alia)
set_target_properties(${TEST_NAME}_control
PROPERTIES
EXCLUDE_FROM_ALL 1
EXCLUDE_FROM_DEFAULT_BUILD 1)
add_test(NAME ${TEST_NAME}_control
COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME}_control
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})

# This is the actual failure case.
fips_begin_lib(${TEST_NAME})
fips_deps(alia)
fips_files(${TEST_FILE})
fips_end_lib()
add_library(${TEST_NAME} ${TEST_FILE})
target_link_libraries(${TEST_NAME} alia)
target_compile_definitions(
${TEST_NAME} PRIVATE ALIA_TEST_COMPILATION_FAILURE)
set_target_properties(${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL 1
Expand All @@ -191,8 +145,8 @@ add_custom_target(
COMMAND ${CMAKE_COMMAND} -E remove_directory unit-testing
COMMAND ${CMAKE_COMMAND} -E make_directory unit-testing
COMMAND ${CMAKE_COMMAND} -E chdir unit-testing ${CMAKE_COMMAND}
-E env ALIA_DEPLOY_DIR=${FIPS_PROJECT_DEPLOY_DIR}
${FIPS_PROJECT_DEPLOY_DIR}/unit_test_runner
-E env ALIA_DEPLOY_DIR=${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/unit_test_runner
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
DEPENDS unit_test_runner)

Expand All @@ -205,22 +159,23 @@ add_custom_target(
COMMAND ${CMAKE_COMMAND} -E remove_directory single-header-testing
COMMAND ${CMAKE_COMMAND} -E make_directory single-header-testing
COMMAND ${CMAKE_COMMAND} -E chdir single-header-testing ${CMAKE_COMMAND}
-E env ALIA_DEPLOY_DIR=${FIPS_PROJECT_DEPLOY_DIR}
${FIPS_PROJECT_DEPLOY_DIR}/single_header_tester
-E env ALIA_DEPLOY_DIR=${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/single_header_tester
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
DEPENDS single_header_tester)

# On Linux debug builds, the proper CMake test associated with the unit tests
# includes test coverage reporting.
if(FIPS_CLANG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
if(IS_CLANG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
string(REPLACE clang llvm-profdata LLVM_PROFDATA $ENV{CC})
string(REPLACE clang llvm-cov LLVM_COV $ENV{CC})
add_custom_target(
unit_test_coverage
COMMAND ${CMAKE_COMMAND} --build . --target unit_tests
COMMAND llvm-profdata-${CLANG_MAJOR_MINOR_VERSION} merge -sparse
unit-testing/default.profraw -o default.profdata
COMMAND llvm-cov-${CLANG_MAJOR_MINOR_VERSION} show
-instr-profile=default.profdata
${FIPS_PROJECT_DEPLOY_DIR}/unit_test_runner
COMMAND ${LLVM_PROFDATA} merge -sparse unit-testing/default.profraw
-o default.profdata
COMMAND ${LLVM_COV} show -instr-profile=default.profdata
${PROJECT_BINARY_DIR}/unit_test_runner
>${PROJECT_SOURCE_DIR}/coverage.txt
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
add_test(
Expand Down
15 changes: 7 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ for:
- platform: x64
configuration: Release
before_build:
- fips set config win64-vstudio-release
- call %VCVARSALL% x64
- set Qt5_DIR=%QT_ROOT_DIR%\%MSVCID%_64\lib\cmake\Qt5
environment:
Expand All @@ -59,7 +58,6 @@ for:
- platform: x64
configuration: Debug
before_build:
- fips set config win64-vstudio-debug
- call %VCVARSALL% x64
- set Qt5_DIR=%QT_ROOT_DIR%\%MSVCID%_64\lib\cmake\Qt5
environment:
Expand All @@ -69,7 +67,6 @@ for:
- platform: x86
configuration: Release
before_build:
- fips set config win32-vstudio-release
- call %VCVARSALL% x86
- set Qt5_DIR=%QT_ROOT_DIR%\%MSVCID%\lib\cmake\Qt5
environment:
Expand All @@ -79,21 +76,23 @@ for:
- platform: x86
configuration: Debug
before_build:
- fips set config win32-vstudio-debug
- call %VCVARSALL% x86
- set Qt5_DIR=%QT_ROOT_DIR%\%MSVCID%\lib\cmake\Qt5
environment:
LIBRARY_ARCHITECTURE: lib32

build_script:
- set CTEST_OUTPUT_ON_FAILURE=1
- fips gen
- fips make ctest
# Test the Qt sandbox.
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% -G"NMake Makefiles" ..
- cmake --build . --target ctest
- cd ..
# Also test the Qt sandbox.
- C:\Python36\python scripts\generate-distributables.py
- move alia.hpp examples\qt
- cd examples\qt
- mkdir build
- cd build
- cmake -G"NMake Makefiles" ..
- cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% -G"NMake Makefiles" ..
- cmake --build .
2 changes: 1 addition & 1 deletion examples/asm-dom/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.11)
cmake_minimum_required (VERSION 3.14)
project(asm-dom-demos)

# Apply some emscripten optimizations flags if we're in release mode.
Expand Down
17 changes: 0 additions & 17 deletions fips

This file was deleted.

2 changes: 0 additions & 2 deletions fips.cmd

This file was deleted.

2 changes: 0 additions & 2 deletions fips.yml

This file was deleted.

0 comments on commit a38f2f5

Please sign in to comment.