Forráskód Böngészése

[CMake] add WITH_* build options

Andy Li 7 éve
szülő
commit
9a6344922a
3 módosított fájl, 125 hozzáadás és 88 törlés
  1. 46 42
      CMakeLists.txt
  2. 46 8
      libs/CMakeLists.txt
  3. 33 38
      libs/sdl/CMakeLists.txt

+ 46 - 42
CMakeLists.txt

@@ -2,15 +2,16 @@ cmake_minimum_required(VERSION 3.1)
 
 cmake_policy(SET CMP0042 NEW)
 
-include(GNUInstallDirs)
-include(FindPkgConfig)
-
 if (WIN32)
     project(hashlink C CXX) # C++ required for directx
 else()
     project(hashlink C)
 endif()
 
+include(GNUInstallDirs)
+include(FindPkgConfig)
+include(CTest)
+
 # force Unicode over Multi-byte
 if (MSVC)
     add_definitions(-DUNICODE -D_UNICODE)
@@ -140,51 +141,54 @@ else()
     target_link_libraries(libhl m dl pthread)
 endif()
 
-#####################
-# hello.hl
+if (BUILD_TESTING)
 
-find_program(
-    HAXE_COMPILER
-    haxe
-)
+    #####################
+    # hello.hl
 
-add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
-    COMMAND ${HAXE_COMPILER} -hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl -cp ${CMAKE_SOURCE_DIR}/other/tests -main HelloWorld
-)
-add_custom_target(hello.hl ALL
-    DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
-)
+    find_program(
+        HAXE_COMPILER
+        haxe
+    )
 
-#####################
-# hello.c
+    add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
+        COMMAND ${HAXE_COMPILER} -hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl -cp ${CMAKE_SOURCE_DIR}/other/tests -main HelloWorld
+    )
+    add_custom_target(hello.hl ALL
+        DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
+    )
 
-add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.c
-    COMMAND ${HAXE_COMPILER} -hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.c -cp ${CMAKE_SOURCE_DIR}/other/tests -main HelloWorld
-)
-add_executable(hello
-    ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.c
-)
-set_target_properties(hello
-    PROPERTIES
-    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test
-)
-target_include_directories(hello
-    PRIVATE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test
-)
-target_link_libraries(hello
-    libhl
-)
+    #####################
+    # hello.c
 
-#####################
-# Tests
+    add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.c
+        COMMAND ${HAXE_COMPILER} -hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.c -cp ${CMAKE_SOURCE_DIR}/other/tests -main HelloWorld
+    )
+    add_executable(hello
+        ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.c
+    )
+    set_target_properties(hello
+        PROPERTIES
+        RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test
+    )
+    target_include_directories(hello
+        PRIVATE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test
+    )
+    target_link_libraries(hello
+        libhl
+    )
 
-include(CTest)
-add_test(NAME hello.hl
-    COMMAND hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
-)
-add_test(NAME hello
-    COMMAND hello
-)
+    #####################
+    # Tests
+
+    add_test(NAME hello.hl
+        COMMAND hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello.hl
+    )
+    add_test(NAME hello
+        COMMAND hello
+    )
+
+endif()
 
 #####################
 # Packaging

+ 46 - 8
libs/CMakeLists.txt

@@ -15,12 +15,50 @@ if(WIN32)
 	add_subdirectory(directx)
 endif()
 
-add_subdirectory(fmt)
+option(WITH_FMT "Build fmt.hdll." ON)
+if (WITH_FMT)
+    add_subdirectory(fmt)
+endif()
+
 # add_subdirectory(mesa)
-add_subdirectory(openal)
-add_subdirectory(sdl)
-add_subdirectory(sqlite)
-add_subdirectory(ssl)
-add_subdirectory(ui)
-add_subdirectory(uv)
-add_subdirectory(video)
+
+if(WIN32)
+    option(WITH_OPENAL "Build openal.hdll." ON)
+    if (WITH_OPENAL)
+        add_subdirectory(openal)
+    endif()
+endif()
+
+option(WITH_SDL "Build sdl.hdll." ON)
+if(WITH_SDL)
+    add_subdirectory(sdl)
+endif()
+
+option(WITH_SQLITE "Build sqlite.hdll." ON)
+if(WITH_SQLITE)
+    add_subdirectory(sqlite)
+endif()
+
+if(WIN32)
+    option(WITH_SSL "Build ssl.hdll." ON)
+    if(WITH_SSL)
+    add_subdirectory(ssl)
+    endif()
+endif()
+
+option(WITH_UI "Build ui.hdll." ON)
+if(WITH_UI)
+    add_subdirectory(ui)
+endif()
+
+option(WITH_UV "Build uv.hdll." ON)
+if(WITH_UV)
+    add_subdirectory(uv)
+endif()
+
+option(WITH_VIDEO "Build video.hdll." ON)
+if(WIN32)
+    if(WITH_VIDEO)
+        add_subdirectory(video)
+    endif()
+endif()

+ 33 - 38
libs/sdl/CMakeLists.txt

@@ -1,49 +1,44 @@
-option(WITH_SDL2 "Build SDL2 support." ON)
+if (WIN32)
+    set(SDL2_PATH ${INCLUDES_BASE_DIR}/sdl)
+endif()
+find_package(SDL2 REQUIRED)
 
-if (WITH_SDL2)
-    if (WIN32)
-        set(SDL2_PATH ${INCLUDES_BASE_DIR}/sdl)
-    endif()
-    find_package(SDL2 REQUIRED)
+add_library(sdl.hdll SHARED
+    sdl.c
+    gl.c
+)
+set_as_hdll(sdl)
+target_include_directories(sdl.hdll
+    PRIVATE
+    ${SDL2_INCLUDE_DIR}
+    ${INCLUDES_BASE_DIR}/gl
+)
+target_link_libraries(sdl.hdll
+    libhl
+    ${SDL2_LIBRARY}
+)
 
-    add_library(sdl.hdll SHARED
-        sdl.c
-        gl.c
+if(WIN32)
+    target_link_libraries(sdl.hdll
+        winmm
+        opengl32
     )
-    set_as_hdll(sdl)
+endif()
+
+if (APPLE)
+    find_package(OPENGL REQUIRED)
     target_include_directories(sdl.hdll
         PRIVATE
-        ${SDL2_INCLUDE_DIR}
-        ${INCLUDES_BASE_DIR}/gl
+        ${OPENGL_INCLUDE_DIR}
     )
     target_link_libraries(sdl.hdll
         libhl
-        ${SDL2_LIBRARY}
+        ${OPENGL_gl_LIBRARY}
     )
-
-    if(WIN32)
-        target_link_libraries(sdl.hdll
-            winmm
-            opengl32
-        )
-    endif()
-
-    if (APPLE)
-        find_package(OPENGL REQUIRED)
-        target_include_directories(sdl.hdll
-            PRIVATE
-            ${OPENGL_INCLUDE_DIR}
-        )
-        target_link_libraries(sdl.hdll
-            libhl
-            ${OPENGL_gl_LIBRARY}
-        )
-    endif()
+endif()
 
 
-    install(
-        TARGETS sdl.hdll
-        DESTINATION ${HDLL_DESTINATION}
-    )
-
-endif()
+install(
+    TARGETS sdl.hdll
+    DESTINATION ${HDLL_DESTINATION}
+)