Skip to content

Commit

Permalink
[Enhancement] Add option to build as shared libraries (#67)
Browse files Browse the repository at this point in the history
Closes: #55

* feat: add option to build shared

* chore: make everything output into bin dir

* chore: fix ci

* chore: switch to MALLOY_LIBRARY_TYPE rather than malloy_add_library

* chore: fix mingw ci
  • Loading branch information
0x00002a committed Jul 14, 2021
1 parent 40fdc07 commit a104278
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ jobs:
run: cmake --build build

- name: Run tests
run: ./build/test/malloy-tests
run: ./build/bin/malloy-tests
2 changes: 1 addition & 1 deletion .github/workflows/msys2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ jobs:
run: cmake --build build

- name: Run tests
run: ./build/test/malloy-tests
run: ./build/bin/malloy-tests
24 changes: 18 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ project(
)

# Options
option(MALLOY_BUILD_SHARED "Whether to build as a shared library" OFF)
option(MALLOY_BUILD_EXAMPLES "Whether to build examples" ON)
option(MALLOY_BUILD_TESTS "Whether to build tests" ON)
option(MALLOY_FEATURE_CLIENT "Whether to build the client" ON)
Expand All @@ -16,6 +17,16 @@ option(MALLOY_FEATURE_HTML "Whether to enable HTML features" ON)
option(MALLOY_FEATURE_TLS "Whether to enable TLS features" OFF)
option(MALLOY_DEPENDENCY_SPDLOG_DOWNLOAD "Whether to automatically fetch spdlog" ON)


set(MALLOY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin) # Needed for later


if (MALLOY_BUILD_SHARED)
set(MALLOY_LIBRARY_TYPE SHARED)
else()
set(MALLOY_LIBRARY_TYPE STATIC)
endif()

# Set dependencies accordingly
if (MALLOY_FEATURE_TLS)
set(MALLOY_DEPENDENCY_OPENSSL ON)
Expand All @@ -39,12 +50,13 @@ message("")
message("---------------------")
message("Malloy configuration:")
message(" Build:")
message(" Examples : " ${MALLOY_BUILD_EXAMPLES})
message(" Tests : " ${MALLOY_BUILD_TESTS})
message(" Examples : " ${MALLOY_BUILD_EXAMPLES})
message(" Tests : " ${MALLOY_BUILD_TESTS})
message(" Library Type : " ${MALLOY_LIBRARY_TYPE})
message(" Features:")
message(" Client : " ${MALLOY_FEATURE_CLIENT})
message(" Server : " ${MALLOY_FEATURE_SERVER})
message(" HTML : " ${MALLOY_FEATURE_HTML})
message(" TLS : " ${MALLOY_FEATURE_TLS})
message(" Client : " ${MALLOY_FEATURE_CLIENT})
message(" Server : " ${MALLOY_FEATURE_SERVER})
message(" HTML : " ${MALLOY_FEATURE_HTML})
message(" TLS : " ${MALLOY_FEATURE_TLS})
message("---------------------")
message("")
2 changes: 2 additions & 0 deletions examples/client/example.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ function(malloy_example_setup_client target)
PRIVATE
malloy-client
)

set_target_properties(${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${MALLOY_BINARY_DIR})
endfunction()
2 changes: 2 additions & 0 deletions examples/server/example.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ function(malloy_example_setup target)
PRIVATE
malloy-server
)

set_target_properties(${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${MALLOY_BINARY_DIR})
endfunction()
2 changes: 1 addition & 1 deletion lib/malloy/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include("../target_setup.cmake")
set(TARGET "malloy-client")

# Create library
add_library(${TARGET} STATIC)
add_library(${TARGET} ${MALLOY_LIBRARY_TYPE})

# Apply common setup
malloy_target_common_setup(${TARGET})
Expand Down
2 changes: 1 addition & 1 deletion lib/malloy/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(../target_setup.cmake)
set(TARGET "malloy-core")

# Create library
add_library(${TARGET} STATIC)
add_library(${TARGET} ${MALLOY_LIBRARY_TYPE})

# Apply common setup
malloy_target_common_setup(${TARGET})
Expand Down
3 changes: 2 additions & 1 deletion lib/malloy/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ include(../target_setup.cmake)
set(TARGET "malloy-server")

# Create library
add_library(${TARGET} STATIC)
add_library(${TARGET} ${MALLOY_LIBRARY_TYPE})


# Apply common setup
malloy_target_common_setup(${TARGET})
Expand Down
6 changes: 6 additions & 0 deletions lib/malloy/target_setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ function(malloy_target_common_setup TARGET)
$<$<BOOL:${WIN32}>:wsock32>
$<$<BOOL:${WIN32}>:ws2_32>
)
set_target_properties(
${TARGET}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${MALLOY_BINARY_DIR}
LIBRARY_OUTPUT_DIRECTORY ${MALLOY_BINARY_DIR}
)
endfunction()
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ add_test(
NAME doctest
COMMAND ${TARGET}
)

set_target_properties(${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${MALLOY_BINARY_DIR})

0 comments on commit a104278

Please sign in to comment.