dougbinks / enkiTS

A permissively licensed C and C++ Task Scheduler for creating parallel programs. Requires C++11 support.
zlib License
1.74k stars 145 forks source link

adding enkiTS as a static library to another project #74

Closed vadersb closed 2 years ago

vadersb commented 2 years ago

I have a project with the following setup in CMakeLists.txt:

add_subdirectory(${ENKITS_DIR} "enkiTS")

add_executable(mytest01 main.cpp main.h tasks_enkits.cpp)
target_link_libraries(mytest01 PRIVATE shared_stuff enkiTS )

where ENKITS_DIR is a CMake var, a path to the library folder, outside of my project source path.

the problem is mytest01 doesn't compile, because this header file can't be found: #include "TaskScheduler.h"

There are two important things that have to be mentioned:

  1. the very same setup works with various other libraries like raylib and spdlog
  2. my project compiles just fine if the following line (it's the second one from the bottom) is applied to enkiTS' CMakeLists.txt:
    if( ENKITS_BUILD_SHARED )
    add_library( enkiTS SHARED ${ENKITS_SRC} )
    target_compile_definitions( enkiTS PRIVATE ENKITS_BUILD_DLL=1 )
    target_compile_definitions( enkiTS INTERFACE ENKITS_DLL=1 )
    if( UNIX )
        if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 
             SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
        endif()
    endif ()
    else()
    message(STATUS "enkiTS as a static library")
    add_library( enkiTS STATIC ${ENKITS_SRC} )
    target_include_directories(enkiTS PUBLIC "${PROJECT_SOURCE_DIR}/src") #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    endif()

I have little experience with CMake so maybe there is a problem with my project setup (although it does work with other libs)?

dougbinks commented 2 years ago

Thanks for filing the issue - I'll look into adding target_include_directories (I think this would need to be done for both static and dynamic library builds), for now you can add include_directories("enkiTS/src") to your CmakeLists.txt to add the appropriate directory to your build includes, as per the one in the enkiTSExamples project.

vadersb commented 2 years ago

ok, great, thank you!