{"action":"created","issue":{"url":"https://api.github.com/repos/onqtam/doctest/issues/21","repository_url":"https://api.github.com/repos/onqtam/doctest","labels_url":"https://api.github.com/repos/onqtam/doctest/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/onqtam/doctest/issues/21/comments","events_url":"https://api.github.com/repos/onqtam/doctest/issues/21/events","html_url":"https://github.com/onqtam/doctest/issues/21","id":158505140,"number":21,"title":"Tests inside a library","user":{"login":"pthom","id":7694091,"avatar_url":"https://avatars.githubusercontent.com/u/7694091?v=3","gravatar_id":"","url":"https://api.github.com/users/pthom","html_url":"https://github.com/pthom","followers_url":"https://api.github.com/users/pthom/followers","following_url":"https://api.github.com/users/pthom/following{/other_user}","gists_url":"https://api.github.com/users/pthom/gists{/gist_id}","starred_url":"https://api.github.com/users/pthom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pthom/subscriptions","organizations_url":"https://api.github.com/users/pthom/orgs","repos_url":"https://api.github.com/users/pthom/repos","events_url":"https://api.github.com/users/pthom/events{/privacy}","received_events_url":"https://api.github.com/users/pthom/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-06-04T13:36:56Z","updated_at":"2016-09-08T08:22:14Z","closed_at":null,"body":"Hi,\r\n\r\n(This is more a question than an issue)\r\nWhat is the recommended way to add tests inside a static library project ?\r\n\r\nIf I compile a library (which includes TEST_CASE(s)) as a static library, \r\nand then I try to run the tests from this library by creating a target that links\r\nto it, the test suite is actually empty (i.e I guess the tests were stripped at link time)\r\n\r\nAm I doing something wrong, or is there a way to circumvent this?  \r\n\r\nBelow is an example of what I am trying to achieve (using cmake):\r\n\r\n```\r\nProject         <- main project\r\n  CMakeLists.txt\r\n  doctest/\r\n    doctest.h\r\n    doctest_main.cpp\r\n  MyLibrary/\r\n    lib1.cpp    <- these files includes actual library code and TEST_CASE(s)\r\n    lib2.cpp    \r\n    lib3.cpp    \r\n    CMakeLists.txt <- will produce two targets : library and its test\r\n  MyMainProgram/\r\n    main.cpp\r\n    CMakeLists.txt\r\n\r\n```\r\nMyLibrary/CMakeLists.txt :\r\n```\r\n    set(sources lib1.cpp lib2.cpp lib3.cpp)\r\n    add_library(MyLibrary STATIC ${sources})\r\n    target_include_directories(MyLibrary PUBLIC ${CMAKE_SOURCE_DIR}/doctest )\r\n\r\n    # This does not work : it links but the test list is empty !\r\n    add_executable(MyLibrary_DocTest ${CMAKE_SOURCE_DIR}/doctest/doctest_main.cpp)\r\n    target_link_libraries(MyLibrary_DocTest MyLibrary)\r\n\r\n    # This works, but it requires to re-compile all the source files and to re-define\r\n    # exactly the same compile options as for the library (linked library, compile definition, etc); \r\n    # this can be tedious\r\n    add_executable(MyLibrary_DocTest ${sources} ${CMAKE_SOURCE_DIR}/doctest/doctest_main.cpp)\r\n\r\n```\r\nMyMainProgram/CMakeLists.txt :\r\n```\r\n    add_executable(MyMainProgram main.cpp)\r\n    target_link_libraries(MyMainProgram MyLibrary)\r\n```\r\n\r\nA working example can be found at https://github.com/pthom/DocTest_LibTest"},"comment":{"url":"https://api.github.com/repos/onqtam/doctest/issues/comments/245527417","html_url":"https://github.com/onqtam/doctest/issues/21#issuecomment-245527417","issue_url":"https://api.github.com/repos/onqtam/doctest/issues/21","id":245527417,"user":{"login":"onqtam","id":4648169,"avatar_url":"https://avatars.githubusercontent.com/u/4648169?v=3","gravatar_id":"","url":"https://api.github.com/users/onqtam","html_url":"https://github.com/onqtam","followers_url":"https://api.github.com/users/onqtam/followers","following_url":"https://api.github.com/users/onqtam/following{/other_user}","gists_url":"https://api.github.com/users/onqtam/gists{/gist_id}","starred_url":"https://api.github.com/users/onqtam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onqtam/subscriptions","organizations_url":"https://api.github.com/users/onqtam/orgs","repos_url":"https://api.github.com/users/onqtam/repos","events_url":"https://api.github.com/users/onqtam/events{/privacy}","received_events_url":"https://api.github.com/users/onqtam/received_events","type":"User","site_admin":false},"created_at":"2016-09-08T08:22:14Z","updated_at":"2016-09-08T08:22:14Z","body":":D I'm still delaying the finish of the 1.1 release. Actually my approach wouldn't work. I came up with a different one - if it doesn't work as well I will link in my FAQ to your project.\r\n\r\nI hope that I release 1.1 in the next 1-2 weeks with this fixed (or linked to your solution)..."}}
{"actor":{"display_login":"onqtam"}}