I am currently creating a set of classes that should be used in different projects using CLion. My question is how do I implement this functionality.
So far I looked into the following related issues which didn't really solve my problem:
- CMake link to external library
- Add external libraries to CMakeList.txt c++
- CMake reference for add_library(), find_library() which I don't fully understand yet since I am fairly new to CMake
I created two sample projects "TestLib" and "TestProj":
- TestLib
- src
- Class.h
- Class.cpp
- CMakeList.txt
- src
- TestProj
- main.cpp
- CMakeList.txt
The CMakeList.txt for "TestLib" currently looks as follows:
cmake_minimum_required(VERSION 3.5)
project(TestLib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
set(SOURCE_FILES src/Class.cpp src/Class.h)
add_library(TestLib ${SOURCE_FILES})>
Now, I tried to use this library in "TestProj" using the following
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(TestProj)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
find_library(CLASS_LIB TestLib HINTS /home/user/.CLion2016.1/system/cmake/generated/TestLib-7507f101/7507f101/Debug)
set(SOURCE_FILES main.cpp)
add_executable(TestProj ${SOURCE_FILES})
target_link_libraries(TestProj CLASS_LIB)
CMake finds the library but
- I dont have access to Class.h of the library
- Writing the whole /home/user/.CLion2016.1/...-Path to the library seems to be wrong
Any help is really appreciated. Thank you.