- 
                Notifications
    You must be signed in to change notification settings 
- Fork 94
qt-build-utils: Add an option to use CMake instead of QMake #1156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            redstrate
  wants to merge
  1
  commit into
  KDAB:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
redstrate:work/josh/cmake-package
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -558,6 +558,30 @@ impl QtBuild { | |
| /// Get the include paths for Qt, including Qt module subdirectories. This is intended | ||
| /// to be passed to whichever tool you are using to invoke the C++ compiler. | ||
| pub fn include_paths(&self) -> Vec<PathBuf> { | ||
| #[cfg(feature = "cmake")] | ||
| { | ||
| let Ok(package) = cmake_package::find_package(format!("Qt{}", self.version.major)) | ||
| .components(self.qt_modules.clone()) | ||
| .find() | ||
| else { | ||
| return Vec::default(); | ||
| }; | ||
|  | ||
| let mut paths = Vec::new(); | ||
| for qt_module in &self.qt_modules { | ||
| if let Some(target) = package.target(format!("Qt::{}", qt_module)) { | ||
| paths.extend(target.include_directories); | ||
| } | ||
| } | ||
|  | ||
| return paths | ||
| .iter() | ||
| .map(PathBuf::from) | ||
| // Only add paths if they exist | ||
| .filter(|path| path.exists()) | ||
| .collect(); | ||
| } | ||
|  | ||
| let root_path = self.qmake_query("QT_INSTALL_HEADERS"); | ||
| let lib_path = self.qmake_query("QT_INSTALL_LIBS"); | ||
| let mut paths = Vec::new(); | ||
|  | @@ -591,6 +615,27 @@ impl QtBuild { | |
| /// Lazy load the path of a Qt executable tool | ||
| /// Skip doing this in the constructor because not every user of this crate will use each tool | ||
| fn get_qt_tool(&self, tool_name: &str) -> Result<String, ()> { | ||
| #[cfg(feature = "cmake")] | ||
| { | ||
| // QML tools live in the QML target, of course | ||
| let tools_component = if tool_name.contains("qml") { | ||
| "QmlTools" | ||
| } else { | ||
| "CoreTools" | ||
| }; | ||
|  | ||
| let Ok(package) = cmake_package::find_package(format!("Qt{}", self.version.major)) | ||
| .components([tools_component.into()]) | ||
| .find() | ||
| else { | ||
| return Err(()); | ||
| }; | ||
| let Some(target) = package.target(format!("Qt6::{}", tool_name)) else { | ||
| return Err(()); | ||
| }; | ||
| return target.location.ok_or(()); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here | ||
| } | ||
|  | ||
| // "qmake -query" exposes a list of paths that describe where Qt executables and libraries | ||
| // are located, as well as where new executables & libraries should be installed to. | ||
| // We can use these variables to find any Qt tool. | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes the code after it unreachable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is really interesting, i wonder if the approach here could be.
unimplemented!()Whether as part of the refactor @LeonMatthesKDAB we change the code of qt-build-utils to be trait driven, so instead of every function having a two cfg blocks and a unimplemented instead there is a trait that is implemented by either CMake/QMake implementations ? Then the question is whether the feature is even needed and both are always built, but maybe the feature chooses the "default" implementation and you can still manually force one of them...