Skip to content

Commit deb8377

Browse files
authored
Specialized target defaults (#86)
1 parent 10cb0a4 commit deb8377

File tree

9 files changed

+62
-176
lines changed

9 files changed

+62
-176
lines changed

buildcc/lib/target/include/target/target.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Target {
9191
const fs::path &absolute_output_path);
9292

9393
// * Headers
94-
void AddHeader(const std::string &relative_filename,
94+
void AddHeader(const fs::path &relative_filename,
9595
const fs::path &relative_to_target_path = "");
9696
void AddHeaderAbsolute(const fs::path &absolute_filepath);
9797

buildcc/lib/target/src/target/include_dir.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void Target::AddHeaderAbsolute(const fs::path &absolute_filepath) {
3232
internal::add_path(absolute_filepath, current_header_files_);
3333
}
3434

35-
void Target::AddHeader(const std::string &relative_filename,
35+
void Target::AddHeader(const fs::path &relative_filename,
3636
const fs::path &relative_to_target_path) {
3737
env::log_trace(name_, __FUNCTION__);
3838

buildcc/targets/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
set(TARGET_SPECIALIZED_SRCS
2-
include/targets/target_constants.h
32
include/targets/target_gcc.h
43
include/targets/target_msvc.h
54
include/targets/target_generic.h
65
include/targets/target_custom.h
7-
include/targets/target_utils.h
86
)
97

108
if(${BUILDCC_BUILD_AS_SINGLE_LIB})

buildcc/targets/include/targets/target_constants.h

Lines changed: 0 additions & 70 deletions
This file was deleted.

buildcc/targets/include/targets/target_custom.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#ifndef TARGETS_TARGET_CUSTOM_H_
1818
#define TARGETS_TARGET_CUSTOM_H_
1919

20-
#include "target_constants.h"
21-
#include "target_utils.h"
22-
2320
namespace buildcc {
2421

2522
class Target_custom : public base::Target {
@@ -28,8 +25,7 @@ class Target_custom : public base::Target {
2825
const base::Toolchain &toolchain,
2926
const std::filesystem::path &target_path_relative_to_root,
3027
std::string_view compile_command, std::string_view link_command)
31-
: Target(Name(name, type, toolchain), type, toolchain,
32-
target_path_relative_to_root) {
28+
: Target(name, type, toolchain, target_path_relative_to_root) {
3329
compile_command_ = compile_command;
3430
link_command_ = link_command;
3531
}

buildcc/targets/include/targets/target_gcc.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,30 @@
1919

2020
#include "target/target.h"
2121

22-
#include "target_constants.h"
23-
2422
// TODO, Combine all of these into Target_gcc
2523
namespace buildcc {
2624

25+
// Extensions
26+
constexpr std::string_view kGccStaticLibExt = ".a";
27+
constexpr std::string_view kGccDynamicLibExt = ".so";
28+
29+
// GCC
30+
constexpr std::string_view kGccPrefixIncludeDir = "-I";
31+
constexpr std::string_view kGccPrefixLibDir = "-L";
32+
constexpr std::string_view kGccGenericCompileCommand =
33+
"{compiler} {preprocessor_flags} {include_dirs} {compile_flags} -o "
34+
"{output} -c {input}";
35+
constexpr std::string_view kGccExecutableLinkCommand =
36+
"{cpp_compiler} {link_flags} {compiled_sources} -o {output} "
37+
"{lib_dirs} {lib_deps}";
38+
constexpr std::string_view kGccStaticLibLinkCommand =
39+
"{archiver} rcs {output} {compiled_sources}";
40+
constexpr std::string_view kGccDynamicLibCompileCommand =
41+
"{compiler} {preprocessor_flags} {include_dirs} {compile_flags} "
42+
"-fpic -o {output} -c {input}";
43+
constexpr std::string_view kGccDynamicLibLinkCommand =
44+
"{cpp_compiler} -shared {link_flags} {compiled_sources} -o {output}";
45+
2746
class ExecutableTarget_gcc : public base::Target {
2847
public:
2948
ExecutableTarget_gcc(

buildcc/targets/include/targets/target_generic.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
#include "target_gcc.h"
2323
#include "target_msvc.h"
2424

25-
#include "target_constants.h"
26-
#include "target_utils.h"
27-
2825
namespace buildcc {
2926

3027
struct SyncTargetOptions {
@@ -189,7 +186,8 @@ class Target_generic : public base::Target {
189186
env::assert_fatal(false, "Compiler ID not supported");
190187
break;
191188
}
192-
SyncTargets(*this, *target, {
189+
SyncTargets(*this, *target,
190+
{
193191
.c_compile_flags_ = true,
194192
.cpp_compile_flags_ = true,
195193
.link_flags_ = true,

buildcc/targets/include/targets/target_msvc.h

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,39 @@
1919

2020
#include "target/target.h"
2121

22-
#include "target_constants.h"
23-
2422
// TODO, Combine all of these into Target_msvc
2523
namespace buildcc {
2624

27-
inline void DefaultMsvcFlags(base::Target &target) {
25+
// MSVC Constants
26+
constexpr std::string_view kMsvcExecutableExt = ".exe";
27+
constexpr std::string_view kMsvcStaticLibExt = ".lib";
28+
// Why is `kWinDynamicLibExt != .dll` but `.lib` instead?
29+
// See `kMsvcDynamicLibLinkCommand`
30+
// IMPLIB .lib stubs are what is linked during link time
31+
// OUT .dll needs to be present in the executable folder during runtime
32+
constexpr std::string_view kMsvcDynamicLibExt = ".lib";
33+
34+
constexpr std::string_view kMsvcObjExt = ".obj";
35+
constexpr std::string_view kMsvcPrefixIncludeDir = "/I";
36+
constexpr std::string_view kMsvcPrefixLibDir = "/LIBPATH:";
37+
// TODO, Split this into individual CompileCommands if any differences occur
38+
constexpr std::string_view kMsvcCompileCommand =
39+
"{compiler} {preprocessor_flags} {include_dirs} {compile_flags} "
40+
"/Fo{output} /c {input}";
41+
constexpr std::string_view kMsvcExecutableLinkCommand =
42+
"{linker} {link_flags} {lib_dirs} /OUT:{output} {lib_deps} "
43+
"{compiled_sources}";
44+
constexpr std::string_view kMsvcStaticLibLinkCommand =
45+
"{archiver} {link_flags} /OUT:{output} {compiled_sources}";
46+
constexpr std::string_view kMsvcDynamicLibLinkCommand =
47+
"{linker} /DLL {link_flags} /OUT:{output}.dll /IMPLIB:{output} "
48+
"{compiled_sources}";
49+
50+
inline void DefaultMsvcOptions(base::Target &target) {
51+
target.obj_ext_ = kMsvcObjExt;
52+
target.prefix_include_dir_ = kMsvcPrefixIncludeDir;
53+
target.prefix_lib_dir_ = kMsvcPrefixLibDir;
54+
2855
target.AddCCompileFlag("/nologo");
2956
target.AddCppCompileFlag("/nologo");
3057
target.AddCppCompileFlag("/EHsc"); // TODO, Might need to remove this
@@ -38,11 +65,10 @@ class ExecutableTarget_msvc : public base::Target {
3865
const std::filesystem::path &target_path_relative_to_root)
3966
: Target(name, base::TargetType::Executable, toolchain,
4067
target_path_relative_to_root) {
41-
prefix_include_dir_ = kMsvcPrefixIncludeDir;
42-
prefix_lib_dir_ = kMsvcPrefixLibDir;
68+
target_ext_ = kMsvcExecutableExt;
4369
compile_command_ = kMsvcCompileCommand;
4470
link_command_ = kMsvcExecutableLinkCommand;
45-
DefaultMsvcFlags(*this);
71+
DefaultMsvcOptions(*this);
4672
}
4773
};
4874

@@ -52,11 +78,10 @@ class StaticTarget_msvc : public base::Target {
5278
const std::filesystem::path &target_path_relative_to_root)
5379
: Target(name, base::TargetType::StaticLibrary, toolchain,
5480
target_path_relative_to_root) {
55-
prefix_include_dir_ = kMsvcPrefixIncludeDir;
56-
prefix_lib_dir_ = kMsvcPrefixLibDir;
81+
target_ext_ = kMsvcStaticLibExt;
5782
compile_command_ = kMsvcCompileCommand;
5883
link_command_ = kMsvcStaticLibLinkCommand;
59-
DefaultMsvcFlags(*this);
84+
DefaultMsvcOptions(*this);
6085
}
6186
};
6287

@@ -66,11 +91,10 @@ class DynamicTarget_msvc : public base::Target {
6691
const std::filesystem::path &target_path_relative_to_root)
6792
: Target(name, base::TargetType::DynamicLibrary, toolchain,
6893
target_path_relative_to_root) {
69-
prefix_include_dir_ = kMsvcPrefixIncludeDir;
70-
prefix_lib_dir_ = kMsvcPrefixLibDir;
94+
target_ext_ = kMsvcDynamicLibExt;
7195
compile_command_ = kMsvcCompileCommand;
7296
link_command_ = kMsvcDynamicLibLinkCommand;
73-
DefaultMsvcFlags(*this);
97+
DefaultMsvcOptions(*this);
7498
}
7599
};
76100

buildcc/targets/include/targets/target_utils.h

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)