Skip to content

Commit

Permalink
chore: define ProjectOptions_SRC_DIR in all cmake files
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored and FeignClaims committed Feb 9, 2024
1 parent 1ef80b1 commit caf8071
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 88 deletions.
2 changes: 2 additions & 0 deletions src/Common.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include_guard()

set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")

# This function sets ProjectOptions_SRC_DIR using the current lists path
macro(set_project_options_src_dir)
get_directory_property(LISTFILE_STACK LISTFILE_STACK)
Expand Down
2 changes: 2 additions & 0 deletions src/CrossCompiler.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include_guard()

set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")

#[[.rst:

``enable_cross_compiler``
Expand Down
2 changes: 2 additions & 0 deletions src/DetectCompiler.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include_guard()

set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")

# includes a separate CMakeLists.txt file to detect the CXX/C compilers before project is called
# Using a separate file ensures that the current scope is not contaminated by the variable
macro(detect_compiler)
Expand Down
7 changes: 5 additions & 2 deletions src/Doxygen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ function(enable_doxygen DOXYGEN_THEME)

# find doxygen and dot if available
find_package(Doxygen OPTIONAL_COMPONENTS dot)
if (NOT Doxygen_FOUND)
message(WARNING "Doxygen not found, install doxygen and try again. Documentation will not be generated.")
if(NOT Doxygen_FOUND)
message(
WARNING
"Doxygen not found, install doxygen and try again. Documentation will not be generated."
)
return()
endif()

Expand Down
46 changes: 23 additions & 23 deletions src/Index.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
endif()

# only useable here
set(ProjectOptions_SRC_DIR ${CMAKE_CURRENT_LIST_DIR})
set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")

# include the files to allow calling individual functions (including the files does not run any code.)
include("${CMAKE_CURRENT_LIST_DIR}/Common.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Utilities.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Git.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/SystemLink.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Cuda.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/PackageProject.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Optimization.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Cache.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Linker.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/CompilerWarnings.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Tests.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Sanitizers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Doxygen.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/StaticAnalyzers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/VCEnvironment.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/MinGW.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/DetectCompiler.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/CrossCompiler.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/DynamicProjectOptions.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Hardening.cmake")
include("${ProjectOptions_SRC_DIR}/Common.cmake")
include("${ProjectOptions_SRC_DIR}/Utilities.cmake")
include("${ProjectOptions_SRC_DIR}/Git.cmake")
include("${ProjectOptions_SRC_DIR}/SystemLink.cmake")
include("${ProjectOptions_SRC_DIR}/Cuda.cmake")
include("${ProjectOptions_SRC_DIR}/PackageProject.cmake")
include("${ProjectOptions_SRC_DIR}/Optimization.cmake")
include("${ProjectOptions_SRC_DIR}/Cache.cmake")
include("${ProjectOptions_SRC_DIR}/Linker.cmake")
include("${ProjectOptions_SRC_DIR}/CompilerWarnings.cmake")
include("${ProjectOptions_SRC_DIR}/Tests.cmake")
include("${ProjectOptions_SRC_DIR}/Sanitizers.cmake")
include("${ProjectOptions_SRC_DIR}/Doxygen.cmake")
include("${ProjectOptions_SRC_DIR}/StaticAnalyzers.cmake")
include("${ProjectOptions_SRC_DIR}/VCEnvironment.cmake")
include("${ProjectOptions_SRC_DIR}/MinGW.cmake")
include("${ProjectOptions_SRC_DIR}/DetectCompiler.cmake")
include("${ProjectOptions_SRC_DIR}/CrossCompiler.cmake")
include("${ProjectOptions_SRC_DIR}/DynamicProjectOptions.cmake")
include("${ProjectOptions_SRC_DIR}/Hardening.cmake")

# Include msvc toolchain on windows if the generator is not visual studio. Should be called before run_vcpkg and run_conan to be effective
if("${CMAKE_TOOLCHAIN_FILE}" STREQUAL "")
Expand All @@ -41,8 +41,8 @@ else()
message(STATUS "project_options: skipping msvc_toolchain as CMAKE_TOOLCHAIN_FILE is set")
endif()

include("${CMAKE_CURRENT_LIST_DIR}/Conan.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/Vcpkg.cmake")
include("${ProjectOptions_SRC_DIR}/Conan.cmake")
include("${ProjectOptions_SRC_DIR}/Vcpkg.cmake")

#[[.rst:

Expand Down
2 changes: 2 additions & 0 deletions src/MinGW.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include_guard()

set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")

# detect mingw
function(is_mingw value)
if(USE_CROSSCOMPILER_MINGW)
Expand Down
6 changes: 3 additions & 3 deletions src/VCEnvironment.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include_guard()

include("${CMAKE_CURRENT_LIST_DIR}/Utilities.cmake")
set(ProjectOptions_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")
include("${ProjectOptions_SRC_DIR}/Utilities.cmake")

# detect if the compiler is msvc
function(is_msvc value)
Expand Down Expand Up @@ -58,8 +59,7 @@ macro(msvc_toolchain)
message(STATUS "Using Windows Windows toolchain")
include(FetchContent)
FetchContent_Declare(
_msvc_toolchain
GIT_REPOSITORY "https://github.com/MarkSchofield/WindowsToolchain.git"
_msvc_toolchain GIT_REPOSITORY "https://github.com/MarkSchofield/WindowsToolchain.git"
GIT_TAG "17c6d4ff6531ee268b9a22a8bcfbb3809e970e4e"
)
FetchContent_MakeAvailable(_msvc_toolchain)
Expand Down
4 changes: 2 additions & 2 deletions tests/emscripten/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#endif

int main() {
printf("hello, world!\n");
return 0;
printf("hello, world!\n");
return 0;
}
4 changes: 2 additions & 2 deletions tests/install/src/another_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#include <mylib2/lib.hpp>

int main() {
some_fun2();
return some_fun2();
some_fun2();
return some_fun2();
}
4 changes: 2 additions & 2 deletions tests/minimal/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fmt/core.h>

int main() {
fmt::print("Hello World!");
return 0;
fmt::print("Hello World!");
return 0;
}
12 changes: 6 additions & 6 deletions tests/myproj/include/mylib/lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#include <cstring>

int some_fun() {
fmt::print("Hello from fmt{}", "!");
fmt::print("Hello from fmt{}", "!");

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

// print the vector
fmt::print("[{}]", fmt::join(eigen_vec, ", "));
// print the vector
fmt::print("[{}]", fmt::join(eigen_vec, ", "));

return 0;
return 0;
}
18 changes: 9 additions & 9 deletions tests/myproj/libs/mythirdpartylib/include/Foo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
namespace mythirdpartylib {

class MYTHIRDPARTYLIB_EXPORT Foo {
public:
Foo() = default;
public:
Foo() = default;

/*implicit*/ Foo(int a) : m_a(a) {}
/*implicit*/ Foo(int a) : m_a(a) {}

int a() const { return m_a; }
int a() const { return m_a; }

void update(bool b, bool c, bool d);
void bad(std::vector<std::string> &v);
void update(bool b, bool c, bool d);
void bad(std::vector<std::string> &v);

private:
int m_a;
private:
int m_a;
};

} // namespace mythirdpartylib
}// namespace mythirdpartylib
20 changes: 10 additions & 10 deletions tests/myproj/libs/mythirdpartylib/src/Foo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
namespace mythirdpartylib {

void Foo::update(bool b, bool c, bool d) {
int e = b + d;
m_a = e;
int e = b + d;
m_a = e;
}

void Foo::bad(std::vector<std::string> &v) {
std::string val = "hello";
int index = -1; // bad, plus should use gsl::index
for (int i = 0; i < v.size(); ++i) {
if (v[i] == val) {
index = i;
break;
std::string val = "hello";
int index = -1;// bad, plus should use gsl::index
for (int i = 0; i < v.size(); ++i) {
if (v[i] == val) {
index = i;
break;
}
}
}
}

static Foo foo(5);
static Foo bar = 42;

} // namespace mythirdpartylib
}// namespace mythirdpartylib
22 changes: 11 additions & 11 deletions tests/myproj/src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
#include <cstring>

Check warning on line 16 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (windows-2022, llvm, true, true)

included header cstring is not used directly [misc-include-cleaner]

Check warning on line 16 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (windows-2022, gcc, true, true)

included header cstring is not used directly [misc-include-cleaner]

int main() {
fmt::print("Hello from fmt{}", "!");
fmt::print("Hello from fmt{}", "!");

Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("[{}]", fmt::join(eigen_vec, ", "));
Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("[{}]", fmt::join(eigen_vec, ", "));

#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("[{}]", fmt::join(eigen_vec2, ", "));
#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);

Check warning on line 25 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]

Check warning on line 25 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]

Check warning on line 25 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]

Check warning on line 25 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
fmt::print("[{}]", fmt::join(eigen_vec2, ", "));
#endif

// trigger address sanitizer
// int *p = nullptr;
// *p = 1;
// trigger address sanitizer
// int *p = nullptr;
// *p = 1;

// trigger compiler warnings, clang-tidy, and cppcheck
int a;
// trigger compiler warnings, clang-tidy, and cppcheck
int a;

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

unused variable 'a' [clang-diagnostic-unused-variable]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

variable 'a' is not initialized [cppcoreguidelines-init-variables]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

variable name 'a' is too short, expected at least 3 characters [readability-identifier-length]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

Unused variable: a [unusedVariable]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

unused variable 'a' [-Wunused-variable]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

unused variable 'a' [clang-diagnostic-unused-variable]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

variable 'a' is not initialized [cppcoreguidelines-init-variables]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

unused variable 'a' [clang-diagnostic-unused-variable]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

variable 'a' is not initialized [cppcoreguidelines-init-variables]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

variable name 'a' is too short, expected at least 3 characters [readability-identifier-length]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

Unused variable: a [unusedVariable]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

unused variable 'a' [-Wunused-variable]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

unused variable 'a' [clang-diagnostic-unused-variable]

Check warning on line 34 in tests/myproj/src/main/main.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

variable 'a' is not initialized [cppcoreguidelines-init-variables]
}
14 changes: 7 additions & 7 deletions tests/myproj/src/mylib2/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
#include <cstring>

Check warning on line 16 in tests/myproj/src/mylib2/lib.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-22.04, llvm, true, true)

included header cstring is not used directly [misc-include-cleaner]

Check warning on line 16 in tests/myproj/src/mylib2/lib.cpp

View workflow job for this annotation

GitHub Actions / Test (ubuntu-22.04, gcc, true, true)

included header cstring is not used directly [misc-include-cleaner]

int some_fun2() {
fmt::print("Hello from fmt{}", "!");
fmt::print("Hello from fmt{}", "!");

Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("[{}]", fmt::join(eigen_vec, ", "));
Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("[{}]", fmt::join(eigen_vec, ", "));

#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("[{}]", fmt::join(eigen_vec2, ", "));
#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);

Check warning on line 25 in tests/myproj/src/mylib2/lib.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-12, llvm, true, true)

10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]

Check warning on line 25 in tests/myproj/src/mylib2/lib.cpp

View workflow job for this annotation

GitHub Actions / Test (macos-11, gcc, true, true)

10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
fmt::print("[{}]", fmt::join(eigen_vec2, ", "));
#endif

return 0;
return 0;
}
10 changes: 5 additions & 5 deletions tests/rpi3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ char uart_getc() { return 'a'; }
void uart_puts(char *s) {}

void main() {
uart_init();
uart_init();

uart_puts("Hello World!\n");
uart_puts("Hello World!\n");

while (1) {
uart_send(uart_getc());
}
while (1) {
uart_send(uart_getc());
}
}
4 changes: 2 additions & 2 deletions tests/rpi3/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
std::cout << "Hello World!";
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi4-vcpkg/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fmt/core.h>

int main() {
fmt::print("Hello World!");
return 0;
fmt::print("Hello World!");
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi4/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
std::cout << "Hello World!";
return 0;
}

0 comments on commit caf8071

Please sign in to comment.