I have the following code that works perfectly with gcc
by running the command:
gcc -L ~/Installed/C_LIBS/cmocka/lib -I ~/Installed/C_LIBS/cmocka/include hello.c -lcmocka -o hello
When I try to convert that to a CMakeLists.txt
it breaks after running cd build && cmake .. && make
with the following error codes:
Scanning dependencies of target hello
[ 50%] Building C object CMakeFiles/hello.dir/main.c.o
[100%] Linking C executable hello
ld: library not found for -lcmocka
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [hello] Error 1
make[1]: *** [CMakeFiles/hello.dir/all] Error 2
make: *** [all] Error 2
I have the code setup like this:
my-proj/
- CMakeLists.txt
- main.c
- build/
Here are my files:
main.c
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
/* A test case that does nothing and succeeds. */
static void null_test_success(void **state) {
(void) state; /* unused */
}
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(null_test_success),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.9)
project (hello)
include_directories(
SYSTEM ~/Installed/C_LIBS/cmocka/lib
SYSTEM ~/Installed/C_LIBS/cmocka/include
)
add_executable(hello main.c)
target_link_libraries(hello cmocka)
Can someone please tell me what I am doing wrong here? Also maybe point me in the direction of where to learn CMake better?