-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcommon.cmake
88 lines (69 loc) · 2.77 KB
/
common.cmake
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
cmake_minimum_required (VERSION 2.8)
project (${PROJECT})
enable_testing()
option(TODO "Enable TODO items that are in progress" OFF)
option(TESTS "Enable building of extended test code in library" ON)
option(EXAMPLES "Enable building of example programs" ON)
option(TOOLS "Enable building of tools" ON)
option(TOOLS_DEV "Enable building of tools-dev" ON)
if(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake|MSBuild)")
add_definitions("/W2")
else()
add_definitions("-Wall -Wextra")
endif()
if(TODO MATCHES "ON")
add_definitions("-DTODO=1")
message(STATUS "TODO items that are in progress are enabled for compiling")
endif()
set(LIBS ${LIBS} ${CHECK_LIBRARIES} ${PROJECT})
include_directories( include ${ADDITIONAL_INCLUDE_DIRECTORIES} )
if(TESTS MATCHES "ON")
message(STATUS "Extended test code functions are enabled")
file(GLOB PROJECT_INCLUDES "include/*.hpp" "include/tests/*.hpp" "include/*.h" "include/tests/*.h" ${ADDITIONAL_PROJECT_INCLUDES} )
file(GLOB PROJECT_SRC "src/*.c" "src/test/*.c" "src/*.cpp" "src/test/*.cpp" ${ADDITIONAL_PROJECT_SRC} )
else()
file(GLOB PROJECT_INCLUDES "include/*.h" "include/*.hpp")
file(GLOB PROJECT_SRC "src/*.c" "src/*.cpp" )
endif()
add_library (${PROJECT} ${PROJECT_SRC} ${PROJECT_INCLUDES})
link_directories( ${PROJECT_BINARY_DIR} )
if(EXAMPLES MATCHES "ON")
file(GLOB PROJECT_EXAMPLES "examples/*.c" "examples/*.cpp")
foreach(item ${PROJECT_EXAMPLES})
GET_FILENAME_COMPONENT(examplename ${item} NAME_WE )
add_executable(${examplename} ${item})
target_link_libraries(${examplename} ${LIBS} )
endforeach(item)
endif()
if(TOOLS MATCHES "ON")
file(GLOB PROJECT_TOOLS "tools/*.c" "tools/*.cpp")
foreach(item ${PROJECT_TOOLS})
GET_FILENAME_COMPONENT(toolname ${item} NAME_WE )
add_executable(${toolname} ${item})
target_link_libraries(${toolname} ${LIBS} )
endforeach(item)
endif()
if(TOOLS_DEV MATCHES "ON")
file(GLOB PROJECT_TOOLS_DEV "tools-dev/*.c" "tools-dev/*.cpp")
foreach(item ${PROJECT_TOOLS_DEV})
GET_FILENAME_COMPONENT(toolname ${item} NAME_WE )
add_executable(${toolname} ${item})
target_link_libraries(${toolname} ${LIBS} )
endforeach(item)
endif()
if(TESTS MATCHES "ON")
file(GLOB PROJECT_TESTS "tests/*.c" "tests/*.cpp")
foreach(item ${PROJECT_TESTS})
GET_FILENAME_COMPONENT(testname ${item} NAME_WE )
add_executable(${testname} ${item})
target_link_libraries(${testname} ${LIBS} )
add_test(NAME ${testname} COMMAND ${testname} )
endforeach(item)
endif()
INSTALL(TARGETS ${PROJECT} DESTINATION "lib" EXPORT ${PROJECT}-exports.cmake )
EXPORT(TARGETS ${PROJECT} FILE ${PROJECT}-exports.cmake )
INSTALL(FILES
${PROJECT_INCLUDES}
DESTINATION include
)
install(EXPORT ${PROJECT}-exports.cmake DESTINATION "lib" )