I'm trying to create Makefile for my project with CMake but I'm getting
CMake Error: Cannot determine link language for target "mylib".
CMake Error: CMake can not determine linker language for target: mylib
error.
Project structure is as follows:
.
├── CMakeLists.txt
├── build
├── doc
├── include
│ ├── headers_library1
│ │ ├── headers1.hpp
│ │ ├── headers2.hpp
│ │ └── headers3.hpp
│ └── headers_library2
│ ├── dir1
│ ├── dir2
│ ├── dir3
│ ├── headers1.h
│ ├── headers2.h
.
. many header files
.
│ ├── headers20.h
│ └── headers21.h
├── lib
│ └── CMakeLists.txt
└── src
└── example.cpp
Where headers in headers_library1
includes system shared libraries (namely libcurl and libcryptopp) and header-only library headers_library2
.
Root CMakeLists.txt
contains:
cmake_minimum_required (VERSION 3.12)
project (example)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_subdirectory(lib)
# TARGET example
add_executable (example src/example.cpp)
target_link_libraries (example PRIVATE mylib)
target_include_directories (example PUBLIC include)
target_compile_options(example PRIVATE -Wall)
and lib/CMakeLists.txt
contains:
file(GLOB_RECURSE HDRS_H ${PROJECT_SOURCE_DIR}/include/*.h)
file(GLOB_RECURSE HDRS_HPP ${PROJECT_SOURCE_DIR}/include/*.hpp)
# TARGET mylib
add_library (mylib STATIC ${HDRS_H} ${HDRS_HPP})
target_include_directories (mylib PUBLIC ${PROJECT_SOURCE_DIR}/include)
set_target_properties(mylib PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
First I want to build static library mylib
and place it into /lib
directory. Then I want to build example
executable and link it with the mylib
library.