Remove headers from cmake add_library

Headers aren't supposed to be listed in `add_library` calls and are an
unfortunately common cmake anti-pattern.  (cmake does *not* need headers
listed to know how to check that things need rebuilding when a header
changes, which seems to be the reason people think they have to include
them).

Apparently this antipattern emerged partly because of buggy behaviour in
MSVC pre-2017 that didn't understand how to find headers when loading a
CMake project.
This commit is contained in:
Jason Rhinelander 2020-04-13 15:53:08 -03:00
parent 5680167f11
commit f01db5bb2f
5 changed files with 5 additions and 42 deletions

View file

@ -2,17 +2,10 @@ cmake_minimum_required(VERSION 3.1)
add_definitions(-DSPDLOG_COMPILED_LIB)
set(SRC_FILES
add_library(common STATIC
src/loki_logger.cpp
)
set(HEADER_FILES
include/loki_common.h
include/loki_logger.h
include/dev_sink.h
)
add_library(common STATIC ${HEADER_FILES} ${SRC_FILES})
find_package(Boost
REQUIRED

View file

@ -4,26 +4,7 @@ add_definitions(-DDISABLE_ENCRYPTION)
project(httpserver)
set(HEADER_FILES
http_connection.h
swarm.h
service_node.h
serialization.h
rate_limiter.h
../external/json.hpp
https_client.h
server_certificates.h
stats.h
security.h
command_line.h
net_stats.h
dns_text_records.h
reachability_testing.h
lmq_server.h
request_handler.h
)
set(SRC_FILES
add_library(httpserver_lib STATIC
main.cpp
http_connection.cpp
swarm.cpp
@ -40,8 +21,6 @@ set(SRC_FILES
request_handler.cpp
)
add_library(httpserver_lib STATIC ${HEADER_FILES} ${SRC_FILES})
loki_add_subdirectory(../common common)
loki_add_subdirectory(../storage storage)
loki_add_subdirectory(../utils utils)

View file

@ -1,9 +1,7 @@
set(SOURCES
include/pow.hpp
add_library(pow STATIC
src/pow.cpp
)
add_library(pow STATIC ${SOURCES})
loki_add_subdirectory(../utils utils)

View file

@ -1,13 +1,9 @@
cmake_minimum_required(VERSION 3.1)
set(SOURCES
include/Database.hpp
include/Item.hpp
add_library(storage STATIC
src/Database.cpp
)
add_library(storage STATIC ${SOURCES})
set_property(TARGET storage PROPERTY CXX_STANDARD 14)
target_include_directories(storage

View file

@ -2,8 +2,7 @@ if (TARGET utils)
return()
endif()
set(SOURCES
include/utils.hpp
add_library(utils STATIC
src/utils.cpp
)
@ -12,8 +11,6 @@ find_package(Boost
filesystem
)
add_library(utils STATIC ${SOURCES})
set_property(TARGET utils PROPERTY CXX_STANDARD 14)
target_include_directories(utils