add options to build static/shared libs
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.1)
project(flecs LANGUAGES C)
+option(FLECS_STATIC_LIBS "Build static flecs lib" ON)
option(FLECS_PIC "Compile static flecs lib with position-independent-code (PIC)" ON)
+option(FLECS_SHARED_LIBS "Build shared flecs lib" ON)
+
+if(NOT FLECS_STATIC_LIBS AND NOT FLECS_SHARED_LIBS)
+ message(FATAL_ERROR "At least one of FLECS_STATIC_LIBS or FLECS_SHARED_LIBS options must be enabled")
+endif()
# include utilities for compiler options and warnings
@@ -84,8 +90,10 @@ set(SRC
src/vector.c
src/world.c)
-# build the shared library
+set(FLECS_TARGETS "")
+# build the shared library
+if(FLECS_SHARED_LIBS)
add_library(flecs SHARED ${INC} ${SRC})
target_default_compile_options_c(flecs)
@@ -93,8 +101,11 @@ target_default_compile_warnings_c(flecs)
target_include_directories(flecs PUBLIC include)
-# build the static library
+ list(APPEND FLECS_TARGETS flecs)
+endif()
+# build the static library
+if(FLECS_STATIC_LIBS)
add_library(flecs_static STATIC ${INC} ${SRC})
target_default_compile_options_c(flecs_static)
@@ -107,6 +118,9 @@ endif()
target_include_directories(flecs_static PUBLIC include)
target_compile_definitions(flecs_static PUBLIC flecs_STATIC)
+ list(APPEND FLECS_TARGETS flecs_static)
+endif()
+
# define the install steps
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
@@ -115,8 +129,5 @@ install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
PATTERN "*.h"
PATTERN "*.hpp")
-install(TARGETS flecs
- DESTINATION lib)
-
-install(TARGETS flecs_static
+install(TARGETS ${FLECS_TARGETS}
DESTINATION lib)
