Skip to content

Commit f74150a

Browse files
committed
improve cmake: fix required min version to 3.14 to use FetchContent, more robust detection of pugixml, PIC for static builds
1 parent 14dde04 commit f74150a

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
cmake_minimum_required(VERSION 3.13)
1+
cmake_minimum_required(VERSION 3.14)
22

33
project(libOpenDrive VERSION 0.6.0 DESCRIPTION ".xodr library")
44

5-
include(CTest)
65
include(FetchContent)
76
include(GNUInstallDirs)
87

8+
option(OPENDRIVE_BUILD_TESTS "Build OpenDrive tests" OFF)
9+
910
find_package(pugixml QUIET CONFIG)
10-
if(NOT pugixml_FOUND)
11-
FetchContent_Declare(
12-
pugixml
13-
GIT_REPOSITORY https://github.com/zeux/pugixml.git
14-
GIT_TAG v1.14
15-
)
16-
FetchContent_MakeAvailable(pugixml)
17-
add_library(pugixml::pugixml ALIAS pugixml)
11+
if(NOT TARGET pugixml::pugixml)
12+
if(TARGET pugixml)
13+
add_library(pugixml::pugixml ALIAS pugixml)
14+
else()
15+
FetchContent_Declare(
16+
pugixml
17+
GIT_REPOSITORY https://github.com/zeux/pugixml.git
18+
GIT_TAG v1.14
19+
)
20+
FetchContent_MakeAvailable(pugixml)
21+
add_library(pugixml::pugixml ALIAS pugixml)
22+
endif()
1823
endif()
1924

2025
set(SOURCES
@@ -40,9 +45,11 @@ set(SOURCES
4045
)
4146

4247
add_library(OpenDrive ${SOURCES})
48+
add_library(OpenDrive::OpenDrive ALIAS OpenDrive)
4349
set_target_properties(OpenDrive PROPERTIES
4450
CXX_STANDARD 17
4551
CXX_STANDARD_REQUIRED ON
52+
POSITION_INDEPENDENT_CODE ON
4653
)
4754
if(MSVC)
4855
target_compile_options(OpenDrive PRIVATE /W3 /EHsc)
@@ -60,6 +67,7 @@ target_include_directories(
6067
)
6168

6269
if(OPENDRIVE_BUILD_TESTS)
70+
include(CTest)
6371
FetchContent_Declare(
6472
Catch2
6573
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
@@ -75,6 +83,7 @@ endif()
7583

7684
install(
7785
TARGETS OpenDrive
86+
EXPORT OpenDriveTargets
7887
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
7988
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
8089
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

0 commit comments

Comments
 (0)