Title
#windows
Stefano Bonicatti

Stefano Bonicatti

08/02/2019, 7:10 PM
well it's not ready as is, but it should be along the lines of having
set(source_files 
"${CMAKE_CURRENT_BINARY_DIR}/empty_osqueryd_target_source_file.cpp"
${CMAKE_CURRENT_BINARY_DIR}/windows_resources.rc
)
[...]
configure_file(
${CMAKE_SOURCE_DIR}/tools/windows_resources.rc.in
${CMAKE_CURRENT_BINARY_DIR}/windows_resources.rc
@ONLY)
[...]
add_osquery_executable(osqueryd "${source_files}")
here: https://github.com/osquery/osquery/blob/c2fde72fa6c67083b7e56001d51054345977d809/osquery/CMakeLists.txt#L55
t

TonyC

08/27/2019, 10:32 PM
No Joy 😞 function(generateOsqueryd)

Upstream uses an empty executable that links to a library with a

a main() entry point; try to emulate this.

set(source_files "${CMAKE_CURRENT_BINARY_DIR}/empty_osqueryd_target_source_file.cpp" "${CMAKE_CURRENT_BINARY_DIR}/windows_resources.rc" ) generateBuildTimeSourceFile(${source_files} "extern int main(int argc, char* argv[]);") configure_file( ${CMAKE_SOURCE_DIR}/tools/windows_resources.rc.in ${CMAKE_CURRENT_BINARY_DIR}/windows_resources.rc @ONLY) add_osquery_executable(osqueryd "${source_files}") set_target_properties(osqueryd PROPERTIES POSITION_INDEPENDENT_CODE true) target_link_libraries(osqueryd PRIVATE global_cxx_settings osquery_main ) endfunction() C:\temp\osquery\osquery\build\osquery\empty_osqueryd_target_source_file.cpp(1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\temp\osquery\osquery\build\osquery\o squeryd.vcxproj] C:\temp\osquery\osquery\build\osquery\empty_osqueryd_target_source_file.cpp(1): error C2059: syntax error: ':' [C:\temp\osquery\osquery\build\osquery\osqueryd.vcxproj] C:\temp\osquery\osquery\build\osquery\empty_osqueryd_target_source_file.cpp(1): error C2059: syntax error: '/' [C:\temp\osquery\osquery\build\osquery\osqueryd.vcxproj]
Stefano Bonicatti

Stefano Bonicatti

08/28/2019, 1:47 AM
One issue is that you're passing both files to generateBuildTimeSourceFile, only the
empty_osqueryd_target_source_file.cpp
one has to be passed, might want to do something like:
[...]
set(source_files  "${CMAKE_CURRENT_BINARY_DIR}/empty_osqueryd_target_source_file.cpp")
generateBuildTimeSourceFile(${source_files} "extern int main(int argc, char* argv[]);")
list(APPEND source_files "${CMAKE_CURRENT_BINARY_DIR}/windows_resources.rc")
[...]
1:48 AM
If you check that file in the build folder it will probably not contain
extern int main(int argc, char* argv[]);
, which it should
t

TonyC

08/28/2019, 4:16 AM
Ya, I forgot to post that the empty_osqueryd_target_source_file.cpp contained the string ../windows_resources.rc not extern int main(int argc, char* argv[]); I got busy trying to figure out how to make it work. I will continue to try different options. Thank you Stefano
5:18 AM
I have zero experience with cmake so I'm sure this is completely wrong, but it works 🙂 function(generateOsqueryd)

Upstream uses an empty executable that links to a library with a

a main() entry point; try to emulate this.

set(source_files "${CMAKE_CURRENT_BINARY_DIR}/empty_osqueryd_target_source_file.cpp") generateBuildTimeSourceFile(${source_files} "extern int main(int argc, char* argv[]);") list(APPEND source_files "${CMAKE_CURRENT_BINARY_DIR}/windows_resources.rc") list(APPEND source_files "${CMAKE_CURRENT_BINARY_DIR}/tools/wel") set(OSQUERY_PRODUCT_NUMBER 4) set(OSQUERY_PRODUCT_VERSION 0) set(OSQUERY_BUILD_NUMBER 0) configure_file( ${CMAKE_SOURCE_DIR}/tools/windows_resources.rc.in ${CMAKE_CURRENT_BINARY_DIR}/windows_resources.rc @ONLY) file(COPY "${CMAKE_SOURCE_DIR}/tools/wel" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/tools") add_osquery_executable(osqueryd "${source_files}") set_target_properties(osqueryd PROPERTIES POSITION_INDEPENDENT_CODE true) target_link_libraries(osqueryd PRIVATE global_cxx_settings osquery_main ) endfunction()
Stefano Bonicatti

Stefano Bonicatti

08/28/2019, 9:23 AM
to set the version you like (for instance 4.0.0), you can pass
-DOSQUERY_VERSION="4.0.0"
at the configure phase
t

TonyC

08/28/2019, 3:19 PM
That doesn't appear to work C:\temp\osquery\osquery\build\osquery\windows_resources.rc(26): error RC2127: version WORDs separated by commas expected [C:\temp\osquery\osquery\build\osquery\osqueryd.vcxproj]
3:20 PM
Generated rc file #define VER_FILEVERSION ,,,0 #define VER_FILEVERSION_STR ".0\0" #define VER_PRODUCTVERSION ,,,0 #define VER_PRODUCTVERSION_STR "\0"
Stefano Bonicatti

Stefano Bonicatti

08/28/2019, 3:26 PM
Yeah I'm sorry, that files has not been touched/corrected after Facebook refactor to Buck and the reintroduction of CMake
3:26 PM
It refers to variables that do not exist
t

TonyC

08/28/2019, 3:27 PM
no worries, I have a workaround. Hopefully sources will be fixed soon. Thx Sefano