Skip to content

Commit c96bdff

Browse files
committed
Merge branch 'main' into pr/163
2 parents 41a7403 + cad19a9 commit c96bdff

13 files changed

Lines changed: 73 additions & 108 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,14 @@ jobs:
3131
vcvarsall: true
3232
- os: "windows-2022"
3333
compiler: "msvc"
34-
cmake: 3.18.0
3534
cmake_generator: "Ninja"
3635
vcvarsall: true
3736
- os: "windows-2022"
3837
compiler: "msvc"
39-
cmake: 3.18.0
4038
cmake_generator: "Ninja"
4139
vcvarsall: false
4240
- os: "windows-2022"
4341
compiler: "msvc"
44-
cmake: 3.18.0
4542
vcvarsall: false
4643
steps:
4744
- uses: actions/checkout@v2

src/Index.cmake

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.18.0")
2-
cmake_minimum_required(VERSION 3.18)
3-
else()
4-
cmake_minimum_required(VERSION 3.16)
5-
message(
6-
WARNING
7-
"Consider upgrading CMake to the latest version. CMake ${CMAKE_VERSION} might fail in the linking stage because of missing references."
8-
)
9-
endif()
1+
cmake_minimum_required(VERSION 3.20)
2+
# 3.20 is required by the windows toolchain and cmake_path. It also has a more reliable building functionality.
3+
# 3.18 required by package_project and interprocedural optimization. It also has a more reliable building functionality (no errors during the linking stage).
104

115
include_guard()
126

src/Optimization.cmake

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
include_guard()
22

33
macro(enable_interprocedural_optimization project_name)
4-
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.18.0")
5-
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
6-
include(CheckIPOSupported)
7-
check_ipo_supported(RESULT result OUTPUT output)
8-
is_mingw(_is_mingw)
9-
if(result AND NOT ${_is_mingw})
10-
# If a static library of this project is used in another project that does not have `CMAKE_INTERPROCEDURAL_OPTIMIZATION` enabled, a linker error might happen.
11-
# TODO set this option in `package_project` function.
12-
message(
13-
STATUS
14-
"Interprocedural optimization is enabled. In other projects, linking with the compiled libraries of this project might require `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)`"
15-
)
16-
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
17-
set_target_properties(${project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
18-
else()
19-
message(WARNING "Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}")
20-
endif()
4+
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
5+
include(CheckIPOSupported)
6+
check_ipo_supported(RESULT result OUTPUT output)
7+
is_mingw(_is_mingw)
8+
if(result AND NOT ${_is_mingw})
9+
# If a static library of this project is used in another project that does not have `CMAKE_INTERPROCEDURAL_OPTIMIZATION` enabled, a linker error might happen.
10+
# TODO set this option in `package_project` function.
11+
message(
12+
STATUS
13+
"Interprocedural optimization is enabled. In other projects, linking with the compiled libraries of this project might require `set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)`"
14+
)
15+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
16+
set_target_properties(${project_name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
17+
else()
18+
message(WARNING "Interprocedural Optimization is not supported. Not using it. Here is the error log: ${output}")
2119
endif()
22-
else()
23-
message(
24-
WARNING
25-
"Consider upgrading CMake to the latest version. CMake ${CMAKE_VERSION} does not support ENABLE_INTERPROCEDURAL_OPTIMIZATION."
26-
)
2720
endif()
2821
endmacro()
2922

src/PackageProject.cmake

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,8 @@ include_guard()
55
# A function that packages the project for external usage (e.g. from vcpkg, Conan, etc).
66
# See the [README.md] for more details
77
function(package_project)
8-
if(${CMAKE_VERSION} VERSION_LESS "3.18.0")
9-
message(
10-
WARNING
11-
"Consider upgrading CMake to the latest version. CMake ${CMAKE_VERSION} does not support checking for policy CMP0103."
12-
)
13-
else()
14-
cmake_minimum_required(VERSION 3.18)
15-
cmake_policy(SET CMP0103 NEW) # disallow multiple calls with the same NAME
16-
endif()
17-
18-
set(_options ARCH_INDEPENDENT # default to false
19-
)
8+
# default to false
9+
set(_options ARCH_INDEPENDENT)
2010
set(_oneValueArgs
2111
# default to the project_name:
2212
NAME

src/SystemLink.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ function(target_include_system_directories target)
1212

1313
foreach(scope IN ITEMS INTERFACE PUBLIC PRIVATE)
1414
foreach(lib_include_dirs IN LISTS ARG_${scope})
15-
if(NOT MSVC)
16-
# system includes do not work in MSVC
17-
# awaiting https://gitlab.kitware.com/cmake/cmake/-/issues/18272#
18-
# awaiting https://gitlab.kitware.com/cmake/cmake/-/issues/17904
15+
if(NOT MSVC OR (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL
16+
"19.29.30036.3"))
17+
# system includes do not work prior to CMake 3.24.0 and MSVC 19.29.30036.3
1918
set(_SYSTEM SYSTEM)
2019
endif()
2120
if(${scope} STREQUAL "INTERFACE" OR ${scope} STREQUAL "PUBLIC")

test/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ target_link_system_libraries(
117117
PRIVATE
118118
fmt::fmt
119119
Eigen3::Eigen)
120-
target_link_system_libraries(
121-
lib2
122-
PRIVATE
123-
mythirdpartylib)
120+
target_link_system_libraries(lib2 PRIVATE mythirdpartylib)
124121

125122
# package everything automatically
126123
package_project(

test/include/mylib/lib.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
#include <cstring>
1919

2020
int some_fun() {
21-
fmt::print("Hello from fmt{}", "!");
21+
fmt::print("Hello from fmt{}", "!");
2222

23-
// populate an Eigen vector with the values
24-
auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);
23+
// populate an Eigen vector with the values
24+
auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);
2525

26-
// print the vector
27-
fmt::print("{}", eigen_vec);
26+
// print the vector
27+
fmt::print("{}", eigen_vec);
2828

29-
return 0;
29+
return 0;
3030
}
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
21
add_library(mythirdpartylib STATIC src/Foo.cpp)
32
generate_export_header(mythirdpartylib)
43

5-
target_include_directories(mythirdpartylib
6-
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
7-
$<INSTALL_INTERFACE:include>
8-
)
9-
target_include_directories(mythirdpartylib
10-
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
11-
)
4+
target_include_directories(mythirdpartylib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
5+
$<INSTALL_INTERFACE:include>)
6+
target_include_directories(mythirdpartylib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#pragma once
22

3-
#include <vector>
43
#include <string>
4+
#include <vector>
55

66
#include "mythirdpartylib_export.h"
77

88
namespace mythirdpartylib {
99

1010
class MYTHIRDPARTYLIB_EXPORT Foo {
1111
public:
12-
Foo() = default;
12+
Foo() = default;
1313

14-
/*implicit*/ Foo(int a) : m_a(a) {}
14+
/*implicit*/ Foo(int a) : m_a(a) {}
1515

16-
int a() const { return m_a; }
16+
int a() const { return m_a; }
1717

18-
void update(bool b, bool c, bool d);
19-
void bad(std::vector<std::string>& v);
18+
void update(bool b, bool c, bool d);
19+
void bad(std::vector<std::string> &v);
2020

2121
private:
22-
int m_a;
22+
int m_a;
2323
};
2424

25-
}
25+
} // namespace mythirdpartylib

test/libs/mythirdpartylib/src/Foo.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
namespace mythirdpartylib {
44

55
void Foo::update(bool b, bool c, bool d) {
6-
int e = b + d;
7-
m_a = e;
6+
int e = b + d;
7+
m_a = e;
88
}
99

10-
void Foo::bad(std::vector<std::string>& v) {
11-
std::string val = "hello";
12-
int index = -1; // bad, plus should use gsl::index
13-
for (int i = 0; i < v.size(); ++i) {
14-
if (v[i] == val) {
15-
index = i;
16-
break;
17-
}
10+
void Foo::bad(std::vector<std::string> &v) {
11+
std::string val = "hello";
12+
int index = -1; // bad, plus should use gsl::index
13+
for (int i = 0; i < v.size(); ++i) {
14+
if (v[i] == val) {
15+
index = i;
16+
break;
1817
}
18+
}
1919
}
2020

21-
static Foo foo (5);
21+
static Foo foo(5);
2222
static Foo bar = 42;
2323

24-
}
24+
} // namespace mythirdpartylib

0 commit comments

Comments
 (0)