Visual studio project for header only library

后端 未结 2 1131
生来不讨喜
生来不讨喜 2021-01-03 12:29

I\'m creating a CMake project whose two main files are:

cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(CPP_Algorithms_and_Data_Structures)

set( CM         


        
相关标签:
2条回答
  • 2021-01-03 13:06

    As far as I know there is no normal way to do it. Only a hackish one. So you create a custom target which will force MSVC to show the project in the solution tree. Something like this:

    add_custom_target(${PROJECT_NAME}_ SOURCES ${PROJECT_SOURCES})
    

    Note the underscore in the name: it is there to differentiate it from the name in the add_library command. Of course you need to replace the variables in my example to yours actual ones.

    0 讨论(0)
  • 2021-01-03 13:14

    Another solution is to declare static library with stub source file:

    file(TOUCH ${CMAKE_BINARY_DIR}/stub.cpp)
    
    add_library(elementary-data-structures STATIC
        "${CMAKE_BINARY_DIR}/stub.cpp"
        "${CMAKE_CURRENT_LIST_DIR}/list.h"
        "${CMAKE_CURRENT_LIST_DIR}/list.tcc"
    )
    target_include_directories(elementary-data-structures INTERFACE ./)
    
    0 讨论(0)
提交回复
热议问题