|
1 | 1 | # Updated 2025.05 to 3.10 since compatibility with CMake < 3.10 will be removed from a future version of CMake. |
2 | 2 | cmake_minimum_required(VERSION 3.10) |
| 3 | + |
| 4 | +# Added in case users want to build this library as STATIC |
3 | 5 | # https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html |
4 | 6 | option(BUILD_SHARED_LIBS "Build using shared libraries" ON) |
5 | 7 |
|
6 | 8 | if(WIN32) |
7 | 9 | set(CMAKE_TOOLCHAIN_FILE C:/vcpkg/scripts/buildsystems/vcpkg.cmake) |
| 10 | + # A must so that we don't need to manually export each public part of the library |
8 | 11 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) |
9 | 12 | endif() |
10 | 13 |
|
11 | 14 | project(dqrobotics) |
12 | | -set (CMAKE_CXX_STANDARD 11) |
| 15 | + |
| 16 | +find_package(Eigen3 REQUIRED) |
13 | 17 |
|
14 | 18 | # As of 2025.05, Not using GLOB_RECURSE as it's explicitly discouraged. |
15 | 19 | # https://stackoverflow.com/questions/3201154/automatically-add-all-files-in-a-folder-to-a-target-using-cmake |
@@ -50,57 +54,49 @@ add_library(dqrobotics |
50 | 54 | src/robots/FrankaEmikaPandaRobot.cpp |
51 | 55 | ) |
52 | 56 |
|
53 | | -target_include_directories( |
| 57 | +set_property(TARGET dqrobotics PROPERTY CXX_STANDARD 17) |
| 58 | + |
| 59 | +target_include_directories(dqrobotics PUBLIC |
54 | 60 | include |
55 | 61 | ) |
56 | 62 |
|
57 | | -if(UNIX AND NOT APPLE) |
58 | | - find_package(Eigen3 REQUIRED) |
59 | | - include_directories(${EIGEN3_INCLUDE_DIR}) |
60 | | - add_compile_options(-Werror=return-type -Wall -Wextra -Wmissing-declarations -Wredundant-decls -Woverloaded-virtual) |
61 | | -endif() |
62 | | - |
63 | | -if(APPLE) |
64 | | - include_directories( |
65 | | - /usr/local/include/ |
66 | | - /usr/local/include/eigen3 |
67 | | - # Most recent versions of brew install here |
68 | | - /opt/homebrew/include |
69 | | - /opt/homebrew/include/eigen3) |
70 | | - add_compile_options(-Werror=return-type -Wall -Wextra -Wmissing-declarations -Wredundant-decls -Woverloaded-virtual) |
| 63 | +if(UNIX) |
| 64 | + # WIN32 does not accept these flags |
| 65 | + add_compile_options(-Werror=return-type -Wall -Wextra -Wmissing-declarations -Wredundant-decls -Woverloaded-virtual -fPIC) |
71 | 66 | endif() |
72 | 67 |
|
73 | 68 | if(WIN32) |
74 | | - add_definitions(-D_USE_MATH_DEFINES) |
75 | | - find_package(Eigen3 CONFIG REQUIRED) |
76 | | - include_directories(${EIGEN3_INCLUDE_DIR}) |
| 69 | + # https://learn.microsoft.com/en-us/cpp/c-runtime-library/math-constants?view=msvc-170 |
| 70 | + target_compile_definitions(dqrobotics PUBLIC |
| 71 | + _USE_MATH_DEFINES |
| 72 | + ) |
77 | 73 | endif() |
78 | 74 |
|
| 75 | +target_link_libraries(dqrobotics PUBLIC |
| 76 | + Eigen3::Eigen |
| 77 | +) |
| 78 | + |
79 | 79 | set_target_properties(dqrobotics |
80 | 80 | PROPERTIES PUBLIC_HEADER |
81 | 81 | include/dqrobotics/DQ.h |
82 | 82 | ) |
83 | 83 |
|
84 | 84 | install(TARGETS dqrobotics |
85 | | -# https://stackoverflow.com/questions/21592361/cmake-install-is-not-installing-libraries-on-windows |
| 85 | + # https://stackoverflow.com/questions/21592361/cmake-install-is-not-installing-libraries-on-windows |
86 | 86 | RUNTIME DESTINATION "bin" |
87 | 87 | LIBRARY DESTINATION "lib" |
88 | 88 | ARCHIVE DESTINATION "lib" |
89 | 89 | PUBLIC_HEADER DESTINATION "include/dqrobotics" |
90 | | - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) |
91 | | - |
92 | | -################################################################ |
93 | | -# INSTALL HEADERS IN SUBFOLDERS |
94 | | -################################################################ |
| 90 | + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ |
| 91 | +) |
95 | 92 |
|
96 | 93 | install(DIRECTORY |
97 | 94 | include/ |
98 | | - DESTINATION "include") |
99 | | - |
100 | | -################################################################ |
101 | | -# INSTALL SOURCE FILES (So that the debugger can find them) |
102 | | -################################################################ |
| 95 | + DESTINATION "include" |
| 96 | +) |
103 | 97 |
|
| 98 | +# Install source files so that the debugger can find them |
104 | 99 | install(DIRECTORY |
105 | 100 | src/ |
106 | | - DESTINATION "src/dqrobotics") |
| 101 | + DESTINATION "src/dqrobotics" |
| 102 | +) |
0 commit comments