Skip to content

Commit

Permalink
CMake updates (#302)
Browse files Browse the repository at this point in the history
* Add BUILD_SHARED_LIBS option to choose between shared and static lib

* Fix build break for Android aarch64

* Install built target

* Set the correct version number

* Don't add include dirs through CFlags. Include dirs are already set as target property

* Install all relevant headers, not just from include dir

* Update note about BUILD_SHARED_LIBS in README.md

* Fix mistake in README.md, option(BUILD_SHARED_LIBS ON) sets the lib to shared by default
  • Loading branch information
ViliusSutkus89 authored Jun 19, 2024
1 parent d9f2b0f commit 87e5f0b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
cmake_minimum_required(VERSION 3.25)

project(openlibm
VERSION 0.8.0
VERSION 0.8.2
LANGUAGES C ASM)

add_library("${PROJECT_NAME}" SHARED)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

add_library("${PROJECT_NAME}")

# Find the relevant folder depending on the architecture
set(OPENLIBM_ARCH_FOLDER ${CMAKE_SYSTEM_PROCESSOR})
string(TOLOWER "${OPENLIBM_ARCH_FOLDER}" OPENLIBM_ARCH_FOLDER)

if(${OPENLIBM_ARCH_FOLDER} STREQUAL "amd64" OR ${OPENLIBM_ARCH_FOLDER} STREQUAL "x86_64")
set(OPENLIBM_ARCH_FOLDER "amd64")
elseif(${OPENLIBM_ARCH_FOLDER} MATCHES "arm64")
elseif(${OPENLIBM_ARCH_FOLDER} STREQUAL "arm64" OR ${OPENLIBM_ARCH_FOLDER} STREQUAL "aarch64")
set(OPENLIBM_ARCH_FOLDER "aarch64")
elseif(${OPENLIBM_ARCH_FOLDER} STREQUAL "x86")
set(OPENLIBM_ARCH_FOLDER "i387")
Expand Down Expand Up @@ -51,13 +52,6 @@ if(OPENLIBM_SUPPRESS_WARNINGS)
list(APPEND C_ASM_COMPILE_FLAGS "-w")
endif()

list(APPEND C_ASM_COMPILE_FLAGS
"-I${PROJECT_SRC}"
"-I${PROJECT_SRC}/include"
"-I${PROJECT_SRC}/${OPENLIBM_ARCH_FOLDER}"
"-I${PROJECT_SRC}/src"
)

# Add compile flags
target_compile_options("${PROJECT_NAME}" PUBLIC ${C_ASM_COMPILE_FLAGS})

Expand Down Expand Up @@ -547,3 +541,7 @@ else()
endif()

target_include_directories("${PROJECT_NAME}" PUBLIC ${OPENLIBM_INCLUDE_DIRS})

file(GLOB PUBLIC_HEADERS "*.h" "include/*.h" "${OPENLIBM_ARCH_FOLDER}/*.h" "src/*.h")
set_target_properties("${PROJECT_NAME}" PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
install (TARGETS "${PROJECT_NAME}")
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ qemu-$ARCH-static -L . -L /usr/$TRIPLE/ test/test-double
or generate project with build system of choice e.g. `cmake /path/to/openlib/ -G "MinGW Makefiles"`.
3. Build with the build system with `cmake --build .`.

Default CMake configuration builds a shared library, this can easily be changed by replacing
the keyword in the `add_library()` command in the `CMakeLists.txt`.
Default CMake configuration builds a shared library, this can easily be configured using
[BUILD_SHARED_LIBS](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html)
configuration option.


## Acknowledgements
Expand Down

0 comments on commit 87e5f0b

Please sign in to comment.