Skip to content

Commit c0b20b9

Browse files
committed
Update CMake
1 parent 1e3f918 commit c0b20b9

File tree

21 files changed

+327
-136
lines changed

21 files changed

+327
-136
lines changed

Boost/CMakeLists.txt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
cmake_minimum_required(VERSION 3.20)
22

3-
# ┌──────────────────────────────────────────────────────────────────┐
4-
# │ Projects Settings │
5-
# └──────────────────────────────────────────────────────────────────┘
6-
project("boost"
3+
project("boost_examples"
74
VERSION 1.0.0
85
DESCRIPTION "Examples on using boost library"
96
LANGUAGES CXX
107
)
118

12-
# ┌──────────────────────────────────────────────────────────────────┐
13-
# │ CXX Standard Requirements │
14-
# └──────────────────────────────────────────────────────────────────┘
15-
set(CMAKE_CXX_STANDARD 17)
16-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
find_package(Boost REQUIRED)
1710

18-
set(CMAKE_INCLUDE_CURRENT_DIR ON)
11+
include_directories(${Boost_INCLUDE_DIRS})
1912

20-
# ┌──────────────────────────────────────────────────────────────────┐
21-
# │ Sub-directories with CMake │
22-
# └──────────────────────────────────────────────────────────────────┘
13+
add_subdirectory("Assign")
2314
add_subdirectory("Common")
15+
add_subdirectory("ComparablePoint")
16+
add_subdirectory("CurrentFunctionMacro")
17+
add_subdirectory("Fusion")
2418
add_subdirectory("LambdaExample")
19+
add_subdirectory("LinearRegression")
20+
add_subdirectory("MultiArray")
21+
add_subdirectory("Proto")
22+
add_subdirectory("StringRef")
2523
add_subdirectory("TimeDate")
24+
add_subdirectory("TypeIndex")

Boost/Common/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ project("installation_test")
55
set(CMAKE_CXX_STANDARD 11)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77

8+
# Find Boost via vcpkg
9+
find_package(Boost REQUIRED)
10+
811
add_executable(installation_test "test.cpp")
9-
# Modern style CMake: target-centric
10-
target_include_directories(installation_test PUBLIC "C:\\boost\\boost_1_82_0")
12+
13+
# Explicitly add Boost include directories if needed
14+
target_include_directories(installation_test PUBLIC ${Boost_INCLUDE_DIRS})
15+
16+
target_link_libraries(installation_test PUBLIC ${Boost_LIBRARIES})

Boost/Common/test.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@
99
* \date September 2022
1010
*********************************************************************/
1111

12-
#include <iostream>
13-
#include <boost/version.hpp>
1412
#include <boost/config.hpp>
13+
#include <boost/version.hpp>
14+
#include <iostream>
1515

16-
auto main(void) -> int {
16+
int main(void) {
1717
/* boost/version.hpp */
18-
std::cout << BOOST_VERSION << "\n"
19-
<< BOOST_LIB_VERSION << "\n";
18+
std::cout << BOOST_VERSION << "\n" << BOOST_LIB_VERSION << "\n";
2019

2120
/* boost/config.hpp */
22-
std::cout << BOOST_PLATFORM << "\n"
23-
<< BOOST_COMPILER << "\n"
24-
<< BOOST_STDLIB << "\n";
21+
std::cout << BOOST_PLATFORM << "\n" << BOOST_COMPILER << "\n" << BOOST_STDLIB << "\n";
2522

2623
/*std::cin.get();*/
2724
system("pause");

Boost/LambdaExample/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ project("lambda")
55
set(CMAKE_CXX_STANDARD 23)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77

8+
# Find Boost via vcpkg
9+
find_package(Boost REQUIRED)
10+
811
add_executable(lambda "lambda.cpp")
912

10-
target_include_directories(lambda PUBLIC "C:\\boost\\boost_1_82_0")
13+
# Explicitly add Boost include directories if needed
14+
target_include_directories(lambda PUBLIC ${Boost_INCLUDE_DIRS})
15+
16+
target_link_libraries(lambda PUBLIC ${Boost_LIBRARIES})

Boost/MultiArray/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
# vcpkg install boost-multi-array
2+
13
cmake_minimum_required(VERSION 3.20)
24

35
project("multi_array" LANGUAGES CXX)
46

57
set(CMAKE_CXX_STANDARD 23)
68
set(CMAKE_CXX_STANDARD_REQUIRED ON)
79

10+
# Find Boost via vcpkg
11+
find_package(Boost REQUIRED COMPONENTS multi_array)
12+
813
add_executable(multi_array "multi_array.cpp")
914

10-
target_include_directories(multi_array PUBLIC "C:\\boost\\boost_1_82_0")
15+
# Explicitly add Boost include directories if needed
16+
target_include_directories(multi_array PUBLIC ${Boost_INCLUDE_DIRS})
17+
18+
target_link_libraries(multi_array PRIVATE Boost::multi_array)

Boost/TimeDate/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1+
# vcpkg install boost-timer
2+
13
cmake_minimum_required(VERSION 3.20)
24

35
project("time_date")
46

57
set(CMAKE_CXX_STANDARD 23)
68
set(CMAKE_CXX_STANDARD_REQUIRED ON)
79

10+
# Find Boost via vcpkg
11+
find_package(Boost REQUIRED COMPONENTS timer)
12+
813
# Adding multiple executable to the project
914
# Right-click on each item to set as start-up project
1015
add_executable(progress_timer "progress_timer.cpp")
1116
add_executable(timer "timer.cpp")
1217

13-
# Adding additional include directories
14-
target_include_directories(progress_timer PUBLIC "C:\\boost\\boost_1_82_0")
15-
target_include_directories(timer PUBLIC "C:\\boost\\boost_1_82_0")
18+
# Explicitly add Boost include directories if needed
19+
target_include_directories(progress_timer PUBLIC ${Boost_INCLUDE_DIRS})
20+
target_include_directories(timer PUBLIC ${Boost_INCLUDE_DIRS})
21+
22+
target_link_libraries(progress_timer PRIVATE Boost::timer)
23+
target_link_libraries(timer PRIVATE Boost::timer)

Boost/TimeDate/progress_timer.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// clang-format off
12
/*****************************************************************//**
23
* \file progress_timer.cpp
34
* \brief boost_progress inherits from boost::timer
@@ -14,29 +15,15 @@
1415
* \author Xuhua Huang
1516
* \date September 19, 2022
1617
*********************************************************************/
18+
// clang-format on
1719

20+
#include <boost/timer/progress_display.hpp>
1821
#include <iostream>
1922
#include <sstream>
20-
#include <boost/progress.hpp>
2123

22-
auto main(void) -> int {
23-
/* boost::progress_timer */
24-
boost::progress_timer t;
25-
std::cout << t.elapsed() << "\n";
24+
int main(void) {
25+
boost::timer::progress_display prog{100};
26+
std::cout << prog.count() << "\n";
2627

27-
/**
28-
* The destructor of the class boost:progress_timer also allows
29-
* outputting to other output stream than std::cout (default option).
30-
* For example, std::ofstream, std::ostringstream.
31-
* Or we can use cout.rdbuf() to redirect the buffer output.
32-
*/
33-
std::stringstream ss;
34-
{
35-
boost::progress_timer t(ss);
36-
}
37-
std::cout << ss.str() << "\n";
38-
39-
system("pause");
40-
return EXIT_SUCCESS;
28+
return 0;
4129
}
42-

Concept/usecase_haspushback.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@
1313

1414
namespace {
1515

16-
}
16+
void coll_append(HasPushBack auto& coll, const auto& val) {
17+
coll.push_back(val);
18+
return;
19+
}
1720

18-
/* Ad-hoc style HasInsert concept implementation */
19-
template<typename Coll>
20-
concept HasInsert = requires (Coll & c, typename Coll::value_type val) {
21-
c.insert(val);
22-
};
21+
/* Ad-hoc style HasInsert concept implementation */
22+
template <typename Coll>
23+
concept HasInsert = requires (Coll& c, typename Coll::value_type val) { c.insert(val); };
2324

24-
void coll_append(::HasInsert auto& coll, const auto& val) {
25-
coll.insert(val);
26-
return;
27-
}
25+
void coll_append(::HasInsert auto& coll, const auto& val) {
26+
coll.insert(val);
27+
return;
2828
}
29-
auto main(void) -> int {
30-
std::vector<int> v{ 0, 1 };
31-
std::set<int> s{ 0, 1 };
29+
} // namespace
30+
int main(void) {
31+
std::vector<int> v{0, 1};
32+
std::set<int> s{0, 1};
3233

3334
::coll_append(v, 2); // calls coll_append(HasPushBack ...) variant
3435
::coll_append(s, 2); // calls coll_append(HasInsert ...) variant

CppProperties.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
"includePath": [
99
"${env.INCLUDE}",
1010
"${workspaceRoot}\\**",
11-
"C:\\boost\\boost_1_81_0\\**",
12-
"C:\\boost\\boost_1_81_0\\boost\\**",
13-
"C:\\boost\\boost_1_82_0\\**",
14-
"C:\\boost\\boost_1_82_0\\boost\\**",
15-
"C:\\boost\\ut\\include"
11+
"D:\\include\\boost_1_82_0\\**",
12+
"D:\\include\\boost_1_82_0\\boost\\**",
13+
"D:\\include\\ut\\include"
1614
],
1715
"defines": [
1816
"WIN32",

GoogleTest/CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
cmake_minimum_required(VERSION 3.20)
22

3-
project(GoogleTest)
3+
project("google_test" LANGUAGES C CXX)
44

55
# GoogleTest requires at least C++14
66
set(CMAKE_CXX_STANDARD 17)
77
set(CMAKE_CXX_STANDARD_REQUIRED ON)
88

9+
cmake_policy(SET CMP0135 NEW)
910
include(FetchContent)
1011
FetchContent_Declare(
1112
googletest
12-
URL https://github.com/google/googletest/archive/refs/tags/v1.13.0.zip
13+
URL https://github.com/google/googletest/archive/refs/tags/v1.16.0.zip
14+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
1315
)
1416

1517
# For Windows: Prevent overriding the parent project's compiler/linker settings
@@ -24,26 +26,30 @@ enable_testing()
2426
# GoogleTest project setup test
2527
add_executable(
2628
hello_test
27-
hello_test.cpp
29+
"hello_test.cpp"
2830
)
31+
add_test(NAME hello_test COMMAND hello_test)
2932

3033
# GoogleTest for basic implementation of Queue
3134
add_executable(
3235
queue_test
33-
queue_test.cpp
36+
"queue_test.cpp"
3437
)
38+
add_test(NAME queue_test COMMAND queue_test)
3539

3640
# GoogleTest for basic implementation of Factorial function
3741
add_executable(
3842
factorial_test
39-
factorial_test.cpp
43+
"factorial_test.cpp"
4044
)
45+
add_test(NAME factorial_test COMMAND factorial_test)
4146

4247
# GoogleTest for basic implementation of BankAccount
4348
add_executable(
4449
bank_account_test
45-
bank_account_test.cpp
50+
"bank_account_test.cpp"
4651
)
52+
add_test(NAME bank_account_test COMMAND bank_account_test)
4753

4854
target_link_libraries(
4955
hello_test

Helper/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@ struct integral_constant {
3939
}
4040
};
4141
```
42+
43+
## `gtest_lambda_derivative.lib`
44+
To see the content of such library files, consider using `dumpbin` from `MSVC` toolchain.
45+
46+
For example:
47+
```ps
48+
cd Helper
49+
cmake . -Bbuild
50+
cd Helper\build\Debug
51+
dumpbin /EXPORTS /out:gtest_lambda_derivative.txt gtest_lambda_derivative.lib
52+
```

LeetCodePlayground/BinarySearch/find_peak_element.hpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
// https://leetcode.com/problems/find-peak-element/
22

3-
class Solution
4-
{
3+
class Solution {
54
public:
6-
int findPeakElement(vector<int>& nums)
7-
{
5+
int findPeakElement(vector<int>& nums) {
86
int s = 0;
97
int e = nums.size() - 1;
108
int mid = 0;
119

12-
while (s < e)
13-
{
10+
while (s < e) {
1411
mid = s + (e - s) / 2;
15-
if (nums[mid] < nums[mid + 1])
16-
{
12+
if (nums[mid] < nums[mid + 1]) {
1713
s = mid + 1;
18-
}
19-
else
20-
{
14+
} else {
2115
e = mid;
2216
}
2317
}

LinkedList/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ set(C_STANDARD 17)
66
set(C_STANDARD_REQUIRED ON)
77

88
add_executable(linked_list "linked_list.c")
9+
add_executable(sort_linked_list_cli "sort_linked_list_cli.c")

Miscellaneous/count_digits.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
size_t numDigits(int number);
1313

14-
int main(void)
15-
{
14+
int main(void) {
1615
for (int i = 0; i <= 100; ++i) {
1716
std::cout << "The number of digit of number " << i << " is: " << numDigits(i) << "\n";
1817
}
@@ -21,8 +20,7 @@ int main(void)
2120
return 0;
2221
}
2322

24-
size_t numDigits(int number)
25-
{
23+
size_t numDigits(int number) {
2624
std::size_t digitsCount = 1;
2725
while ((number /= 10) != 0) {
2826
++digitsCount;

Projects/SFML/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ cmake_minimum_required(VERSION 3.20)
22

33
project("sfml_cmake" LANGUAGES CXX)
44

5+
cmake_policy(SET CMP0135 NEW)
6+
57
include(FetchContent)
68
FetchContent_Declare(SFML
79
GIT_REPOSITORY https://github.com/SFML/SFML.git
8-
GIT_TAG 2.6.x)
10+
GIT_TAG 2.6.x
11+
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
12+
)
913
FetchContent_MakeAvailable(SFML)
1014

1115
add_executable(sfml_cmake "Example/main.cpp")

0 commit comments

Comments
 (0)