jwuttke
                (Joachim)
              
                
              
                  
                  
              1
              
             
            
              top-level CMakeLists.txt has
add_subdirectory(MyLib)
add_subdirectory(Tests)
MyLib/CMakeLists.txt has
add_library(MyLib <sources>)
...
Tests/CMakeLists.txt has
add_executable(Test1 <sources>)
target_link_libraries(Test1 PRIVATE $<TARGET_LINKER_FILE:MyLib>)
Works under Linux. Under Windows, however, the command
cmake --build . --config Release
fails because the system tries to build Test1 before MyLib.
What am I doing wrong?
             
            
              
              
              
            
            
           
          
            
              
                fenrir
                (Jakub Zakrzewski)
              
              
                  
                  
              2
              
             
            
              Don’t link to the resulting file. Link to the “MyLib” target. That way CMake will set the dependency right.
             
            
              
              
              1 Like
            
            
           
          
            
              
                jwuttke
                (Joachim)
              
              
                  
                  
              3
              
             
            
              When then would one use the generator expression?
             
            
              
              
              
            
            
           
          
            
              
                Angew
                (Petr Kmoch)
              
              
                  
                  
              4
              
             
            
              When you need to access the file directly: for example, to copy it somewhere in a custom command, or to pass it to a script.
Generator expressions such as this one can be useful for more advanced/niche uses, but for basic everyday usage, you shouldn’t need them.
             
            
              
              
              1 Like
            
            
           
          
            
              
                jwuttke
                (Joachim)
              
              
                  
                  
              5
              
             
            
              OK, with plain MyLib in place of the generator expression everything works.
Thank you very much, Jakub and Petr.