Skip to content

Commit 2a3319d

Browse files
committed
Export cmake config and add option to build unit tests
1 parent 468ee51 commit 2a3319d

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

Diff for: CMakeLists.txt

+44-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
cmake_minimum_required(VERSION 3.9)
12
cmake_policy(SET CMP0048 NEW)
3+
24
project(fast_double_parser LANGUAGES CXX VERSION 0.0.0.0)
3-
cmake_minimum_required(VERSION 3.9)
45
set(CMAKE_CXX_STANDARD 11)
56
set(CMAKE_CXX_STANDARD_REQUIRED ON)
67
if (NOT CMAKE_BUILD_TYPE)
@@ -18,31 +19,53 @@ set(rebogus_src tests/bogus.cpp)
1819
set(benchmark_src benchmarks/benchmark.cpp)
1920

2021

21-
add_library(fast_double_parser INTERFACE)
22-
target_include_directories(fast_double_parser INTERFACE include/)
23-
22+
add_library(fast_double_parser INTERFACE ${headers})
23+
target_include_directories(fast_double_parser
24+
INTERFACE
25+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
26+
$<INSTALL_INTERFACE:include>
27+
)
28+
29+
include(GNUInstallDirs)
30+
install(FILES ${headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
31+
install(TARGETS fast_double_parser EXPORT fast_double_parser-targets)
32+
install(
33+
EXPORT fast_double_parser-targets
34+
DESTINATION "share/fast_double_parser"
35+
NAMESPACE fast_double_parser::
36+
)
37+
38+
include(CMakePackageConfigHelpers)
39+
configure_package_config_file(
40+
"${CMAKE_CURRENT_SOURCE_DIR}/fast_double_parser-config.cmake.in"
41+
"${CMAKE_CURRENT_BINARY_DIR}/fast_double_parser-config.cmake"
42+
INSTALL_DESTINATION "share/fast_double_parser"
43+
)
44+
install(
45+
FILES "${CMAKE_CURRENT_BINARY_DIR}/fast_double_parser-config.cmake"
46+
DESTINATION "share/fast_double_parser"
47+
)
48+
49+
option(BUILD_TESTING "Build unit tests" ON)
50+
if(BUILD_TESTING)
51+
add_executable(unit ${unit_src} ${bogus_src} ${rebogus_src})
52+
53+
if(FAST_DOUBLE_PARSER_SANITIZE)
54+
target_compile_options(unit PUBLIC -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all)
55+
target_link_options(unit PUBLIC -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all)
56+
# Ubuntu bug for GCC 5.0+ (safe for all versions)
57+
if (CMAKE_COMPILER_IS_GNUCC AND NOT APPLE)
58+
target_link_libraries(unit PUBLIC -fuse-ld=gold)
59+
endif()
60+
endif()
61+
target_link_libraries(unit PRIVATE fast_double_parser)
2462

25-
add_executable(unit ${unit_src} ${bogus_src} ${rebogus_src})
26-
if(FAST_DOUBLE_PARSER_SANITIZE)
27-
target_compile_options(unit PUBLIC -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all)
28-
target_link_options(unit PUBLIC -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all)
29-
# Ubuntu bug for GCC 5.0+ (safe for all versions)
30-
if (CMAKE_COMPILER_IS_GNUCC AND NOT APPLE)
31-
target_link_libraries(unit PUBLIC -fuse-ld=gold)
32-
endif()
63+
enable_testing()
64+
add_test(unit unit)
3365
endif()
3466

35-
target_link_libraries(unit PUBLIC fast_double_parser)
36-
37-
38-
39-
enable_testing()
40-
add_test(unit unit)
41-
4267
option(FAST_DOUBLE_BENCHMARKS "include benchmarks" OFF)
4368

44-
45-
4669
function(initialize_submodule DIRECTORY)
4770
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git)
4871
find_package(Git QUIET REQUIRED)
@@ -63,8 +86,6 @@ if(FAST_DOUBLE_BENCHMARKS)
6386
add_subdirectory(benchmarks/dependencies/abseil-cpp)
6487
add_subdirectory(benchmarks/dependencies/double-conversion)
6588

66-
67-
6889
add_executable(benchmark ${benchmark_src})
6990
target_link_libraries(benchmark PUBLIC double-conversion absl_strings)
7091
target_include_directories(benchmark PUBLIC include)

Diff for: fast_double_parser-config.cmake.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/fast_double_parser-targets.cmake")

0 commit comments

Comments
 (0)