Skip to content

Commit 088a63b

Browse files
committed
build(cmake)
1 parent ed8e8a3 commit 088a63b

File tree

3 files changed

+47
-38
lines changed

3 files changed

+47
-38
lines changed

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ project("stdsharp" VERSION 0.1.0 LANGUAGES CXX)
1212

1313
init_proj()
1414

15-
config_interface_lib(${PROJECT_NAME})
15+
config_interface_lib(${PROJECT_NAME} SYSTEM_INCLUDED ON)
1616

1717
#
1818
# Model project dependencies
@@ -22,8 +22,8 @@ find_package(range-v3 CONFIG REQUIRED)
2222

2323
target_compile_options(
2424
${PROJECT_NAME}
25-
INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:-Wno-logical-op-parentheses -Wno-dangling-else -Werror>
26-
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
25+
INTERFACE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:-Wno-logical-op-parentheses -Wno-dangling-else>
26+
$<$<CXX_COMPILER_ID:MSVC>:/wd4127>
2727
)
2828

2929
target_link_libraries(
@@ -55,6 +55,8 @@ install(
5555

5656
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
5757
set(STDSHARP_BUILD_TEST ON)
58+
else()
59+
target_include_as_system(${PROJECT_NAME} INTERFACE)
5860
endif()
5961
option(STDSHARP_BUILD_TEST "Whether to build test")
6062

cmake/Utils.cmake

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ include(cmake/Conan.cmake)
2424
conan()
2525

2626
function(init_proj)
27-
cmake_parse_arguments(${CMAKE_CURRENT_FUNCTION} "USE_ALT_NAMES" "" "" ${ARGN})
27+
cmake_parse_arguments(ARG "USE_ALT_NAMES" "" "" ${ARGN})
2828
message(STATUS "Started CMake for ${PROJECT_NAME} v${PROJECT_VERSION}...\n")
2929

3030
#
3131
# Setup alternative names
3232
#
33-
if (${${CMAKE_CURRENT_FUNCTION}_USE_ALT_NAMES})
33+
if (${ARG_USE_ALT_NAMES})
3434
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWERCASE)
3535
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPERCASE)
3636
endif ()
@@ -43,11 +43,18 @@ function(init_proj)
4343
endif ()
4444
endfunction()
4545

46+
function(target_include_as_system target_name lib_type)
47+
target_include_directories(
48+
${target_name}
49+
SYSTEM BEFORE ${lib_type} $<TARGET_PROPERTY:INTERFACE_INCLUDE_DIRECTORIES>
50+
)
51+
endfunction()
52+
4653
#
4754
# Create header only library
4855
#
4956
function(config_interface_lib lib_name)
50-
cmake_parse_arguments(${CMAKE_CURRENT_FUNCTION} "" "STD" "" ${ARGN})
57+
cmake_parse_arguments(ARG "" "STD" "" ${ARGN})
5158

5259
add_library(${lib_name} INTERFACE)
5360

@@ -56,7 +63,7 @@ function(config_interface_lib lib_name)
5663
#
5764
# Set the project standard and warnings
5865
#
59-
set(std ${${CMAKE_CURRENT_FUNCTION}_STD})
66+
set(std ${ARG_STD})
6067
if (${std})
6168
target_compile_features(${lib_name} INTERFACE cxx_std_${std})
6269
message(STATUS "Using c++ ${std}.\n")
@@ -68,16 +75,16 @@ function(config_interface_lib lib_name)
6875
target_include_directories(
6976
${lib_name}
7077
INTERFACE
71-
$<INSTALL_INTERFACE:include>
72-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
78+
$<INSTALL_INTERFACE:include>
79+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
7380
)
7481
endfunction()
7582

7683
#
7784
# Create static or shared library, setup header and source files
7885
#
7986
function(config_lib lib_name includes src lib_type)
80-
cmake_parse_arguments(${CMAKE_CURRENT_FUNCTION} "" "STD" "" ${ARGN})
87+
cmake_parse_arguments(ARG "" "STD" "" ${ARGN})
8188

8289
# Find all headers and implementation files
8390
list(JOIN includes "\n " includes_str)
@@ -99,7 +106,7 @@ function(config_lib lib_name includes src lib_type)
99106
#
100107
# Set the project standard and warnings
101108
#
102-
set(std ${${CMAKE_CURRENT_FUNCTION}_STD})
109+
set(std ${ARG_STD})
103110
if (${std})
104111
target_compile_features(${lib_name} PUBLIC cxx_std_${std})
105112
message(STATUS "Using c++ ${std}.\n")
@@ -111,31 +118,31 @@ function(config_lib lib_name includes src lib_type)
111118
target_include_directories(
112119
${lib_name}
113120
PUBLIC
114-
$<INSTALL_INTERFACE:include>
115-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
121+
$<INSTALL_INTERFACE:include>
122+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
116123
)
117124
endfunction()
118125

119126
#
120127
# Create executable, setup header and source files
121128
#
122129
function(config_exe exe_name exe_src)
123-
cmake_parse_arguments(${CMAKE_CURRENT_FUNCTION} "" "STD" "INCLUDES;SOURCES" ${ARGN})
124-
set(std ${${CMAKE_CURRENT_FUNCTION}_STD})
130+
cmake_parse_arguments(ARG "" "STD" "INCLUDES;SOURCES" ${ARGN})
131+
set(std ${ARG_STD})
125132

126133
list(JOIN exe_src "\n " exe_src_str)
127134
verbose_message("Found the following executable source files:\n ${exe_src_str}")
128135

129136
add_executable(${exe_name} ${exe_src})
130137

131-
if (${CMAKE_CURRENT_FUNCTION}_INCLUDES)
138+
if (ARG_INCLUDES)
132139
verbose_message("Configuring executable library")
133140

134-
if (${CMAKE_CURRENT_FUNCTION}_SOURCES)
141+
if (ARG_SOURCES)
135142
config_lib(
136143
${exe_name}_LIB
137-
"${${CMAKE_CURRENT_FUNCTION}_INCLUDES}"
138-
"${${CMAKE_CURRENT_FUNCTION}_SOURCES}"
144+
"${ARG_INCLUDES}"
145+
"${ARG_SOURCES}"
139146
STATIC
140147
STD ${std}
141148
)

tests/CMakeLists.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,40 +55,40 @@ set(
5555
config_exe(${PROJECT_NAME} ${exe_src} INCLUDES "${headers}" SOURCES "${src}")
5656

5757
message(STATUS "adding boost-ext/ut")
58-
5958
include(FetchContent)
6059
FetchContent_Declare(
6160
boost-ext-ut
62-
GIT_REPOSITORY https://github.com/boost-ext/ut.git
63-
GIT_TAG 1d304bb6e67b51dfa4fdd794eac537913d5f9e42
61+
GIT_REPOSITORY https://github.com/BlurringShadow/ut.git
62+
GIT_TAG 581e958f41943553012407c6a0b99d632ddcc032
6463
)
65-
if(MSVC)
66-
# target_compile_options(ut INTERFACE "/interface" "/translateInclude" "/ifcOnly")
67-
message(STATUS "disable module for msvc")
68-
set(BOOST_UT_DISABLE_MODULE ON)
69-
endif()
7064
FetchContent_MakeAvailable(boost-ext-ut)
7165

72-
find_program(CLANG_TIDY "clang-tidy")
73-
if(CLANG_TIDY)
74-
message(STATUS "found clang-tidy: ${CLANG_TIDY}")
75-
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY} -p ${CMAKE_CURRENT_BINARY_DIR})
76-
else()
77-
message(STATUS "clang-tidy not found")
78-
endif()
79-
80-
target_include_directories(
66+
target_compile_options(
8167
${PROJECT_NAME}_LIB
82-
SYSTEM PUBLIC $<TARGET_PROPERTY:ut,INTERFACE_INCLUDE_DIRECTORIES>
68+
PUBLIC $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>:-Werror>
69+
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
8370
)
71+
8472
target_link_libraries(${PROJECT_NAME}_LIB PUBLIC stdsharp ut)
8573

74+
#
75+
# Configure clang-tidy
76+
#
77+
if(NOT MSVC)
78+
find_program(CLANG_TIDY "clang-tidy")
79+
if(CLANG_TIDY)
80+
message(STATUS "found clang-tidy: ${CLANG_TIDY}")
81+
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY ${CLANG_TIDY} -p ${CMAKE_CURRENT_BINARY_DIR})
82+
else()
83+
message(STATUS "clang-tidy not found")
84+
endif()
85+
endif()
86+
8687
# TODO enable coverage
8788
# if(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
8889
# target_enable_coverage(${PROJECT_NAME} FORMAT lcov)
8990
# endif()
9091

91-
9292
#
9393
# Add the unit tests
9494
#

0 commit comments

Comments
 (0)