Im able to create a .so file with tensorflow / bazel but without cuda. If i try bazel build -c opts --config=cuda :lib.so i get an undefined reference to main(..). Would there be a way to get rid of the errors referring to main (...) ?
Here is my BUILD file
cc_binary(
name = "lib.so",
srcs = [
"lib.cc",
"jni.h",
"jni_md.h",
"lib.h",
"jni_utils.h", "jni_utils.cc"
],
copts = tf_copts(),
linkopts = ["-shared"],
deps = [
"//tensorflow/core:tensorflow",
"//tensorflow/core:framework",
"//tensorflow/cc:cc_ops",
"//tensorflow/core:all_kernels",
"#opencv//:opencv"
],
)
Im getting these errors:
failed: crosstool_wrapper_driver_is_not_gcc failed: error executing command
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Turns out you just need to set linkshared = 1 onto the BUILD
cc_binary(
name = "lib.so",
srcs = [
"lib.cc",
"jni.h",
"jni_md.h",
"lib.h",
"jni_utils.h", "jni_utils.cc"
],
copts = tf_copts(),
linkshared = 1,
deps = [
"//tensorflow/core:tensorflow",
"//tensorflow/core:framework",
"//tensorflow/cc:cc_ops",
"//tensorflow/core:all_kernels",
"#opencv//:opencv"
],
)
Related
Edit (2022-05-28): for anyone who ends up here from searching for bazel + sfml, I gave up on trying to compile it from source with bazel.
Instead, I installed SFML with brew. Then in WORKSPACE.bazel:
new_local_repository(
name = "SFML",
path = "/opt/homebrew",
build_file = "third_party/SFML/BUILD.bazel"
)
and third_party/SFML/BUILD.bazel:
cc_library(
name = "sfml",
srcs = glob(["lib/libsfml-*.dylib"]),
hdrs = glob(["include/SFML/**/*.*"]),
include_prefix = "SFML",
strip_include_prefix = "include/SFML",
visibility = ["//visibility:public"],
)
finally, as a dependency in any BUILD.bazel:
cc_binary(
name = "main",
srcs = ["main.cc"],
deps = [
"#SFML//:sfml",
]
)
This allows me to #include <SFML/Graphics.hpp> for example in main.cc and so far it's working.
I'm trying to use bazel to build SFML from source and use it in a project. Right now I have a very simple setup:
foo/
src/
main.cc
BUILD
third_party/
SFML/
...
BUILD
BUILD
WORKSPACE
# third_party/SFML/BUILD
load("#rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "sfml",
srcs = glob(["src/*.cpp"]),
hdrs = glob(["include/*.hpp"]),
copts = ["-Ithird_party/SFML/include"],
linkopts = [
"-lsfml‑system",
"-lsfml‑window",
"-lsfml‑graphics",
"-lsfml‑audio",
],
visibility = ["//visibility:public"]
)
# src/BUILD
load("#rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "mygame",
srcs = ["main.cc"],
deps = [
"//third_party/SFML:sfml",
],
)
and main.cc:
#include "third_party/SFML/sfml/Graphics.hpp"
#include "third_party/SFML/sfml/System.hpp"
#include "third_party/SFML/sfml/Window.hpp"
int main() {
// ...
}
When I run bazel build //src:mygame I get an error:
fatal error: 'third_party/SFML/Graphics.hpp' file not found
I also tried using #include "third_party/SFML/Graphics.hpp" but that doesn't work either.
Not sure what the correct include path needs to be. Any suggestions?
I trying to test "Hello World" C++ project with Bazel.
I have the following project structure:
WORKSPACE
/dependencies
BUILD
BUILD.gtest
/test
BUILD
WORKSPACE has the following structure:
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# gtest
http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.10.0.zip",
sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91",
build_file = "#//dependencies:BUILD.gtest",
strip_prefix = "googletest-release-1.10.0",
)
BUILD.gtest has the following structure:
cc_library(
name = "main",
srcs = glob(
["src/*.cc"],
exclude = ["src/gtest-all.cc"]
),
hdrs = glob([
"include/**/*.h",
"src/*.h"
]),
copts = ["-Iexternal/gtest/include"],
linkopts = ["-pthread"],
visibility = ["//visibility:public"],
)
test BUILD has the following structure:
cc_test(
name = "unittests",
srcs = ["scanner_test.cc"],
copts = ["-Iexternal/gtest/include"],
deps = [
"//scanner:scanner",
"#gtest//:main"
]
)
when I execute
bazel build //test:unittests
I get
INFO: Analyzed target //test:unittests (26 packages loaded, 315 targets configured).
INFO: Found 1 target...
ERROR: ../test/BUILD:1:8: Compiling test/scanner_test.cc failed: (Exit 1): gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 25 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
test/scanner_test.cc:1:10: fatal error: gtest/gtest.h: No such file or directory
1 | #include "gtest/gtest.h"
| ^~~~~~~~~~~~~~~
compilation terminated.
Target //test:unittests failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2.314s, Critical Path: 0.08s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
As the other answer mentions:
The file BUILD.gtest is not needed.
Because gtest repo / release archive already provides one.
The reason why your own didn't behave as you might have expected is you've tried to point to the headers by manipulating copts which is applied only to building that one specific cc_library target (from linked docs):
The flags take effect only for compiling this target, not its dependencies, so be careful about header files included elsewhere.
Whereas to expose these interfaces to other targets consuming it you need to use includes (docs again):
Unlike COPTS, these flags are added for this rule and every rule that depends on it.
The file BUILD.gtest is not needed.
WORKSPACE.bazel:
workspace(name = "GTestDemo")
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.10.0.tar.gz",
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
strip_prefix = "googletest-release-1.10.0",
)
BUILD.bazel:
cc_test(
name = "tests",
srcs = ["test.cpp"],
deps = [
"#gtest//:gtest",
"#gtest//:gtest_main",
],
)
test.cpp:
#include <iostream>
#include <fstream>
#include "gtest/gtest.h"
using namespace std;
TEST(sample_test_case, sample_test) {
EXPECT_EQ(1, 1);
}
Tested with Bazel 4.1.0.
I need to build my own toolchain with Bazel, and I would like to force Bazel to use the g++ compiler of mingw64. I am following the instruction in https://docs.bazel.build/versions/master/tutorial/cc-toolchain-config.html trying to adapt them to my Windows 10 machine.
Bazel is able to compile my Hello-world.cc and create the hello-world.exe, and if I run
bazel-bin/main/hello-world
I get the right output.
Nevertheless, Bazel throws the following errors:
bazel build --config=mingw64_config -s //main:hello-world --verbose_failures
Starting local Bazel server and connecting to it...
INFO: Analyzed target //main:hello-world (15 packages loaded, 47 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # //main:hello-world [action 'Compiling main/hello-world.cc', configuration: e711ec75bfc5b6e1d77ea144cef912e655797b748714c6396a6b8cd3625eebee, execution platform: #local_config_platform//:host]
cd C:/users/_bazel_user/bcge3shs/execroot/__main__
SET PATH=c:\tools\msys64\usr\bin;c:\tools\msys64\bin;C:\WINDOWS;C:\WINDOWS\System32;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Haskell\bin;C:\Program Files\Haskell Platform\8.6.5\lib\extralibs\bin;C:\Program Files\Haskell Platform\8.6.5\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Haskell Platform\8.6.5\mingw\bin;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\TortoiseSVN\bin;C:\Users\Documents\Bazel\bazel_binary;C:\mingw64\bin;C:\Users\AppData\Roaming\cabal\bin;C:\Users\AppData\Roaming\local\bin;C:\Users\AppData\Local\Microsoft\WindowsApps;C:\Program Files\LLVM\bin
SET PWD=/proc/self/cwd
SET RUNFILES_MANIFEST_ONLY=1
C:/mingw64/bin/g++ -MD -MF bazel-out/x64_windows-fastbuild/bin/main/_objs/hello-world/hello-world.d -frandom-seed=bazel-out/x64_windows-fastbuild/bin/main/_objs/hello-world/hello-world.o -iquote . -iquote bazel-out/x64_windows-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/x64_windows-fastbuild/bin/external/bazel_tools -c main/hello-world.cc -o bazel-out/x64_windows-fastbuild/bin/main/_objs/hello-world/hello-world.o
SUBCOMMAND: # //main:hello-world [action 'Linking main/hello-world', configuration: e711ec75bfc5b6e1d77ea144cef912e655797b748714c6396a6b8cd3625eebee, execution platform: #local_config_platform//:host]
cd C:/users/_bazel_user/bcge3shs/execroot/__main__
SET PATH=c:\tools\msys64\usr\bin;c:\tools\msys64\bin;C:\WINDOWS;C:\WINDOWS\System32;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Haskell\bin;C:\Program Files\Haskell Platform\8.6.5\lib\extralibs\bin;C:\Program Files\Haskell Platform\8.6.5\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Haskell Platform\8.6.5\mingw\bin;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\TortoiseSVN\bin;C:\Users\Documents\Bazel\bazel_binary;C:\mingw64\bin;C:\Users\AppData\Roaming\cabal\bin;C:\Users\AppData\Roaming\local\bin;C:\Users\AppData\Local\Microsoft\WindowsApps;C:\Program Files\LLVM\bin
SET PWD=/proc/self/cwd
SET RUNFILES_MANIFEST_ONLY=1
C:/mingw64/bin/g++ -o bazel-out/x64_windows-fastbuild/bin/main/hello-world bazel-out/x64_windows-fastbuild/bin/main/_objs/hello-world/hello-world.o -Wl,-S -lstdc++
ERROR: C:/users/documents/bazel/mingw64__compiler/main/BUILD:3:10: output 'main/hello-world' was not created
ERROR: C:/users/documents/bazel/mingw64__compiler/main/BUILD:3:10: not all outputs were created or valid
Target //main:hello-world failed to build
INFO: Elapsed time: 4.171s, Critical Path: 0.31s
INFO: 2 processes: 2 local.
FAILED: Build did NOT complete successfully
Below is my cc_toolchain_config.bzl:
# NEW
load("#bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
# NEW
load(
"#bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"feature",
"flag_group",
"flag_set",
"tool_path",
)
all_link_actions = [ # NEW
ACTION_NAMES.cpp_link_executable,
ACTION_NAMES.cpp_link_dynamic_library,
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
]
def _impl(ctx):
tool_paths = [
tool_path(
name = "gcc",
path = "C:/mingw64/bin/g++",
),
tool_path(
name = "ld",
path = "C:/mingw64/bin/ld",
),
tool_path(
name = "ar",
path = "C:/mingw64/bin/ar",
),
tool_path(
name = "cpp",
path = "C:/mingw64/bin/cpp",
),
tool_path(
name = "gcov",
path = "C:/mingw64/bin/gcov",
),
tool_path(
name = "nm",
path = "C:/mingw64/bin/nm",
),
tool_path(
name = "objdump",
path = "C:/mingw64/bin/objdump",
),
tool_path(
name = "strip",
path = "C:/mingw64/bin/strip",
),
]
features = [ # NEW
feature(
name = "default_linker_flags",
enabled = True,
flag_sets = [
flag_set(
actions = all_link_actions,
flag_groups = ([
flag_group(
flags = [
"-lstdc++",
],
),
]),
),
],
),
]
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
features = features, # NEW
cxx_builtin_include_directories = [
"C:/mingw64/include",
"C:/mingw64/x86_64-w64-mingw32/include",
"C:/mingw64/lib/gcc/x86_64-w64-mingw32/5.1.0/include-fixed",
"C:/mingw64/lib/gcc/x86_64-w64-mingw32/5.1.0/include",
"C:/mingw64/lib/gcc/x86_64-w64-mingw32/5.1.0",
],
toolchain_identifier = "local",
host_system_name = "local",
target_system_name = "local",
target_cpu = "x64_windows",
target_libc = "unknown",
compiler = "g++",
abi_version = "unknown",
abi_libc_version = "unknown",
tool_paths = tool_paths,
)
cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
Any suggestions on what the problem could be?
The answer to this question can be found here:
Mingw-w64 toolchain for Bazel (Ubuntu 20.04.1 )
It is sufficient to load: artifact_name_pattern from #bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl and set artifact_name_patterns attribute of cc_common.create_cc_toolchain_config_info():
artifact_name_patterns = [
artifact_name_pattern(
category_name = "executable",
prefix = "",
extension = ".exe",
),]
I've tried to compile a DLL using bazel for days.
I followed the example bazel build hoping to generate a DLL.
The BUILD file I used is as follow:
cc_binary(
name = "expdtctlib",
srcs = ["expdtctlib.cpp"],
deps = [
"//tensorflow/core:tensorflow",
],
linkshared = 1,
)
cc_binary(
name = "expdetect",
srcs = ["expdetect.cpp"],
data = [":expdtctlib.dll"],
deps = [
"//tensorflow/core:tensorflow",
],
)
I ran the command :
bazel build :expdetect
But an error said the "expdtctlib.dll" was missing.
Don't bazel first generate "expdtctlib.dll" and then compile "expdetect.cpp"?
Besides,I've tried to use a another way to build DLL.The BUILD file is as follow:
cc_library(
name = "ExpDetector",
srcs = ["ExpDetector.cc"],
hdrs = ["ExpDetector.h"],
deps = [
"//tensorflow/core:tensorflow",
],
)
cc_binary(
name = "expdetect",
srcs = ["expdetect.cc"],
deps = [
"//tensorflow/core:tensorflow",
":ExpDetector",
],
)
After a long time compiling,though a EXE file was output and ran well,I could only find .lib and .exp file but the .dll file.
Is there anyone successfully build DLL using bazel?I need your help please.
I modified two BUILD files as follow and it worked well!
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//examples:__pkg__"],
)
cc_binary(
name = "expdtctlib.dll",
srcs = ["expdtctlib.cc",
"expdtctlib.h"],
deps = [
"//tensorflow/core:tensorflow",
],
linkshared = 1,
)
cc_binary(
name = "expdetect",
srcs = ["expdetect.cc"],
data = [":expdtctlib.dll"],
deps = [
"//tensorflow/core:tensorflow",
],
)
The one below is in "//tensorflow".
exports_files(
[
"LICENSE",
"ACKNOWLEDGEMENTS",
],
)
package(default_visibility = ["//visibility:public"])
filegroup(
name = "srcs",
srcs = glob(["**"]) + [
"//tensorflow/tensorflow/detector0405:srcs",
],
)
I am not familiar with bazel and c++,but these modification work.I'll read Bazel Document to learn more.
I tried to compile CMakeLists.txt for my project through KDevelop.
This is the output in KDevelop
/home/gopichand/Desktop/subsurface/build> make -j2
-- Configuring done
-- Generating done
-- Build files have been written to: /home/gopichand/Desktop/subsurface/build
[ 1%] [ 2%] Automoc for target TestProfile
Automoc for target subsurface_corelib
[ 2%] [ 2%] Built target TestProfile_automoc
Built target subsurface_corelib_automoc
[ 3%] Automoc for target TestUnitConversion
[ 3%] Built target version
[ 3%] Built target TestUnitConversion_automoc
[ 3%] Built target link_marble_data
[ 4%] Automoc for target subsurface
[ 5%] Automoc for target subsurface_profile
[ 5%] Built target subsurface_automoc
[ 5%] Built target subsurface_profile_automoc
[ 6%] Automoc for target subsurface_generated_ui
[ 7%] Automoc for target subsurface_interface
[ 7%] Built target subsurface_generated_ui_automoc
[ 8%] [ 8%] Built target subsurface_interface_automoc
Automoc for target subsurface_statistics
AUTOMOC: warning: /home/gopichand/Desktop/subsurface/qt-ui/statistics/yearstatistics.cpp: file is empty
AUTOMOC: warning: /home/gopichand/Desktop/subsurface/qt-ui/statistics/statisticsbar.cpp: file is empty
AUTOMOC: warning: /home/gopichand/Desktop/subsurface/qt-ui/statistics/monthstatistics.cpp: file is empty
[ 8%] Built target subsurface_statistics_automoc
[ 26%] Built target subsurface_generated_ui
Scanning dependencies of target subsurface_corelib
[ 27%] Building C object CMakeFiles/subsurface_corelib.dir/save-git.c.o
[ 38%] Built target subsurface_profile
[ 39%] Building C object CMakeFiles/subsurface_corelib.dir/subsurfacestartup.c.o
Scanning dependencies of target subsurface_interface
[ 39%] Building CXX object CMakeFiles/subsurface_interface.dir/qt-ui/updatemanager.cpp.o
Linking CXX static library libsubsurface_corelib.a
[ 64%] Built target subsurface_corelib
[ 65%] Building CXX object CMakeFiles/subsurface_interface.dir/qt-ui/about.cpp.o
[ 66%] Building CXX object CMakeFiles/subsurface_interface.dir/qt-ui/mainwindow.cpp.o
[ 70%] Built target subsurface_statistics
[ 71%] Building CXX object CMakeFiles/subsurface_interface.dir/qt-ui/usersurvey.cpp.o
Linking CXX executable TestProfile
/usr/bin/ld: libsubsurface_corelib.a(parse-xml.c.o): undefined reference to symbol 'xmlCheckVersion##LIBXML2_2.4.30'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libxml2.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [TestProfile] Error 1
make[1]: *** [CMakeFiles/TestProfile.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Linking CXX static library libsubsurface_interface.a
[ 93%] Built target subsurface_interface
make: *** [all] Error 2
*** Failure: Exit code 2 ***
I searched all DSO related posts, but could not get what went wrong.
This is the CMakeLists.txt file I compiled using KDevelop.
project(Subsurface)
cmake_minimum_required(VERSION 2.8)
#options
SET(SUBSURFACE_QT_VERSION "4")
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTOUIC ON)
SET(CMAKE_MODULE_PATH ${${PROJECT_NAME}_SOURCE_DIR}/marbledata)
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 ")
endif()
INCLUDE_DIRECTORIES( . ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR} qt-ui qt-ui/profile)
FIND_PACKAGE(PkgConfig)
MACRO(pkg_config_library LIBNAME pcfile)
pkg_check_modules(${LIBNAME} ${pcfile})
include_directories(${${LIBNAME}_INCLUDE_DIRS})
link_directories(${${LIBNAME}_LIBRARY_DIRS})
add_definitions(${${LIBNAME}_CFLAGS_OTHER})
set(SUBSURFACE_LINK_LIBRARIES ${SUBSURFACE_LINK_LIBRARIES} ${${LIBNAME}_LIBRARIES})
ENDMACRO()
pkg_config_library(LIBXML libxml-2.0)
pkg_config_library(LIBSQLITE3 sqlite3)
pkg_config_library(LIBGIT2 libgit2)
pkg_config_library(LIBXSLT libxslt)
SET(LIBDCDEVEL "" CACHE STRING "libraries")
IF(NOT (LIBDCDEVEL STREQUAL ""))
cmake_policy(SET CMP0015 OLD)
include_directories(${LIBDCDEVEL}/include )
link_directories(${LIBDCDEVEL}/src/.libs)
ENDIF()
STRING(COMPARE EQUAL "${${PROJECT_NAME}_SOURCE_DIR}" "${${PROJECT_NAME}_BINARY_DIR}" insource)
GET_FILENAME_COMPONENT(PARENTDIR ${${PROJECT_NAME}_SOURCE_DIR} PATH)
STRING(COMPARE EQUAL "${${PROJECT_NAME}_SOURCE_DIR}" "${PARENTDIR}" insourcesubdir)
IF(NOT (insource OR insourcedir))
add_custom_target(link_marble_data ALL COMMAND rm -f marbledata && ln -s ${${PROJECT_NAME}_SOURCE_DIR}/marbledata ${${PROJECT_NAME}_BINARY_DIR}/marbledata)
ENDIF()
#configure Qt version.
IF(${SUBSURFACE_QT_VERSION} MATCHES "4")
SET(QT_USE_QTNETWORK TRUE)
SET(QT_USE_QTXML TRUE)
SET(QT_USE_QTSVG TRUE)
SET(QT_USE_QTTEST TRUE)
SET(QT_USE_QTWEBKIT TRUE)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
FIND_PACKAGE(Marble REQUIRED)
INCLUDE_DIRECTORIES(${MARBLE_INCLUDE_DIR})
ELSEIF(${SUBSURFACE_QT_VERSION} MATCHES "5")
ADD_DEFINITIONS(-DNO_MARBLE)
ELSE()
message( FATAL_ERROR "Qt version should be 4 or 5" )
ENDIF()
# Generate the ssrf-config.h every 'make'
FILE(WRITE ${CMAKE_BINARY_DIR}/version.h.in "\#define VERSION_STRING \"4.1.\"#VERSION#\n")
FILE(WRITE ${CMAKE_BINARY_DIR}/version.cmake "EXECUTE_PROCESS(
COMMAND date +\"%s\"
OUTPUT_VARIABLE VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
CONFIGURE_FILE(\${SRC} \${DST} #ONLY)
")
ADD_CUSTOM_TARGET(version ALL COMMAND
${CMAKE_COMMAND} -D SRC=${CMAKE_BINARY_DIR}/version.h.in
-D DST=${CMAKE_BINARY_DIR}/ssrf-version.h
-P ${CMAKE_BINARY_DIR}/version.cmake
)
# compile the core library, in C.
SET(SUBSURFACE_CORE_LIB_SRCS
cochran.c
deco.c
device.c
dive.c
divelist.c
equipment.c
file.c
libdivecomputer.c
load-git.c
membuffer.c
parse-xml.c
planner.c
profile.c
gaspressures.c
worldmap-save.c
save-git.c
save-xml.c
save-html.c
sha1.c
statistics.c
strtod.c
subsurfacestartup.c
time.c
uemis.c
uemis-downloader.c
linux.c
#gettextfrommoc should be added because we are using it on the c-code.
gettextfromc.cpp
#dirk ported some core functionality to c++.
qthelper.cpp
divecomputer.cpp
exif.cpp
subsurfacesysinfo.cpp
devicedetails.cpp
configuredivecomputer.cpp
configuredivecomputerthreads.cpp
)
#the interface, in C++
SET(SUBSURFACE_INTERFACE
qt-ui/updatemanager.cpp
qt-ui/about.cpp
qt-ui/completionmodels.cpp
qt-ui/divecomputermanagementdialog.cpp
qt-ui/divelistview.cpp
qt-ui/diveplanner.cpp
qt-ui/diveshareexportdialog.cpp
qt-ui/downloadfromdivecomputer.cpp
qt-ui/globe.cpp
qt-ui/graphicsview-common.cpp
qt-ui/kmessagewidget.cpp
qt-ui/maintab.cpp
qt-ui/mainwindow.cpp
qt-ui/modeldelegates.cpp
qt-ui/models.cpp
qt-ui/metrics.cpp
qt-ui/preferences.cpp
qt-ui/printdialog.cpp
qt-ui/printlayout.cpp
qt-ui/printoptions.cpp
qt-ui/simplewidgets.cpp
qt-ui/starwidget.cpp
qt-ui/subsurfacewebservices.cpp
qt-ui/tableview.cpp
qt-ui/divelogimportdialog.cpp
qt-ui/tagwidget.cpp
qt-ui/groupedlineedit.cpp
qt-ui/usermanual.cpp
qt-ui/divelogexportdialog.cpp
qt-ui/divepicturewidget.cpp
qt-ui/usersurvey.cpp
qt-ui/configuredivecomputerdialog.cpp
)
#the profile widget
SET(SUBSURFACE_PROFILE_LIB_SRCS
qt-ui/profile/profilewidget2.cpp
qt-ui/profile/diverectitem.cpp
qt-ui/profile/divepixmapitem.cpp
qt-ui/profile/divelineitem.cpp
qt-ui/profile/divetextitem.cpp
qt-ui/profile/animationfunctions.cpp
qt-ui/profile/divecartesianaxis.cpp
qt-ui/profile/diveplotdatamodel.cpp
qt-ui/profile/diveprofileitem.cpp
qt-ui/profile/diveeventitem.cpp
qt-ui/profile/divetooltipitem.cpp
qt-ui/profile/ruleritem.cpp
qt-ui/profile/tankitem.cpp
)
#the yearly statistics widget.
SET(SUBSURFACE_STATISTICS_LIB_SRCS
qt-ui/statistics/statisticswidget.cpp
qt-ui/statistics/yearstatistics.cpp
qt-ui/statistics/statisticsbar.cpp
qt-ui/statistics/monthstatistics.cpp
)
#the main app.
SET(SUBSURFACE_APP
main.cpp
qt-gui.cpp
qthelper.cpp
)
FILE(GLOB SUBSURFACE_UI qt-ui/*.ui)
# to be replaced by QT_WRAP_UI on CMake 3.
IF(${SUBSURFACE_QT_VERSION} MATCHES "4")
QT4_WRAP_UI( SUBSURFACE_UI_HDRS ${SUBSURFACE_UI} )
QT4_ADD_RESOURCES( SUBSURFACE_QRC_HRDS subsurface.qrc )
ELSEIF(${SUBSURFACE_QT_VERSION} MATCHES "5")
QT5_WRAP_UI( SUBSURFACE_UI_HDRS ${SUBSURFACE_UI} )
ENDIF()
ADD_LIBRARY(subsurface_corelib STATIC ${SUBSURFACE_CORE_LIB_SRCS} )
ADD_LIBRARY(subsurface_profile STATIC ${SUBSURFACE_PROFILE_LIB_SRCS})
ADD_LIBRARY(subsurface_statistics STATIC ${SUBSURFACE_STATISTICS_LIB_SRCS})
ADD_LIBRARY(subsurface_generated_ui STATIC ${SUBSURFACE_UI_HDRS})
ADD_LIBRARY(subsurface_interface STATIC ${SUBSURFACE_INTERFACE})
ADD_EXECUTABLE(subsurface ${SUBSURFACE_APP} ${SUBSURFACE_QRC_HRDS} )
target_link_libraries( subsurface
subsurface_generated_ui
subsurface_interface
subsurface_profile
subsurface_statistics
subsurface_corelib
${QT_LIBRARIES}
${MARBLE_LIBRARIES}
${SUBSURFACE_LINK_LIBRARIES}
-ldivecomputer
-lzip
)
ADD_DEPENDENCIES(subsurface_statistics subsurface_generated_ui)
ADD_DEPENDENCIES(subsurface_profile subsurface_generated_ui)
ADD_DEPENDENCIES(subsurface_interface subsurface_generated_ui)
ADD_DEPENDENCIES(subsurface_generated_ui version)
ADD_DEPENDENCIES(subsurface_corelib version)
ENABLE_TESTING()
ADD_EXECUTABLE( TestUnitConversion tests/testunitconversion.cpp )
TARGET_LINK_LIBRARIES( TestUnitConversion ${QT_LIBRARIES} ${SUBSURFACE_LINK_LIBRARIES} -lzip -ldivecomputer subsurface_corelib)
ADD_TEST( NAME TestUnitConversion COMMAND TestUnitConversion)
ADD_EXECUTABLE( TestProfile tests/testprofile.cpp )
TARGET_LINK_LIBRARIES( TestProfile ${QT_LIBRARIES} ${SUBSURFACE_LINK_LIBRARIES} -lzip -ldivecomputer subsurface_corelib)
ADD_TEST( NAME TestProfile COMMAND TestProfile)
Can someone please help me with this... :)