@@ -15,28 +15,29 @@ if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
15
15
endif ()
16
16
17
17
option (NOTE_C_BUILD_TESTS "Build tests." OFF )
18
- option (BUILD_SHARED_LIBS "Build shared libraries instead of static." OFF )
19
18
option (NOTE_C_COVERAGE "Compile for test NOTE_C_COVERAGE reporting." OFF )
20
19
option (NOTE_C_MEM_CHECK "Run tests with Valgrind." OFF )
21
20
22
21
set (NOTE_C_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
23
- add_library (
22
+ add_library (note_c SHARED)
23
+ target_sources (
24
24
note_c
25
- ${NOTE_C_SRC_DIR} /n_atof.c
26
- ${NOTE_C_SRC_DIR} /n_cjson.c
27
- ${NOTE_C_SRC_DIR} /n_const.c
28
- ${NOTE_C_SRC_DIR} /n_helpers.c
29
- ${NOTE_C_SRC_DIR} /n_i2c.c
30
- ${NOTE_C_SRC_DIR} /n_printf.c
31
- ${NOTE_C_SRC_DIR} /n_serial.c
32
- ${NOTE_C_SRC_DIR} /n_ua.c
33
- ${NOTE_C_SRC_DIR} /n_b64.c
34
- ${NOTE_C_SRC_DIR} /n_cjson_helpers.c
35
- ${NOTE_C_SRC_DIR} /n_ftoa.c
36
- ${NOTE_C_SRC_DIR} /n_hooks.c
37
- ${NOTE_C_SRC_DIR} /n_md5.c
38
- ${NOTE_C_SRC_DIR} /n_request.c
39
- ${NOTE_C_SRC_DIR} /n_str.c
25
+ PRIVATE
26
+ ${NOTE_C_SRC_DIR} /n_atof.c
27
+ ${NOTE_C_SRC_DIR} /n_cjson.c
28
+ ${NOTE_C_SRC_DIR} /n_const.c
29
+ ${NOTE_C_SRC_DIR} /n_helpers.c
30
+ ${NOTE_C_SRC_DIR} /n_i2c.c
31
+ ${NOTE_C_SRC_DIR} /n_printf.c
32
+ ${NOTE_C_SRC_DIR} /n_serial.c
33
+ ${NOTE_C_SRC_DIR} /n_ua.c
34
+ ${NOTE_C_SRC_DIR} /n_b64.c
35
+ ${NOTE_C_SRC_DIR} /n_cjson_helpers.c
36
+ ${NOTE_C_SRC_DIR} /n_ftoa.c
37
+ ${NOTE_C_SRC_DIR} /n_hooks.c
38
+ ${NOTE_C_SRC_DIR} /n_md5.c
39
+ ${NOTE_C_SRC_DIR} /n_request.c
40
+ ${NOTE_C_SRC_DIR} /n_str.c
40
41
)
41
42
target_compile_options (
42
43
note_c
@@ -73,59 +74,5 @@ if(NOTE_C_BUILD_TESTS)
73
74
PRIVATE ${CMAKE_CURRENT_LIST_DIR} /test /include
74
75
)
75
76
76
- # If we don't weaken the functions we're mocking in the tests, the linker
77
- # will complain about multiple function definitions: the mocked one and the
78
- # "real" one from note-c. Weakening the real function causes the mock
79
- # function, if defined, to override the real one. If no mock is defined, the
80
- # real one will be used. So, every time a developer needs to mock a function
81
- # in a test, they need to make sure it's included in the MOCKED_FNS list
82
- # below.
83
- set (
84
- MOCKED_FNS
85
- "NoteReset;
86
- NoteJSONTransaction;
87
- NoteTransaction;
88
- NoteGetMs;
89
- NoteRequestResponse;
90
- NoteMalloc;
91
- NoteI2CTransmit;
92
- NoteI2CReceive;
93
- NoteLockI2C;
94
- NoteUnlockI2C;
95
- NoteI2CReset;
96
- NoteSerialAvailable;
97
- NoteSerialTransmit;
98
- NoteSerialReceive;
99
- NoteSerialReset;
100
- NoteIsDebugOutputActive;
101
- NoteDebug;
102
- NotePrint;
103
- NoteNewCommand;
104
- NoteRequest;
105
- JCreateObject;
106
- NoteTransactionStart;
107
- NoteUserAgent;
108
- serialNoteReset;
109
- serialNoteTransaction;
110
- i2cNoteReset;
111
- i2cNoteTransaction;
112
- JCreateStringValue;
113
- NoteSetEnvDefault;
114
- NoteSleep;
115
- NotePayloadRetrieveAfterSleep;
116
- NoteTimeValidST;
117
- NoteTimeST;
118
- NoteRegion"
119
- )
120
- foreach (MOCKED_FN ${MOCKED_FNS} )
121
- string (APPEND OBJCOPY_WEAKEN "-W ${MOCKED_FN} " )
122
- endforeach ()
123
- separate_arguments (OBJCOPY_WEAKEN_LIST NATIVE_COMMAND "${OBJCOPY_WEAKEN} " )
124
- add_custom_command (TARGET note_c POST_BUILD
125
- COMMAND ${CMAKE_OBJCOPY} ${OBJCOPY_WEAKEN_LIST}
126
- $<TARGET_FILE:note_c>
127
- COMMENT "Weakening mocked functions."
128
- )
129
-
130
77
add_subdirectory (test )
131
78
endif (NOTE_C_BUILD_TESTS)
0 commit comments