Skip to content

Commit 61b14db

Browse files
committed
refac(cmake): WIP
1 parent 8bb9377 commit 61b14db

4 files changed

Lines changed: 50 additions & 133 deletions

File tree

cmake/Utils.cmake

Lines changed: 50 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,75 @@
1-
option(
2-
VERBOSE_OUTPUT
3-
"Enable verbose output, allowing for a better understanding of each step taken."
4-
OFF
5-
)
6-
71
set(CMAKE_COLOR_DIAGNOSTICS ON)
82

9-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10-
add_compile_options(-fdiagnostics-show-template-tree)
11-
endif()
12-
13-
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
14-
add_compile_options(/utf-8 /diagnostics:caret)
15-
endif()
16-
17-
include(ProcessorCount)
18-
19-
processorcount(PROCESSOR_COUNT)
20-
21-
function(verbose_message)
22-
if(VERBOSE_OUTPUT)
23-
message(STATUS ${ARGN})
24-
endif()
25-
endfunction()
26-
273
function(target_include_as_system target_name)
284
get_target_property(included ${target_name} INTERFACE_INCLUDE_DIRECTORIES)
295
get_target_property(target_type ${target_name} TYPE)
30-
target_include_directories(
31-
${target_name}
32-
SYSTEM
33-
BEFORE
34-
${target_type}
35-
${included}
36-
)
6+
target_include_directories(${target_name} SYSTEM BEFORE ${target_type} ${included})
377
endfunction()
388

39-
# Create static or shared library, setup header and source files
40-
function(config_lib lib_name lib_type)
41-
message("Configuring target library ${lib_name}")
42-
43-
cmake_parse_arguments(
44-
ARG
45-
""
46-
"STD;VER"
47-
"INC_DIR;INSTALL_INC_DIR;SRC"
48-
${ARGN}
49-
)
9+
function(target_set_common_cxx_properties target_name target_tag)
10+
cmake_parse_arguments(ARG "" "STD;VER" "INC_DIR;INSTALL_INC_DIR;SRC" ${ARGN})
5011

51-
if(NOT DEFINED ARG_INC_DIR)
52-
set(ARG_INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
12+
if(ARG_STD)
13+
target_compile_features(${lib_name} ${target_tag} cxx_std_${ARG_STD})
14+
message(STATUS "Using c++ ${ARG_STD}")
5315
endif()
5416

55-
if(NOT DEFINED INSTALL_INC_DIR)
56-
set(INSTALL_INC_DIR include)
17+
if(NOT DEFINED ARG_VER)
18+
set(ARG_VER "${CMAKE_PROJECT_VERSION}")
5719
endif()
5820

59-
list(JOIN ARG_INC_DIR "\n " includes_str)
60-
verbose_message("Found the following include dir:\n ${includes_str}")
61-
62-
list(JOIN ARG_SRC "\n " src_str)
63-
verbose_message("Found the following source files:\n ${src_str}")
64-
65-
add_library(${lib_name} ${lib_type} ${ARG_SRC})
66-
67-
set(inc_tag PUBLIC)
68-
69-
if(lib_type STREQUAL "SHARED")
70-
set_target_properties(
71-
${lib_name}
72-
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS OFF
73-
)
74-
75-
string(TOUPPER "${lib_name}_WIN_DLL" ${lib_name}_WIN_DLL)
76-
message(
77-
STATUS
78-
"Detected shared library, setting ${lib_name}_WIN_DLL to ${${lib_name}_WIN_DLL}"
79-
)
80-
target_compile_definitions(
81-
${lib_name}
82-
PRIVATE
83-
$<$<CXX_COMPILER_ID:MSVC>:${${lib_name}_WIN_DLL}=__declspec\(dllexport\)>
84-
)
85-
message(
86-
STATUS
87-
"Added ${lib_name}_WIN_DLL to target ${lib_name} compile definitions"
88-
)
89-
elseif(lib_type STREQUAL "INTERFACE")
90-
set(inc_tag INTERFACE)
21+
if(NOT DEFINED ARG_INC_DIR)
22+
set(ARG_INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
9123
endif()
9224

93-
if(ARG_STD)
94-
target_compile_features(${lib_name} ${inc_tag} cxx_std_${ARG_STD})
95-
message(STATUS "Using c++ ${ARG_STD}")
25+
if(NOT DEFINED ARG_INSTALL_INC_DIR)
26+
set(ARG_INSTALL_INC_DIR include)
9627
endif()
9728

29+
list(JOIN ARG_INC_DIR "\n" includes_str)
30+
message(STATUS "Found the following include dir:")
31+
message(STATUS "${includes_str}")
32+
list(JOIN ARG_SRC "\n" src_str)
33+
message(STATUS "Found the following source files:")
34+
message(STATUS "${src_str}")
35+
36+
set_target_properties(
37+
${lib_name} PROPERTIES
38+
WINDOWS_EXPORT_ALL_SYMBOLS ON
39+
VERSION "${ARG_VER}"
40+
)
9841
target_include_directories(
99-
${lib_name}
100-
${inc_tag}
42+
${lib_name} ${target_tag}
10143
$<INSTALL_INTERFACE:${ARG_INSTALL_INC_DIR}>
10244
$<BUILD_INTERFACE:${ARG_INC_DIR}>
10345
)
46+
target_compile_options(
47+
${target_name} ${target_tag}
48+
$<$<CXX_COMPILER_ID:Clang>:-fdiagnostics-show-template-tree>
49+
$<$<CXX_COMPILER_ID:MSVC>:/utf-8,/diagnostics:caret>
50+
)
51+
target_sources(${target_name} ${target_tag} ${ARG_SRC})
52+
endfunction()
10453

105-
if(NOT DEFINED ARG_VER)
106-
set(ARG_VER "${CMAKE_PROJECT_VERSION}")
107-
endif()
54+
# Create static or shared library, setup header and source files
55+
function(add_interface_target lib_name)
56+
message(STATUS "Configuring interface target ${lib_name}")
57+
add_library(${lib_name} INTERFACE)
58+
target_set_common_cxx_properties(${lib_name} INTERFACE ${ARGN})
59+
endfunction()
10860

109-
set_target_properties(${lib_name} PROPERTIES VERSION "${ARG_VER}")
61+
# Create static or shared library, setup header and source files
62+
function(add_lib_target lib_name lib_type)
63+
message(STATUS "Configuring library target ${lib_name}")
64+
add_library(${lib_name} ${lib_type})
65+
target_set_common_cxx_properties(${lib_name} PUBLIC ${ARGN})
11066
endfunction()
11167

11268
# Create executable, setup header and source files
113-
function(config_exe exe_name)
114-
cmake_parse_arguments(ARG "" "STD;VER" "EXE_SRC" ${ARGN})
115-
116-
list(JOIN ARG_EXE_SRC "\n " exe_src_str)
117-
verbose_message(
118-
"Found the following executable source files:\n ${exe_src_str}"
119-
)
120-
121-
add_executable(${exe_name} "${ARG_EXE_SRC}")
122-
123-
if(NOT DEFINED ARG_VER)
124-
set(ARG_VER ${CMAKE_PROJECT_VERSION})
125-
endif()
126-
127-
set_target_properties(${exe_name} PROPERTIES VERSION ${ARG_VER})
128-
129-
if(ARG_STD)
130-
target_compile_features(${exe_name} PUBLIC cxx_std_${ARG_STD})
131-
message(STATUS "Using c++ ${ARG_STD}.")
132-
endif()
69+
function(add_exe_target exe_name)
70+
cmake_parse_arguments(ARG "" "" "SRC" ${ARGN})
71+
add_executable(${exe_name})
72+
target_set_common_cxx_properties(${exe_name} PRIVATE ${ARGN})
13373
endfunction()
13474

13575
# install library
@@ -140,7 +80,7 @@ function(target_install target_name)
14080
cmake_parse_arguments(
14181
ARG
14282
"ARCH_INDEPENDENT"
143-
"BIN_DIR;INC_DST;VER;COMPATIBILITY;NAMESPACE;CONFIG_FILE"
83+
"BIN_DIR;INC_DST;COMPATIBILITY;NAMESPACE;CONFIG_FILE"
14484
"DEPENDENCIES"
14585
${ARGN}
14686
)
@@ -149,21 +89,15 @@ function(target_install target_name)
14989

15090
if(NOT DEFINED ARG_BIN_DIR)
15191
get_target_property(ARG_BIN_DIR ${target_name} BINARY_DIR)
152-
verbose_message("Use default binary dir ${ARG_BIN_DIR}")
15392
endif()
15493

15594
if(NOT DEFINED ARG_INC_DST)
15695
set(ARG_INC_DST "./")
15796
endif()
15897

159-
if(NOT DEFINED ARG_VER)
160-
get_target_property(ARG_VER ${target_name} VERSION)
161-
verbose_message("Use default version ${ARG_VER}")
162-
endif()
16398

16499
if(NOT DEFINED ARG_NAMESPACE)
165100
set(ARG_NAMESPACE ${CMAKE_PROJECT_NAME})
166-
verbose_message("Use default namespace ${ARG_NAMESPACE}")
167101
endif()
168102

169103
install(
@@ -188,6 +122,7 @@ function(target_install target_name)
188122
INCLUDES DESTINATION "${ARG_INC_DST}"
189123
)
190124

125+
get_target_property(ARG_VER ${target_name} VERSION)
191126
if(
192127
(NOT DEFINED ARG_ARCH_INDEPENDENT)
193128
AND (target_type STREQUAL "INTERFACE_LIBRARY")
@@ -203,9 +138,7 @@ function(target_install target_name)
203138
PARENT_SCOPE
204139
)
205140

206-
verbose_message(
207-
"CMake files install directory: ${${target_name}_INSTALL_CMAKEDIR}"
208-
)
141+
message(STATUS "CMake files install directory: ${${target_name}_INSTALL_CMAKEDIR}")
209142

210143
install(
211144
EXPORT ${target_name}Targets

cmake/vcpkg/scripts/toolchains/linux-clang.cmake

Lines changed: 0 additions & 8 deletions
This file was deleted.

cmake/vcpkg/triplets/community/x64-linux-clang-dynamic.cmake

Lines changed: 0 additions & 4 deletions
This file was deleted.

cmake/vcpkg/triplets/community/x64-linux-clang.cmake

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)