Skip to content

Commit 152f92e

Browse files
authored
Merge branch 'main' into feature/fix-interface-include-directory-path
2 parents 9cbc9c2 + 1e7264d commit 152f92e

File tree

13 files changed

+208
-75
lines changed

13 files changed

+208
-75
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,32 @@ jobs:
2222
- gcc
2323
cmake:
2424
- true
25+
vcvarsall:
26+
- true
2527
include:
2628
- os: "windows-2022"
2729
compiler: "msvc"
2830
cmake: true
31+
vcvarsall: true
32+
- os: "windows-2022"
33+
compiler: "msvc"
34+
cmake: 3.18.0
35+
cmake_generator: "Ninja"
36+
vcvarsall: true
2937
- os: "windows-2022"
3038
compiler: "msvc"
3139
cmake: 3.18.0
3240
cmake_generator: "Ninja"
41+
vcvarsall: false
42+
- os: "windows-2022"
43+
compiler: "msvc"
44+
cmake: 3.18.0
45+
vcvarsall: false
3346
exclude:
3447
- os: "windows-2022"
3548
compiler: "gcc"
3649
cmake: true
50+
vcvarsall: true
3751
steps:
3852
- uses: actions/checkout@v2
3953
- name: Cache
@@ -54,7 +68,7 @@ jobs:
5468
uses: aminya/setup-cpp@v1
5569
with:
5670
compiler: ${{ matrix.compiler }}
57-
vcvarsall: ${{ contains(matrix.os, 'windows') }}
71+
vcvarsall: ${{ contains(matrix.os, 'windows') && matrix.vcvarsall }}
5872
cmake: ${{ matrix.cmake }}
5973
ninja: true
6074
vcpkg: true

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ cmake_minimum_required(VERSION 3.16)
1717
# If commented, the latest supported standard for your compiler is automatically set.
1818
# set(CMAKE_CXX_STANDARD 20)
1919
20-
# Add project_options v0.20.0
20+
# Add project_options v0.21.1
2121
# https://github.com/aminya/project_options
2222
# Change the version in the following URL to update the package (watch the releases of the repository for future updates)
2323
include(FetchContent)
24-
FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.20.0.zip)
24+
FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.21.1.zip)
2525
FetchContent_MakeAvailable(_project_options)
2626
include(${_project_options_SOURCE_DIR}/Index.cmake)
2727
@@ -90,6 +90,7 @@ project_options(
9090
# ENABLE_USER_LINKER
9191
# ENABLE_BUILD_WITH_TIME_TRACE
9292
# ENABLE_UNITY
93+
# CONAN_PROFILE ${profile_path} # passes a profile to conan: see https://docs.conan.io/en/latest/reference/profiles.html
9394
)
9495
```
9596

@@ -214,7 +215,11 @@ It accepts the following named flags:
214215

215216
It gets the following named parameters that can have different values in front of them:
216217

217-
- `DOXYGEN_THEME`: the name of the Doxygen theme to use. Supported themes: `awesome-sidebar` (default), `awesome` and `original`.
218+
- `DOXYGEN_THEME`: the name of the Doxygen theme to use. Supported themes:
219+
- `awesome-sidebar` (default)
220+
- `awesome`
221+
- `original`
222+
- Alternatively you can supply a list of css files to be added to [DOXYGEN_HTML_EXTRA_STYLESHEET](https://www.doxygen.nl/manual/config.html#cfg_html_extra_stylesheet)
218223
- `PCH_HEADERS`: the list of the headers to precompile
219224
- `MSVC_WARNINGS`: Override the defaults for the MSVC warnings
220225
- `CLANG_WARNINGS`: Override the defaults for the CLANG warnings
@@ -323,11 +328,11 @@ cmake_minimum_required(VERSION 3.16)
323328
# If commented, the latest supported standard for your compiler is automatically set.
324329
# set(CMAKE_CXX_STANDARD 20)
325330
326-
# Add project_options v0.20.0
331+
# Add project_options v0.21.1
327332
# https://github.com/aminya/project_options
328333
# Change the version in the following URL to update the package (watch the releases of the repository for future updates)
329334
include(FetchContent)
330-
FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.20.0.zip)
335+
FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.21.1.zip)
331336
FetchContent_MakeAvailable(_project_options)
332337
include(${_project_options_SOURCE_DIR}/Index.cmake)
333338

cspell.config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enableGlobDot: true
1212
words:
1313
- aarch
1414
- aminya
15+
- Amnet
1516
- anotherproj
1617
- applellvm
1718
- ARGN
@@ -73,6 +74,7 @@ words:
7374
- shlib
7475
- suppr
7576
- TOLOWER
77+
- TOUPPER
7678
- ubsan
7779
- vcpkg
7880
- vcvarsall

src/Common.cmake

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,38 @@ macro(common_project_options)
2121
"RelWithDebInfo")
2222
endif()
2323

24+
get_property(BUILDING_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
25+
if(BUILDING_MULTI_CONFIG)
26+
if(NOT CMAKE_BUILD_TYPE)
27+
# Make sure that all supported configuration types have their
28+
# associated conan packages available. You can reduce this
29+
# list to only the configuration types you use, but only if one
30+
# is not forced-set on the command line for VS
31+
message(TRACE "Setting up multi-config build types")
32+
set(CMAKE_CONFIGURATION_TYPES
33+
Debug
34+
Release
35+
RelWithDebInfo
36+
MinSizeRel
37+
CACHE STRING "Enabled build types" FORCE)
38+
else()
39+
message(TRACE "User chose a specific build type, so we are using that")
40+
set(CMAKE_CONFIGURATION_TYPES
41+
${CMAKE_BUILD_TYPE}
42+
CACHE STRING "Enabled build types" FORCE)
43+
endif()
44+
endif()
45+
46+
# Fix for Amnet/Colcon
47+
if(NOT
48+
"${AMENT_PREFIX_PATH}"
49+
STREQUAL
50+
""
51+
OR "$ENV{COLCON}" STREQUAL "1")
52+
# these are used in order:
53+
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO "RelWithDebInfo;Release;None;NoConfig")
54+
endif()
55+
2456
# Generate compile_commands.json to make it easier to work with clang based tools
2557
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
2658

@@ -50,6 +82,5 @@ macro(common_project_options)
5082
set_standards()
5183

5284
# run vcvarsall when msvc is used
53-
include("${ProjectOptions_SRC_DIR}/VCEnvironment.cmake")
5485
run_vcvarsall()
5586
endmacro()

src/Conan.cmake

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,63 @@ macro(run_conan)
3333
URL
3434
https://bincrafters.jfrog.io/artifactory/api/conan/public-conan)
3535

36-
# For multi configuration generators, like VS and XCode
37-
if(NOT CMAKE_CONFIGURATION_TYPES)
38-
message(STATUS "Single configuration build!")
39-
set(LIST_OF_BUILD_TYPES ${CMAKE_BUILD_TYPE})
36+
if(CONAN_EXPORTED)
37+
# standard conan installation, in which deps will be defined in conanfile. It is not necessary to call conan again, as it is already running.
38+
if(EXISTS "${CMAKE_BINARY_DIR}/../conanbuildinfo.cmake")
39+
include(${CMAKE_BINARY_DIR}/../conanbuildinfo.cmake)
40+
else()
41+
message(
42+
FATAL_ERROR "Could not set up conan because \"${CMAKE_BINARY_DIR}/../conanbuildinfo.cmake\" does not exist")
43+
endif()
44+
conan_basic_setup()
4045
else()
41-
message(STATUS "Multi-configuration build: '${CMAKE_CONFIGURATION_TYPES}'!")
42-
set(LIST_OF_BUILD_TYPES ${CMAKE_CONFIGURATION_TYPES})
43-
endif()
46+
# For multi configuration generators, like VS and XCode
47+
if(NOT CMAKE_CONFIGURATION_TYPES)
48+
message(STATUS "Single configuration build!")
49+
set(LIST_OF_BUILD_TYPES ${CMAKE_BUILD_TYPE})
50+
else()
51+
message(STATUS "Multi-configuration build: '${CMAKE_CONFIGURATION_TYPES}'!")
52+
set(LIST_OF_BUILD_TYPES ${CMAKE_CONFIGURATION_TYPES})
53+
endif()
4454

45-
is_verbose(_is_verbose)
46-
if(NOT ${_is_verbose})
47-
set(OUTPUT_QUIET "OUTPUT_QUIET")
48-
else()
49-
set(OUTPUT_QUIET OFF)
50-
endif()
55+
is_verbose(_is_verbose)
56+
if(NOT ${_is_verbose})
57+
set(OUTPUT_QUIET "OUTPUT_QUIET")
58+
else()
59+
set(OUTPUT_QUIET OFF)
60+
endif()
5161

52-
foreach(TYPE ${LIST_OF_BUILD_TYPES})
53-
message(STATUS "Running Conan for build type '${TYPE}'")
62+
foreach(TYPE ${LIST_OF_BUILD_TYPES})
63+
message(STATUS "Running Conan for build type '${TYPE}'")
5464

55-
# Detects current build settings to pass into conan
56-
conan_cmake_autodetect(settings BUILD_TYPE ${TYPE})
65+
if("${ProjectOptions_CONAN_PROFILE}" STREQUAL "")
66+
# Detects current build settings to pass into conan
67+
conan_cmake_autodetect(settings BUILD_TYPE ${TYPE})
68+
set(CONAN_SETTINGS SETTINGS ${settings})
69+
set(CONAN_ENV ENV "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}")
70+
else()
71+
# Derive all conan settings from a conan profile
72+
set(CONAN_SETTINGS PROFILE ${ProjectOptions_CONAN_PROFILE})
73+
# CONAN_ENV should be redundant, since the profile can set CC & CXX
74+
endif()
5775

58-
# PATH_OR_REFERENCE ${CMAKE_SOURCE_DIR} is used to tell conan to process
59-
# the external "conanfile.py" provided with the project
60-
# Alternatively a conanfile.txt could be used
61-
conan_cmake_install(
62-
PATH_OR_REFERENCE
63-
${CMAKE_SOURCE_DIR}
64-
BUILD
65-
missing
66-
# Pass compile-time configured options into conan
67-
OPTIONS
68-
${ProjectOptions_CONAN_OPTIONS}
69-
# Pass CMake compilers to Conan
70-
ENV
71-
"CC=${CMAKE_C_COMPILER}"
72-
"CXX=${CMAKE_CXX_COMPILER}"
73-
SETTINGS
74-
${settings}
75-
${OUTPUT_QUIET})
76-
endforeach()
76+
# PATH_OR_REFERENCE ${CMAKE_SOURCE_DIR} is used to tell conan to process
77+
# the external "conanfile.py" provided with the project
78+
# Alternatively a conanfile.txt could be used
79+
conan_cmake_install(
80+
PATH_OR_REFERENCE
81+
${CMAKE_SOURCE_DIR}
82+
BUILD
83+
missing
84+
# Pass compile-time configured options into conan
85+
OPTIONS
86+
${ProjectOptions_CONAN_OPTIONS}
87+
# Pass CMake compilers to Conan
88+
${CONAN_ENV}
89+
# Pass either autodetected settings or a conan profile
90+
${CONAN_SETTINGS}
91+
${OUTPUT_QUIET})
92+
endforeach()
93+
endif()
7794

7895
endmacro()

src/Doxygen.cmake

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,22 @@ function(enable_doxygen DOXYGEN_THEME)
4242
set(DOXYGEN_HTML_EXTRA_STYLESHEET ${DOXYGEN_HTML_EXTRA_STYLESHEET}
4343
"${_doxygen_theme_SOURCE_DIR}/doxygen-awesome-sidebar-only.css")
4444
endif()
45-
else()
45+
elseif("${DOXYGEN_THEME}" STREQUAL "original")
4646
# use the original doxygen theme
47+
else()
48+
# use custom doxygen theme
49+
50+
# if any of the custom theme files are not found, the theme is reverted to original
51+
set(OLD_DOXYGEN_HTML_EXTRA_STYLESHEET ${DOXYGEN_HTML_EXTRA_STYLESHEET})
52+
foreach(file ${DOXYGEN_THEME})
53+
if(NOT EXISTS ${file})
54+
message(WARNING "Could not find doxygen theme file '${file}'. Using original theme.")
55+
set(DOXYGEN_HTML_EXTRA_STYLESHEET ${OLD_DOXYGEN_HTML_EXTRA_STYLESHEET})
56+
break()
57+
else()
58+
set(DOXYGEN_HTML_EXTRA_STYLESHEET ${DOXYGEN_HTML_EXTRA_STYLESHEET} "${file}")
59+
endif()
60+
endforeach()
4761
endif()
4862

4963
# find doxygen and dot if available

src/Index.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ include("${ProjectOptions_SRC_DIR}/Tests.cmake")
2929
include("${ProjectOptions_SRC_DIR}/Sanitizers.cmake")
3030
include("${ProjectOptions_SRC_DIR}/Doxygen.cmake")
3131
include("${ProjectOptions_SRC_DIR}/StaticAnalyzers.cmake")
32-
include("${ProjectOptions_SRC_DIR}/Vcpkg.cmake")
32+
include("${ProjectOptions_SRC_DIR}/VCEnvironment.cmake")
33+
34+
# find msvc on windows if required. Should be called before run_vcpkg and run_conan to be effective
35+
find_msvc()
36+
3337
include("${ProjectOptions_SRC_DIR}/Conan.cmake")
38+
include("${ProjectOptions_SRC_DIR}/Vcpkg.cmake")
3439

3540
#
3641
# Params:
@@ -86,8 +91,9 @@ macro(project_options)
8691
ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
8792
ENABLE_SANITIZER_THREAD
8893
ENABLE_SANITIZER_MEMORY)
89-
set(oneValueArgs DOXYGEN_THEME VS_ANALYSIS_RULESET)
94+
set(oneValueArgs VS_ANALYSIS_RULESET CONAN_PROFILE)
9095
set(multiValueArgs
96+
DOXYGEN_THEME
9197
MSVC_WARNINGS
9298
CLANG_WARNINGS
9399
GCC_WARNINGS

src/PackageProject.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function(package_project)
8282
set(_PackageProject_COMPATIBILITY "SameMajorVersion")
8383
endif()
8484

85-
# default to the build_directory/project_name
85+
# default to the build_directory/project_name
8686
if("${_PackageProject_CONFIG_EXPORT_DESTINATION}" STREQUAL "")
8787
set(_PackageProject_CONFIG_EXPORT_DESTINATION "${CMAKE_BINARY_DIR}/${_PackageProject_NAME}")
8888
endif()

src/VCEnvironment.cmake

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,50 @@ include_guard()
22

33
include("${ProjectOptions_SRC_DIR}/Utilities.cmake")
44

5+
macro(find_msvc)
6+
# Try finding MSVC
7+
if(# if MSVC is not found by CMake yet,
8+
NOT MSVC
9+
AND # if the user has specified cl using -DCMAKE_CXX_COMPILER=cl or -DCMAKE_C_COMPILER=cl
10+
((CMAKE_CXX_COMPILER MATCHES "^cl(.exe)?$" AND CMAKE_C_COMPILER MATCHES "^cl(.exe)?$")
11+
# if the user has specified cl using CC and CXX but not using -DCMAKE_CXX_COMPILER or -DCMAKE_C_COMPILER
12+
OR (NOT CMAKE_CXX_COMPILER
13+
AND NOT CMAKE_C_COMPILER
14+
AND ("$ENV{CXX}" MATCHES "^cl(.exe)?$" AND "$ENV{CC}" MATCHES "^cl(.exe)?$"))
15+
))
16+
message(STATUS "Finding MSVC cl.exe ...")
17+
include(FetchContent)
18+
FetchContent_Declare(
19+
_msvc_toolchain
20+
URL "https://github.com/MarkSchofield/Toolchain/archive/5fdd24e609cfb860c06ada86c9e64f43062e0866.zip")
21+
FetchContent_MakeAvailable(_msvc_toolchain)
22+
include("${_msvc_toolchain_SOURCE_DIR}/Windows.MSVC.toolchain.cmake")
23+
message(STATUS "Setting CMAKE_CXX_COMPILER to ${CMAKE_CXX_COMPILER}")
24+
set(ENV{CXX} ${CMAKE_CXX_COMPILER})
25+
set(ENV{CC} ${CMAKE_C_COMPILER})
26+
set(MSVC_FOUND TRUE)
27+
run_vcvarsall()
28+
endif()
29+
endmacro()
30+
531
# Run vcvarsall.bat and set CMake environment variables
6-
function(run_vcvarsall)
7-
# if MSVC but VSCMD_VER is not set, which means vcvarsall has not run
8-
if(MSVC AND "$ENV{VSCMD_VER}" STREQUAL "")
32+
macro(run_vcvarsall)
33+
# detect the architecture
34+
detect_architecture(VCVARSALL_ARCH)
35+
36+
# If MSVC is being used, and ASAN is enabled, we need to set the debugger environment
37+
# so that it behaves well with MSVC's debugger, and we can run the target from visual studio
38+
if(MSVC)
39+
string(TOUPPER "${VCVARSALL_ARCH}" VCVARSALL_ARCH_UPPER)
40+
set(VS_DEBUGGER_ENVIRONMENT "PATH=\$(VC_ExecutablePath_${VCVARSALL_ARCH_UPPER});%PATH%")
41+
42+
get_all_targets(all_targets)
43+
set_target_properties(${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT "${VS_DEBUGGER_ENVIRONMENT}")
44+
endif()
45+
46+
# if msvc_found is set by find_msvc
47+
# or if MSVC but VSCMD_VER is not set, which means vcvarsall has not run
48+
if(MSVC_FOUND OR (MSVC AND "$ENV{VSCMD_VER}" STREQUAL ""))
949

1050
# find vcvarsall.bat
1151
get_filename_component(MSVC_DIR ${CMAKE_CXX_COMPILER} DIRECTORY)
@@ -20,9 +60,6 @@ function(run_vcvarsall)
2060
PATH_SUFFIXES "VC/Auxiliary/Build" "Common7/Tools" "Tools")
2161

2262
if(EXISTS ${VCVARSALL_FILE})
23-
# detect the architecture
24-
detect_architecture(VCVARSALL_ARCH)
25-
2663
# run vcvarsall and print the environment variables
2764
message(STATUS "Running `${VCVARSALL_FILE} ${VCVARSALL_ARCH}` to set up the MSVC environment")
2865
execute_process(
@@ -38,12 +75,11 @@ function(run_vcvarsall)
3875

3976
# set the environment variables
4077
set_env_from_string("${VCVARSALL_ENV}")
41-
4278
else()
4379
message(
4480
WARNING
4581
"Could not find `vcvarsall.bat` for automatic MSVC environment preparation. Please manually open the MSVC command prompt and rebuild the project.
4682
")
4783
endif()
4884
endif()
49-
endfunction()
85+
endmacro()

0 commit comments

Comments
 (0)