Skip to content
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

CMake configuration for Visual Studio #42

Merged
merged 30 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
125b3c2
Add base for VS project.
thomthom Feb 22, 2018
c9197f8
Add library src folder to source path.
thomthom Feb 22, 2018
2d36379
Add library files to project.
thomthom Feb 22, 2018
a85691d
Add SLAPI headers/libs for SU2018.
thomthom Feb 22, 2018
1ed1396
Reference SLAPI
thomthom Feb 22, 2018
4583416
Fix build errors.
thomthom Feb 22, 2018
cf6d8fd
Fix build warning.
thomthom Feb 22, 2018
9761bb7
Set up GoogleTest project.
thomthom Feb 22, 2018
62a8696
Base for Color tests.
thomthom Feb 22, 2018
0f81d3a
Add base for TypedValue tests.
thomthom Feb 22, 2018
f67133f
Move tests to their own folder.
thomthom Feb 22, 2018
c45c885
Fix googletest submodule.
thomthom Feb 23, 2018
f3ae814
Avoid returning NULL character from String::std_string. Fixes #37.
thomthom Feb 23, 2018
43859dd
Fix .submodules such that SourceTree can also open it.
thomthom Feb 23, 2018
d7f9c8f
Correct indentation in .gitmodules.
thomthom Feb 23, 2018
11395cc
Update VS project to reflect the new location of the headers.
thomthom Feb 23, 2018
b370f96
Update README with information on test setup.
thomthom Feb 23, 2018
7ba1bef
Adding tests for Radians (different behaviour from original) Ref #40.
thomthom Feb 23, 2018
89089d2
Correct Radians to original intent.
thomthom Feb 23, 2018
74b9368
Move the location of the Windows C API.
thomthom Feb 23, 2018
bf05c1a
Eliminate warnings, and treat them as errors. Fixes #41.
thomthom Feb 23, 2018
d99786f
Base for CMake solution. Stubbing tests project.
thomthom Feb 23, 2018
c837df6
GoogleTest Cmake static lib.
thomthom Feb 23, 2018
02b2c4c
Wrapper lib built as static lib via CMake.
thomthom Feb 23, 2018
2185612
More Radians tests to correct directory.
thomthom Feb 23, 2018
225e095
Fix test case names for Color class.
thomthom Feb 23, 2018
93351db
Put files into groups.
thomthom Feb 24, 2018
79c050c
Treat warnings as errors.
thomthom Feb 24, 2018
eba8b51
Remove the manually created VS solution.
thomthom Feb 24, 2018
2a38092
Restore Windows libs missing due to .gitignore.
thomthom Feb 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
Expand All @@ -24,7 +23,6 @@
*.lai
*.la
*.a
*.lib

# Executables
*.exe
Expand All @@ -41,10 +39,16 @@
ehthumbs.db
Thumbs.db

# Xcode
# Xcode
*.xcuserstate
*.xcodeproj/project.xcworkspace/
*.xcodeproj/xcuserdata/

# Project specific
# Visual Studio
.vs/
Debug/
Release/
*.vcxproj.user

# CMake
build/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third-party/googletest"]
path = third-party/googletest
url = https://github.com/google/googletest.git
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.8)

set(CMAKE_CXX_STANDARD 14)

project (SketchUpApiCppWrapper)

# Define various paths:

set(CPP_API_BASENAME "SUAPI-CppWrapper")
set(CPP_API_INCLUDE_PATH "${PROJECT_SOURCE_DIR}/include")
set(CPP_API_SOURCE_PATH "${PROJECT_SOURCE_DIR}/src")
set(CPP_API_TESTS_PATH "${PROJECT_SOURCE_DIR}/tests")

set(CPP_API_THIRD_PARTY_PATH "${PROJECT_SOURCE_DIR}/third-party")

# TODO(thomthom): Configure for Mac:
set(SLAPI_PATH "${CPP_API_THIRD_PARTY_PATH}/slapi")
set(SLAPI_INCLUDE_PATH "${SLAPI_PATH}/win/headers")
set(SLAPI_BINARIES_PATH "${SLAPI_PATH}/win/binaries")
set(SLAPI_BINARIES_X64_PATH "${SLAPI_BINARIES_PATH}/sketchup/x64")
# TODO(thomthom): Add library paths per platform, and try to add just "SketchUpAPI"
# to `target_link_libraries`.
set(SLAPI_LIB "${SLAPI_BINARIES_X64_PATH}/SketchUpAPI.lib")

set(GOOGLETEST_PATH "${CPP_API_THIRD_PARTY_PATH}/googletest/googletest")
set(GOOGLETEST_INCLUDE_PATH "${GOOGLETEST_PATH}/include")


# GoogleTest 1.8 produce a warning that must be silenced. The fix is yet to be
# pushed to the GoogleTest stable branch.
# warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1
# namespace and TR1-only machinery are deprecated and will be REMOVED. You can
# define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING to acknowledge that you
# have received this warning.
add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want this to apply to all of the folowing targets, or just GoogleTest? It should be appended to the GoogleTest.cmake file and made so it only acts on GoogleTest.

...
add_library(GoogleTest STATIC third-party/googletest/googletest/src/gtest-all.cc)
target_compile_definitions(GoogleTest PRIVATE -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could probably be omitted for the wrapper lib, but the Tests project also needs it as including the GoogleTest headers cause warnings also there.


# Avoid conflicting macros from Win32 API.
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DNOMINMAX)


include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SketchUpAPICpp.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GoogleTest.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SketchUpAPITests.cmake)
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,43 @@ Added to this benefit, the wrapper classes have helper functions to help with ge
The project is documented in Doxygen, accessible here:
https://tommykaneko.github.io/Sketchup-API-C-Wrapper/html

## CMake

### Visual Studio

```
CMake .. -G "Visual Studio 15 2017 Win64"
```

### XCode

Coming...

## Testing
The project uses GoogleTest for unit testing. It's included as a submodule so make sure to also initialize those when checking out the project.

The tests are located under `/tests/`. One file per testcase. One testcase per class being tested.

Keep tests small, keep their name descriptive.

### Running Tests

#### Visual Studio
1. Set the SketchUpAPITests project as your startup project.
2. Build
3. Run

Alternativly you can use the [Google Test Adapter extension](https://marketplace.visualstudio.com/items?itemName=ChristianSoltenborn.GoogleTestAdapter) which provides overview of the tests from the UI. Makes it easy to run induvidual tests.

#### Xcode
*Coming soon.*

### GoogleTests References
* https://github.com/google/googletest/blob/master/googlemock/docs/ForDummies.md
* https://github.com/google/googletest/blob/master/googletest/docs/Primer.md
* https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
* https://github.com/google/googletest/blob/master/googletest/docs/FAQ.md

======================
## Project Objectives

Expand Down
564 changes: 0 additions & 564 deletions SUAPI-CppWrapper.xcodeproj/project.pbxproj

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions cmake/GoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/third-party/googletest/googletest/include")
include_directories("${PROJECT_SOURCE_DIR}/third-party/googletest/googletest")

add_library(GoogleTest STATIC third-party/googletest/googletest/src/gtest-all.cc)
31 changes: 31 additions & 0 deletions cmake/SketchUpAPICpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# TODO(thomthom): Configure for Mac:
include_directories(SYSTEM "${SLAPI_INCLUDE_PATH}")
include_directories("${CPP_API_INCLUDE_PATH}")

file(GLOB_RECURSE CPP_API_HEADERS ${CPP_API_INCLUDE_PATH}/*.hpp)
file(GLOB_RECURSE CPP_API_SOURCES ${CPP_API_SOURCE_PATH}/*.cpp)

add_library(SketchUpAPICpp STATIC ${CPP_API_HEADERS} ${CPP_API_SOURCES})

# https://stackoverflow.com/a/14235055/486990
if ( MSVC )
# TODO(thomthom): Enable /W4 when the warnings it trigger is addressed.
# target_compile_options(SketchUpAPICpp PRIVATE "/W4")
target_compile_options(SketchUpAPICpp PRIVATE "/W3")
target_compile_options(SketchUpAPICpp PRIVATE "/WX")
target_compile_options(SketchUpAPICpp PRIVATE "/MP")
else()
# target_compile_options(SketchUpAPICpp PRIVATE "-Wall")
target_compile_options(SketchUpAPICpp PRIVATE "-Werror")
endif()

source_group(
TREE "${CPP_API_INCLUDE_PATH}/${CPP_API_BASENAME}"
PREFIX "Header Files"
FILES ${CPP_API_HEADERS}
)
source_group(
TREE "${CPP_API_SOURCE_PATH}/${CPP_API_BASENAME}"
PREFIX "Source Files"
FILES ${CPP_API_SOURCES}
)
29 changes: 29 additions & 0 deletions cmake/SketchUpAPITests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
include_directories("${CPP_API_TESTS_PATH}")
include_directories("${GOOGLETEST_INCLUDE_PATH}")

file(GLOB_RECURSE TESTS_HEADERS ${CPP_API_TESTS_PATH}/*.hpp)
file(GLOB_RECURSE TESTS_SOURCES ${CPP_API_TESTS_PATH}/*.cpp)

add_executable(SketchUpAPITests ${TESTS_HEADERS} ${TESTS_SOURCES})

target_link_libraries(SketchUpAPITests GoogleTest SketchUpAPICpp ${SLAPI_LIB})

set_target_properties(${SketchUpAPITests} PROPERTIES COMPILE_FLAGS "-Wall")

source_group(
"Tests"
REGULAR_EXPRESSION "${CPP_API_TESTS_PATH}/[^\//]+Tests.cpp"
)
# Force the CPP file that define `main` to not appear in the Tests list.
source_group(
"Source Files"
FILES "${CPP_API_TESTS_PATH}/SketchUpAPITests.cpp"
)

# TODO(thomthom): Set up per-platform post-build commands.
add_custom_command(TARGET SketchUpAPITests POST_BUILD
# xcopy seem to require at least one \ slash in the source path, otherwise it
# appear to fail.
COMMAND xcopy \"${SLAPI_BINARIES_PATH}\\sketchup\\x64\\SketchUpAPI.dll\" $(OutputPath) /D /Y
COMMAND xcopy \"${SLAPI_BINARIES_PATH}\\sketchup\\x64\\SketchUpCommonPreferences.dll\" $(OutputPath) /D /Y
)
1 change: 1 addition & 0 deletions include/SUAPI-CppWrapper/Geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Radians
public:
double m_val;
static constexpr double PI = 3.141592653589793;
static constexpr double PI2 = PI * 2;
// Estimate the degree of correctness of angles (Sketchup Tolerance is 1/1000", so try to make some sort of guess - suggest discrepancies of 1/1000" over radians rotations over 30m (approx 1000")
constexpr static double EPSILON = 0.0000000000005; // Sketchup Tolerance is 1/1000"

Expand Down
16 changes: 7 additions & 9 deletions src/SUAPI-CppWrapper/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ namespace CW {
*/
Radians::Radians(const double &rhs):
m_val(rhs)
{
if(rhs > (2*PI)) {
int numPi = rhs / (2*PI); // Get number of times 2pi fits in to rhs
m_val = rhs - (numPi*2*PI);
}
else if(rhs < 0.0) {
int numPi = (rhs / (2*PI)) - 1; // Get number of times 2pi fits in to rhs
m_val = rhs - (numPi*2*PI);
}
{
if(rhs > PI2) {
m_val = std::fmod(rhs, PI2);
}
else if(rhs < 0.0) {
m_val = PI2 - std::fmod(std::fabs(rhs), PI2);
}
}

// Copy constructor
Expand Down
6 changes: 3 additions & 3 deletions src/SUAPI-CppWrapper/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ std::string String::std_string() const {
size_t out_length = 0;
SUResult res = SUStringGetUTF8Length(m_string, &out_length);
assert(res == SU_ERROR_NONE);
out_length++; // Allow for null termianted string
std::vector<char> char_array(out_length);
out_length++; // Allow for null terminated string
std::vector<char> char_array(out_length, 0);
res = SUStringGetUTF8(m_string, out_length, char_array.data(), &out_length);
assert(res == SU_ERROR_NONE);
std::string str(char_array.begin(),char_array.end());
std::string str(char_array.data());
return str;
}

Expand Down
7 changes: 0 additions & 7 deletions src/SUAPI-CppWrapper/model/AttributeDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,6 @@ AttributeDictionary::operator SUAttributeDictionaryRef() const {
}


AttributeDictionary::operator SUAttributeDictionaryRef*() {
// TODO: test if the solution below works.
SUAttributeDictionaryRef dict = SUAttributeDictionaryFromEntity(m_entity);
return &dict;
}


TypedValue AttributeDictionary::get_attribute(const std::string &key, const TypedValue &default_value) const {
if (!(*this)) {
throw std::logic_error("CW::AttributeDictionary::get_attribute(): AttributeDictionary is null");
Expand Down
5 changes: 0 additions & 5 deletions src/SUAPI-CppWrapper/model/ComponentDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ SUComponentDefinitionRef ComponentDefinition::ref() const {
ComponentDefinition::operator SUComponentDefinitionRef() const {
return this->ref();
}
ComponentDefinition::operator SUComponentDefinitionRef*() {
// TODO: test if the solution below works.
SUComponentDefinitionRef definition = this->ref();
return &definition;
}


ComponentInstance ComponentDefinition::create_instance() const {
Expand Down
7 changes: 0 additions & 7 deletions src/SUAPI-CppWrapper/model/ComponentInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ ComponentInstance::operator SUComponentInstanceRef() const {
}


ComponentInstance::operator SUComponentInstanceRef*() {
// TODO: test if the solution below works.
SUComponentInstanceRef instance = this->ref();
return &instance;
}


Transformation ComponentInstance::transformation() const {
if (!(*this)) {
throw std::logic_error("CW::ComponentInstance::transformation(): ComponentInstance is null");
Expand Down
Loading