2
2
dart_find_package(NLOPT)
3
3
dart_check_optional_package(NLOPT "dart-optimizer-nlopt" "nlopt" "2.4.1" )
4
4
5
+ if (NOT NLOPT_VERSION)
6
+ # If version is not found, we just assume 2.9.0
7
+ set (NLOPT_VERSION "2.9.0" )
8
+ endif ()
9
+
10
+ # Attempt to parse version components
11
+ string (REGEX REPLACE "^([0-9]+)\\ .([0-9]+)\\ .([0-9]+)$" "\\ 1" NLOPT_MAJOR_VERSION "${NLOPT_VERSION} " )
12
+ string (REGEX REPLACE "^([0-9]+)\\ .([0-9]+)\\ .([0-9]+)$" "\\ 2" NLOPT_MINOR_VERSION "${NLOPT_VERSION} " )
13
+ string (REGEX REPLACE "^([0-9]+)\\ .([0-9]+)\\ .([0-9]+)$" "\\ 3" NLOPT_PATCH_VERSION "${NLOPT_VERSION} " )
14
+
15
+ # Check if parsing succeeded
16
+ if (NOT (NLOPT_MAJOR_VERSION MATCHES "^[0-9]+$" AND
17
+ NLOPT_MINOR_VERSION MATCHES "^[0-9]+$" AND
18
+ NLOPT_PATCH_VERSION MATCHES "^[0-9]+$" ))
19
+ message (WARNING "Failed to parse NLOPT_VERSION '${NLOPT_VERSION} '. Using default values (2, 9, 0) for version components." )
20
+ set (NLOPT_MAJOR_VERSION "2" )
21
+ set (NLOPT_MINOR_VERSION "9" )
22
+ set (NLOPT_PATCH_VERSION "0" )
23
+ endif ()
24
+
5
25
# Search all header and source files
6
26
file (GLOB hdrs "*.hpp" )
7
27
file (GLOB srcs "*.cpp" )
@@ -13,6 +33,12 @@ set(component_name optimizer-nlopt)
13
33
# Add target
14
34
dart_add_library(${target_name} ${hdrs} ${srcs} )
15
35
target_link_libraries (${target_name} PUBLIC dart NLOPT::nlopt)
36
+ target_compile_definitions (${target_name}
37
+ PUBLIC
38
+ -DNLOPT_MAJOR_VERSION=${NLOPT_MAJOR_VERSION}
39
+ -DNLOPT_MINOR_VERSION=${NLOPT_MINOR_VERSION}
40
+ -DNLOPT_PATCH_VERSION=${NLOPT_PATCH_VERSION}
41
+ )
16
42
17
43
# Component
18
44
add_component(${PROJECT_NAME} ${component_name} )
0 commit comments