Skip to content

Commit b7994c4

Browse files
committed
Add use of compile time option
1 parent 6c511c2 commit b7994c4

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

tests/myproj/CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.16...3.21)
1+
cmake_minimum_required(VERSION 3.16...3.31)
22

33
# set a default CXX standard used by the external tools like clang-tidy, cppcheck, etc.
44
# You can later set fine-grained standards for each target using `target_compile_features`
@@ -49,6 +49,17 @@ if(NOT MSVC)
4949
#message(STATUS "Detect Linker: ${LINKER}")
5050
endif()
5151

52+
set(ENABLE_INTERPROCEDURAL_OPTIMIZATION "ENABLE_INTERPROCEDURAL_OPTIMIZATION")
53+
if(APPLE)
54+
detect_macos_version(apple_version)
55+
if(apple_version VERSION_GREATER_EQUAL 13)
56+
# workaround for linkage error as described in https://github.com/Homebrew/homebrew-core/issues/145991
57+
# although fixed, this problem still exists in github actions
58+
#XXX add_link_options(-Wl,-ld_classic)
59+
set(ENABLE_INTERPROCEDURAL_OPTIMIZATION "")
60+
endif()
61+
endif()
62+
5263
# Initialize project_options
5364
# uncomment the options to enable them
5465
project_options(
@@ -60,7 +71,7 @@ project_options(
6071
ENABLE_CLANG_TIDY
6172
# ENABLE_INCLUDE_WHAT_YOU_USE
6273
# ENABLE_GCC_ANALYZER
63-
ENABLE_COVERAGE
74+
#XXX ENABLE_COVERAGE
6475
# ENABLE_PCH
6576
# PCH_HEADERS
6677
# ${PCH_HEADERS}
@@ -124,6 +135,13 @@ target_include_system_directories(
124135
target_link_libraries(lib INTERFACE myproj_project_options myproj_project_warnings)
125136
target_link_system_libraries(lib INTERFACE fmt::fmt Eigen3::Eigen)
126137

138+
option(LIB_WITH_EIGEN "Enable Eigen" OFF)
139+
if(LIB_WITH_EIGEN)
140+
target_compile_definitions(lib INTERFACE HAS_EIGEN)
141+
endif()
142+
143+
target_link_libraries(main PRIVATE lib)
144+
127145
# Library
128146
add_library(lib2 "./src/mylib2/lib.cpp")
129147
set(lib2_INCLUDE_DIR2 "include")
@@ -178,3 +196,6 @@ package_project(
178196
)
179197

180198
package_project(NAME myproj_main TARGETS main)
199+
200+
set(CPACK_GENERATOR TGZ)
201+
include(CPack)

tests/myproj/include/mylib/lib.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#pragma once
22

33
// test external pac
4-
#include <Eigen/Dense>
4+
#ifdef HAS_EIGEN
5+
# include <Eigen/Dense>
6+
#else
7+
# include <vector>
8+
#endif
9+
510
#include <fmt/core.h>
611
#include <fmt/ranges.h>
712

@@ -17,14 +22,19 @@
1722
#include <cstdint>
1823
#include <cstring>
1924

20-
int some_fun() {
21-
fmt::print("Hello from fmt{}", "!");
25+
int some_fun()
26+
{
27+
fmt::print("Hello from lib{}\n", "!");
2228

29+
#ifdef HAS_EIGEN
2330
// populate an Eigen vector with the values
2431
auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);
32+
#else
33+
auto eigen_vec = std::vector<int>() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
34+
#endif
2535

2636
// print the vector
27-
fmt::print("[{}]", fmt::join(eigen_vec, ", "));
37+
fmt::print("[{}]\n", fmt::join(eigen_vec, ", "));
2838

2939
return 0;
3040
}

tests/myproj/src/main/main.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
#include "mylib/lib.hpp"
2+
13
// test external pac
2-
#include <Eigen/Dense>
34
#include <fmt/core.h>
45
#include <fmt/ranges.h>
56

7+
#ifdef HAS_EIGEN
8+
# include <Eigen/Dense>
9+
#endif
10+
611
// test std libraries
712
#include <iostream>
813
#include <string>
914
#include <string_view>
15+
#include <vector>
1016

1117
// test c libraries
1218
#include <cassert>
@@ -15,21 +21,22 @@
1521
#include <cstdint>
1622
#include <cstring>
1723

18-
int main() {
19-
fmt::print("Hello from fmt{}", "!");
24+
int main()
25+
{
26+
fmt::print("Hello from main{}\n", "!");
2027

21-
Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
22-
fmt::print("[{}]", fmt::join(eigen_vec, ", "));
28+
auto eigen_vec = std::vector<int>() = {1, 2, 3};
29+
fmt::print("[{}]\n", fmt::join(eigen_vec, ", "));
2330

24-
#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails
31+
#if defined(HAS_EIGEN) && !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails
2532
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
26-
fmt::print("[{}]", fmt::join(eigen_vec2, ", "));
33+
fmt::print("[{}]\n", fmt::join(eigen_vec2, ", "));
2734
#endif
2835

2936
// trigger address sanitizer
3037
// int *p = nullptr;
3138
// *p = 1;
3239

3340
// trigger compiler warnings, clang-tidy, and cppcheck
34-
int a;
41+
int a = some_fun();
3542
}

0 commit comments

Comments
 (0)