-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
90 lines (72 loc) · 3.04 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
cmake_minimum_required(VERSION 3.10)
project(libstopwatch LANGUAGES C)
#=======================================================================================================================
# General Setup
#=======================================================================================================================
# Prevent in-source builds as it pollutes the source directory
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(
FATAL_ERROR
"In-source build prohibited. Please make a build directory and rerun CMake."
)
endif ()
# Allow PAPI to be found via a find_package as it does not provide any CMake targets itself
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
# Build examples from the example directory
option(BUILD_C_EXAMPLES "Build C example programs" OFF)
option(BUILD_FORTRAN_EXAMPLES "Build Fortran example programs" OFF)
add_subdirectory("examples")
# Small testing
add_subdirectory("test")
# ======================================================================================================================
# Stopwatch Library
# ======================================================================================================================
find_package(PAPI REQUIRED)
add_library(stopwatch
STATIC
src/stopwatch.c
src/str_table.c
src/str_table.h
src/call_tree.c
src/call_tree.h
${CMAKE_SOURCE_DIR}/include/stopwatch/stopwatch.h
${CMAKE_SOURCE_DIR}/include/stopwatch/fstopwatch.F03
)
# Consumers of this library are going to need its public headers but not the PAPI headers
target_include_directories(stopwatch
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
# Weird caveat with GCC where non-fixed address is enabled by default which causes some linking to this static lib
target_link_libraries(stopwatch
PRIVATE
PAPI::PAPI
m
-no-pie
)
target_compile_options(stopwatch PRIVATE -Wall -Wextra)
#=======================================================================================================================
# Installation
#=======================================================================================================================
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Stopwatch)
install(TARGETS stopwatch
EXPORT stopwatch-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
set_target_properties(stopwatch PROPERTIES EXPORT_NAME Stopwatch)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT stopwatch-targets
FILE
StopwatchTargets.cmake
NAMESPACE
Stopwatch::
DESTINATION
${INSTALL_CONFIGDIR}
)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindPAPI.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/StopwatchConfig.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)