cefclient build cannot find newly added source code files

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

cefclient build cannot find newly added source code files

Postby martinsb » Sat Feb 11, 2017 3:38 pm

Hello everyone,

I have created a new project, per instructions in $CEF_ROOT/CMakeLists.txt, chose "Example 3" with having a CEF_ROOT environment variable pointing to a CEF binary distribution and copied the "cefclient" into the project as a starting point. At that point, everything builds fine, however then I tried adding new files "$PROJECT_ROOT/cefclient/common/pdf_print_callback.h" and "$PROJECT_ROOT/cefclient/common/pdf_print_callback.cc" (which contain CefPdfPrintCallback implementation) and including them in "$PROJECT_ROOT/cefclient/browser/root_window_mac.mm" (I'm testing this on Mac OS Sierra) like this:
Code: Select all
#include "cefclient/common/pdf_print_callback.h"

... project build started failing with the message
fatal error: 'cefclient/common/pdf_print_callback.h' file not found

Adding paths to these files to CEFCLIENT_COMMON_COMMON_SRCS collection in $PROJECT_ROOT/cefclient/CMakeLists.txt did not help either, not even sure it is supposed to.

This is a bit weird because already existing files do not fail the build, I'm absolutely sure I'm missing something obvious. Does anyone have an idea what I'm doing wrong?
Also I'm not sure whether this is CMake- or CEF-related issue, I apologise if this has nothing to do with CEF.

I'm building the project (in my $PROJECT_ROOT/build directory) like this:
Code: Select all
cmake -G "Ninja" -DPROJECT_ARCH="x86_64" -DCMAKE_BUILD_TYPE=Debug ..
ninja cefclient

I also tried using -G "XCode", however it also resulted in pdf_print_callback.h not being found.
For reference, complete contents of both files of mine below:

pdf_print_callback.h
Code: Select all
#ifndef CEF_TESTS_CEFCLIENT_COMMON_PDF_PRINT_CALLBACK_H
#define CEF_TESTS_CEFCLIENT_COMMON_PDF_PRINT_CALLBACK_H
#pragma once

#include "include/cef_browser.h"

namespace client {

class PdfPrintCallback: public CefPdfPrintCallback {
   
public:
    PdfPrintCallback();
    virtual ~PdfPrintCallback();
   
    void OnPdfPrintFinished(const CefString& path, bool ok) override;
   
private:
    IMPLEMENT_REFCOUNTING(PdfPrintCallback);
};
   
} //namespace client


#endif /* CEF_TESTS_CEFCLIENT_COMMON_PDF_PRINT_CALLBACK_H */


pdf_print_callback.cc:
Code: Select all
#include "cefclient/common/pdf_print_callback.h"

namespace client {
   
PdfPrintCallback::PdfPrintCallback() {
   
}

PdfPrintCallback::~PdfPrintCallback() {
   
}

void PdfPrintCallback::OnPdfPrintFinished(const CefString& path, bool ok) {
   
}
   
} //namespace client

martinsb
Newbie
 
Posts: 4
Joined: Sat Feb 11, 2017 5:32 am

Re: cefclient build cannot find newly added source code file

Postby magreenblatt » Mon Feb 13, 2017 11:40 am

What CEF version are you using? What style of include is used for other files from the same directory?

When adding new files you need to modify the CMakeLists.txt file and then re-run cmake to re-generate the project files.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: cefclient build cannot find newly added source code file

Postby martinsb » Tue Feb 14, 2017 7:15 am

Thank you for your answer.

I'm using CEF v. 3.2743.1432.g66425de, CMake v 3.7.1 via homebrew
I'm using the same include style as other includes in files across the cefclient project for example,
Code: Select all
#include "cefclient/common/client_switches.h"
.
Yes, I did re-run cmake and re-generated the project files on every CMakeLists.txt modification, of course.
martinsb
Newbie
 
Posts: 4
Joined: Sat Feb 11, 2017 5:32 am

Re: cefclient build cannot find newly added source code file

Postby magreenblatt » Tue Feb 14, 2017 10:35 am

You say that you copied the "cefclient" folder. Are you making changes in your copy? Does the add_subdirectory command in your top-level CMakeLists.txt file include your copy or the original?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: cefclient build cannot find newly added source code file

Postby martinsb » Wed Feb 15, 2017 2:26 am

Thank you so much for looking into my issue.
Yes, my top-level CMakeLists.txt file include my copy, that's for sure.

Actually, I've found the solution to my problem. Although I still haven' t figured out how compiler "sees" other include files in "cefclient" example, I started fixing stuff un my own how I see this sensible. Therefore, in my cefclient project's copy CMakeLists.txt I added
Code: Select all
include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR})
and in my "root_window_mac.mm" I reference my file as
Code: Select all
#include "common/pdf_print_callback.h"
(without the "cefclient" prefix). Now everything compiles and even runs :)
I think I'll change references to other paths in the "cefclient" project like this, at least now I really know where they come from thanks to that include_directories directive I added.

Thanks again for looking into this.
martinsb
Newbie
 
Posts: 4
Joined: Sat Feb 11, 2017 5:32 am

Re: cefclient build cannot find newly added source code file

Postby martinsb » Wed Feb 15, 2017 4:08 am

OK, I think I've figured out what was actually wrong here.
While compiling, the actual command line that was failing was:
Code: Select all
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++   -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -I/Users/martinsb/scratch/cefgenpic/cef_macos -g -arch x86_64 -mmacosx-version-min=10.7   -
fno-strict-aliasing -fstack-protector -funwind-tables -fvisibility=hidden -Wall -Werror -Wextra -Wendif-labels -Wnewline-eof -Wno-missing-field-initializers -Wno-unused-parameter -mmacosx-version-min=10.7 -fno-exceptions -fno-rtti -fno-threadsafe-static
s -fobjc-call-cxx-cdtors -fvisibility-inlines-hidden -std=gnu++11 -Wno-narrowing -Wsign-compare -O0 -g -MD -MT cefclient/CMakeFiles/cefclient.dir/browser/root_window_mac.mm.o -MF cefclient/CMakeFiles/cefclient.dir/browser/root_window_mac.mm.o.d -o cefcl
ient/CMakeFiles/cefclient.dir/browser/root_window_mac.mm.o -c /Users/martinsb/scratch/cefgenpic/cefgenpic/cefclient/browser/root_window_mac.mm

where /Users/martinsb/scratch/cefgenpic/cef_macos is actually environment variable $CEF_ROOT (where CEF framework has been unarchived). Since I copied cefclient project from $CEF_ROOT, the includes remained the same, like
Code: Select all
#include "cefclient/browser/client_types.h"
.
This means that all the include files were taken from my CEF directory (where the original cefclient project still remained) thanks to that "-I/Users/[...]/cef_macos" flag and my newly added files therefore were not visible.
As I mentioned in my previous post, adding something like
Code: Select all
include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR})
to my copied cefclient project fixes this.
To make things less confusing I'll remove all the "cefclient" prefixes to my #includes.

Thanks everyone again for looking into this.
martinsb
Newbie
 
Posts: 4
Joined: Sat Feb 11, 2017 5:32 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 54 guests