-
Notifications
You must be signed in to change notification settings - Fork 35
/
CMakeLists.txt
140 lines (119 loc) · 5.99 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
cmake_minimum_required(VERSION 3.7.2)
project(mx)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(CPP_VERSION 17)
option(MX_BUILD_TESTS "build or skip the test suite" OFF)
option(
MX_BUILD_CORE_TESTS
"build or skip the tests in the 'core' namespace, requires MX_BUILD_TESTS"
OFF
)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/Sourcecode")
set(PRIVATE_DIR "${SOURCE_ROOT}/private")
set(PUBLIC_DIR "${SOURCE_ROOT}/include")
file(GLOB_RECURSE HEADERS_MX_API ${PUBLIC_DIR}/mx/api/*.h)
file(GLOB_RECURSE SRC_MX_API ${PRIVATE_DIR}/mx/api/*.cpp ${PRIVATE_DIR}/mx/api/*.h)
file(GLOB_RECURSE SRC_MX_CORE ${PRIVATE_DIR}/mx/core/*.c* ${PRIVATE_DIR}/mx/core/*.h*)
file(GLOB_RECURSE SRC_MX_IMPL ${PRIVATE_DIR}/mx/impl/*.cpp ${PRIVATE_DIR}/mx/impl/*.h)
file(GLOB_RECURSE SRC_MX_UTILITY ${PRIVATE_DIR}/mx/utility/*.cpp ${PRIVATE_DIR}/mx/utility/*.h)
file(GLOB_RECURSE SRC_MX_EZXML ${PRIVATE_DIR}/mx/ezxml/*.cpp ${PRIVATE_DIR}/mx/ezxml/*.h*)
file(GLOB_RECURSE SRC_MX_TEST_API ${PRIVATE_DIR}/mxtest/api/*.cpp ${PRIVATE_DIR}/mxtest/api/*.h)
file(GLOB_RECURSE SRC_MX_TEST_CONTROL ${PRIVATE_DIR}/mxtest/control/*.cpp ${PRIVATE_DIR}/mxtest/control/*.h)
file(GLOB_RECURSE SRC_MX_TEST_FILE ${PRIVATE_DIR}/mxtest/file/*.cpp ${PRIVATE_DIR}/mxtest/file/*.h)
file(GLOB_RECURSE SRC_MX_TEST_IMPL ${PRIVATE_DIR}/mxtest/impl/*.cpp ${PRIVATE_DIR}/mxtest/impl/*.h)
file(GLOB_RECURSE SRC_MX_TEST_CORE ${PRIVATE_DIR}/mxtest/core/*.cpp ${PRIVATE_DIR}/mxtest/core/*.h)
file(GLOB_RECURSE SRC_MX_TEST_IMPORT ${PRIVATE_DIR}/mxtest/import/*.cpp ${PRIVATE_DIR}/mxtest/import/*.h)
file(GLOB_RECURSE SRC_MX_TEST_UTILITY ${PRIVATE_DIR}/mxtest/utility/*.cpp ${PRIVATE_DIR}/mxtest/utility/*.h)
file(GLOB_RECURSE SRC_CPUL ${PRIVATE_DIR}/cpul/*.cpp ${SOURCE}/cpul/*.h)
# mx static library
add_library(${PROJECT_NAME} STATIC ${SRC_MX_API} ${SRC_MX_CORE} ${SRC_MX_IMPL} ${SRC_MX_UTILITY} ${SRC_MX_EZXML})
source_group( "api-public" FILES ${HEADERS_MX_API})
source_group( "api" FILES ${SRC_MX_API} )
source_group( "core" FILES ${SRC_MX_CORE} )
source_group( "impl" FILES ${SRC_MX_IMPL} )
source_group( "utility" FILES ${SRC_MX_UTILITY} )
source_group( "ezxml" FILES ${SRC_MX_EZXML} )
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD ${CPP_VERSION})
target_include_directories(${PROJECT_NAME} PRIVATE ${PRIVATE_DIR})
# these header paths are a little different to make it easier to copy-and-paste the ezxml code over to
# here http://github.com/webern/ezxml. However, as far as mx is concerned, ezxml is just another
# namespace in the mx library (that has a slightly different #include path convention)
target_include_directories(${PROJECT_NAME} PRIVATE "${PRIVATE_DIR}/mx/ezxml/src/include")
target_include_directories(${PROJECT_NAME} PRIVATE "${PRIVATE_DIR}/mx/ezxml/src/private")
target_include_directories(${PROJECT_NAME} PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${PUBLIC_DIR}>
)
# Install Package Configuration
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
install(EXPORT ${PROJECT_NAME}_targets
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}-config.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
)
install(DIRECTORY "${PUBLIC_DIR}/mx" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
file(WRITE ${PRIVATE_DIR}/mxtest/file/PathRoot.h
"// This file was auto-generated by CMake
#pragma once
// The absolute path to the root of the repository.
#ifndef MX_REPO_ROOT_PATH
#define MX_REPO_ROOT_PATH \"${CMAKE_CURRENT_SOURCE_DIR}\"
#endif
"
)
# mxtest
if(MX_BUILD_TESTS)
set(TEST_BINARY_NAME mxtest)
message(STATUS "${PROJECT_NAME}:${CMAKE_CURRENT_LIST_LINE} tests will be compiled")
if(MX_BUILD_CORE_TESTS)
message(STATUS "${PROJECT_NAME}:${CMAKE_CURRENT_LIST_LINE} core tests will be compiled")
add_definitions(-DMX_COMPILE_CORE_TESTS)
else()
message(STATUS "${PROJECT_NAME}:${CMAKE_CURRENT_LIST_LINE} core tests will NOT be compiled")
endif()
find_package( Threads )
add_executable(
${TEST_BINARY_NAME}
${SRC_MX_TEST_API}
${SRC_MX_TEST_CONTROL}
${SRC_MX_TEST_CORE}
${SRC_MX_TEST_FILE}
${SRC_MX_TEST_IMPL}
${SRC_MX_TEST_IMPORT}
${SRC_MX_TEST_UTILITY}
${SRC_MX_TEST_XML}
${SRC_CPUL}
)
target_include_directories(${TEST_BINARY_NAME} PRIVATE ${PRIVATE_DIR})
# See above: ezxml has a slightly different path convention, and it is used by certain tests even though it is
# not considered part of the public API of mx.
target_include_directories(${TEST_BINARY_NAME} PRIVATE "${PRIVATE_DIR}/mx/ezxml/src/include")
target_include_directories(${TEST_BINARY_NAME} PRIVATE "${PRIVATE_DIR}/mx/ezxml/src/private")
target_link_libraries(${TEST_BINARY_NAME} ${PROJECT_NAME})
target_link_libraries(${TEST_BINARY_NAME} ${CMAKE_THREAD_LIBS_INIT})
set_property(TARGET ${TEST_BINARY_NAME} PROPERTY CXX_STANDARD ${CPP_VERSION})
else()
message(STATUS "${PROJECT_NAME}:${CMAKE_CURRENT_LIST_LINE} tests will NOT be compiled")
endif()
# mx examples
if(MX_BUILD_EXAMPLES)
message(STATUS "${PROJECT_NAME}:${CMAKE_CURRENT_LIST_LINE} examples will be compiled")
add_executable(mxread ${PRIVATE_DIR}/mx/examples/Read.cpp)
add_executable(mxwrite ${PRIVATE_DIR}/mx/examples/Write.cpp)
add_executable(mxhide ${PRIVATE_DIR}/mx/examples/Hide.cpp)
target_link_libraries(mxread ${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(mxwrite ${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(mxhide ${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
set_property(TARGET mxread PROPERTY CXX_STANDARD ${CPP_VERSION})
set_property(TARGET mxwrite PROPERTY CXX_STANDARD ${CPP_VERSION})
set_property(TARGET mxhide PROPERTY CXX_STANDARD ${CPP_VERSION})
else()
message(STATUS "${PROJECT_NAME}:${CMAKE_CURRENT_LIST_LINE} examples will NOT be compiled")
endif()