-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bf0d80
commit 506a8f7
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Copyright 2021-2021 by Martin Moene | ||
# | ||
# https://github.com/martinmoene/XXX-lite | ||
# | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
if( NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION ) | ||
cmake_minimum_required( VERSION 3.8 FATAL_ERROR ) | ||
endif() | ||
|
||
project( example LANGUAGES CXX ) | ||
|
||
set( unit_name "byte" ) | ||
set( PACKAGE ${unit_name}-lite ) | ||
set( PROGRAM ${unit_name}-lite ) | ||
|
||
message( STATUS "Subproject '${PROJECT_NAME}', examples '${PROGRAM}-*'") | ||
|
||
set( OPTIONS "" ) | ||
|
||
# Sources (.cpp), normal and no-exception, and their base names: | ||
|
||
set( SOURCES | ||
01-basic.cpp | ||
) | ||
|
||
set( SOURCES_NE | ||
) | ||
|
||
string( REPLACE ".cpp" "" BASENAMES "${SOURCES}" ) | ||
string( REPLACE ".cpp" "" BASENAMES_NE "${SOURCES_NE}" ) | ||
|
||
macro( ternary var boolean value1 value2 ) | ||
if( ${boolean} ) | ||
set( ${var} ${value1} ) | ||
else() | ||
set( ${var} ${value2} ) | ||
endif() | ||
endmacro() | ||
|
||
# Determine options: | ||
|
||
if( MSVC ) | ||
message( STATUS "Matched: MSVC") | ||
|
||
set( BASE_OPTIONS -W3 ) | ||
set( EXCEPTIONS_OPTIONS ${BASE_OPTIONS} -EHsc ) | ||
set( NO_EXCEPTIONS_OPTIONS ${BASE_OPTIONS} ) | ||
|
||
elseif( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang" ) | ||
message( STATUS "CompilerId: '${CMAKE_CXX_COMPILER_ID}'") | ||
|
||
set( BASE_OPTIONS -Wall -Wextra -Wconversion -Wsign-conversion -Wno-missing-braces -fno-elide-constructors ) | ||
set( EXCEPTIONS_OPTIONS ${BASE_OPTIONS} ) | ||
set( NO_EXCEPTIONS_OPTIONS -fno-exceptions ) | ||
|
||
elseif( CMAKE_CXX_COMPILER_ID MATCHES "Intel" ) | ||
# as is | ||
message( STATUS "Matched: Intel") | ||
else() | ||
# as is | ||
message( STATUS "Matched: nothing") | ||
endif() | ||
|
||
# Function to create a target: | ||
|
||
function( make_target name no_exceptions ) | ||
ternary( ne no_exceptions "-ne" "" ) | ||
|
||
add_executable ( ${PROGRAM}-${name}${ne} ${name}.cpp ) | ||
target_include_directories ( ${PROGRAM}-${name}${ne} PRIVATE ../../variant-lite/include ) | ||
target_link_libraries ( ${PROGRAM}-${name}${ne} PRIVATE ${PACKAGE} ) | ||
if ( no_exceptions ) | ||
target_compile_options ( ${PROGRAM}-${name}${ne} PRIVATE ${NO_EXCEPTIONS_OPTIONS} ) | ||
else() | ||
target_compile_options ( ${PROGRAM}-${name}${ne} PRIVATE ${EXCEPTIONS_OPTIONS} ) | ||
endif() | ||
|
||
endfunction() | ||
|
||
# Targets: | ||
|
||
foreach( target ${BASENAMES} ) | ||
make_target( ${target} FALSE ) | ||
endforeach() | ||
|
||
foreach( target ${BASENAMES_NE} ) | ||
make_target( ${target} TRUE ) | ||
endforeach() | ||
|
||
# end of file |