-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
73 lines (62 loc) · 3.63 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
#
# CMake file to build NetworkManagerCpp.
# Mark Grimes ([email protected])
# 06/Oct/2017
# copyright 2017 Rymapt Ltd
# Licence to be decided
#
project( NetworkManagerCpp )
cmake_minimum_required(VERSION 2.8)
if( NOT MSVC ) # Microsoft Visual Studio is C++11 by default and doesn't recognise this flag
add_definitions( "-std=c++11" )
endif()
# Create the file that has the version information and git hash
execute_process( COMMAND git describe --dirty --always --tags WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE NetworkManagerCpp_GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE )
execute_process( COMMAND git log -1 --pretty=format:%H WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE NetworkManagerCpp_GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE )
add_custom_target( ${PROJECT_NAME}_CreateVersionFile ALL ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp.in" ) # Make sure the git hash is always checked (not just at configure time)
configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp.in" "${PROJECT_BINARY_DIR}/src/version.cpp" )
option( LIBNM_MOCK_CLASSES "Build unit tests" OFF )
if( LIBNM_MOCK_CLASSES )
# Build mock code that doesn't do anything, but can be compiled and used without libnm C library
# for when developing the other parts of an application.
message( WARNING "*WARNING* LIBNM_MOCK_CLASSES has been set to ON, which means no functional "
"code will be produced. This is only useful for development on machines without "
"NetworkManager installed." )
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/mock/include" )
aux_source_directory( "${CMAKE_CURRENT_SOURCE_DIR}/mock/src" library_sources )
add_library( ${PROJECT_NAME} STATIC ${library_sources} "${PROJECT_BINARY_DIR}/src/version.cpp" )
set( ${PROJECT_NAME}_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/mock/include" PARENT_SCOPE )
else()
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/include" )
aux_source_directory( "${CMAKE_CURRENT_SOURCE_DIR}/src" library_sources )
# Project dependencies
find_package(PkgConfig REQUIRED)
pkg_check_modules(LibNM REQUIRED libnm)
add_library( ${PROJECT_NAME} STATIC ${library_sources} "${PROJECT_BINARY_DIR}/src/version.cpp" )
set( ${PROJECT_NAME}_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE )
target_link_libraries( ${PROJECT_NAME} ${LibNM_LIBRARIES})
target_include_directories( ${PROJECT_NAME} PUBLIC ${LibNM_INCLUDE_DIRS})
target_compile_options( ${PROJECT_NAME} PUBLIC ${LibNM_CFLAGS_OTHER})
install( TARGETS ${PROJECT_NAME} DESTINATION lib )
install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION include )
option( BUILD_UNITTESTS "Build unit tests" ON )
message( STATUS "BUILD_UNITTESTS: ${BUILD_UNITTESTS}" )
if( BUILD_UNITTESTS )
# Fix the test configuration file to have the correct paths
configure_file( "${PROJECT_SOURCE_DIR}/tests/src/testinputs.cpp.in" "${PROJECT_BINARY_DIR}/tests/src/testinputs.cpp" @ONLY )
include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/tests/include" )
aux_source_directory( "${CMAKE_CURRENT_SOURCE_DIR}/tests/src" unittests_sources )
add_executable( ${PROJECT_NAME}Tests ${unittests_sources} "${PROJECT_BINARY_DIR}/tests/src/testinputs.cpp" )
target_link_libraries( ${PROJECT_NAME}Tests ${PROJECT_NAME} )
endif()
option( BUILD_EXAMPLES "Build examples" ON )
message( STATUS "BUILD_EXAMPLES: ${BUILD_EXAMPLES}" )
if( BUILD_EXAMPLES )
file( GLOB CPP_FILES "examples/*.cpp" )
foreach( CPP_FILE ${CPP_FILES} )
get_filename_component( EXECUTABLE_NAME ${CPP_FILE} NAME_WE )
add_executable( ${EXECUTABLE_NAME} ${CPP_FILE} )
target_link_libraries( ${EXECUTABLE_NAME} ${PROJECT_NAME} )
endforeach()
endif()
endif()