diff --git a/CMakeLists.txt b/CMakeLists.txt index 21f67c0..014544d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,11 @@ set(CMAKE_CXX_STANDARD 17) set (CMAKE_EXPORT_COMPILE_COMMANDS ON) project (shared) + +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set (LIBSHARED_IS_TOP_LEVEL ON) +endif () + include (CXXSniffer) include (CheckFunctionExists) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e17455..4c39464 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,9 +56,11 @@ set (shared_SRCS Args.cpp add_library (shared STATIC ${shared_SRCS}) -set (CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries") -install (TARGETS shared DESTINATION lib) -install (FILES ${shared_HEADERS} DESTINATION include) +if (LIBSHARED_IS_TOP_LEVEL) + set (CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries") + install (TARGETS shared DESTINATION lib) + install (FILES ${shared_HEADERS} DESTINATION include) +endif () add_executable (lex_executable lex.cpp) target_link_libraries (lex_executable shared)