Browse Source

Replace COMPILE_AS_SHARED_LIBRARY by the standard CMake BUILD_SHARED_LIBS (#518)

Jérôme Leclercq 2 years ago
parent
commit
292efe4453
3 changed files with 13 additions and 14 deletions
  1. 2 2
      .github/workflows/build.yml
  2. 1 1
      Build/CMakeLists.txt
  3. 10 11
      Jolt/Jolt.cmake

+ 2 - 2
.github/workflows/build.yml

@@ -47,7 +47,7 @@ jobs:
     - name: Checkout Code
       uses: actions/checkout@v3
     - name: Configure CMake
-      run: cmake -B ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=${{matrix.clang_version}} -DCOMPILE_AS_SHARED_LIBRARY=Yes Build
+      run: cmake -B ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=${{matrix.clang_version}} -DBUILD_SHARED_LIBS=Yes Build
     - name: Build
       run: cmake --build ${{github.workspace}}/Build/Linux_${{matrix.build_type}}_${{matrix.clang_version}} -j 2
     - name: Test
@@ -138,7 +138,7 @@ jobs:
     - name: Add msbuild to PATH
       uses: microsoft/[email protected]
     - name: Configure CMake
-      run: cmake -B ${{github.workspace}}/Build/VS2022_CL -G "Visual Studio 17 2022" -A x64 Build -DCOMPILE_AS_SHARED_LIBRARY=Yes
+      run: cmake -B ${{github.workspace}}/Build/VS2022_CL -G "Visual Studio 17 2022" -A x64 Build -DBUILD_SHARED_LIBS=Yes
     - name: Build
       run: msbuild Build\VS2022_CL\JoltPhysics.sln /property:Configuration=${{matrix.build_type}} -m
     - name: Test

+ 1 - 1
Build/CMakeLists.txt

@@ -15,7 +15,7 @@ option(CROSS_PLATFORM_DETERMINISTIC "Cross platform deterministic" OFF)
 option(CROSS_COMPILE_ARM "Cross compile to aarch64-linux-gnu" OFF)
 
 # When turning this option on, Jolt will be compiled as a shared library and public symbols will be exported.
-option(COMPILE_AS_SHARED_LIBRARY "Compile Jolt as a shared library" OFF)
+option(BUILD_SHARED_LIBS "Compile Jolt as a shared library" OFF)
 
 # When turning this option on, the library will be compiled with interprocedural optimizations enabled, also known as link-time optimizations or link-time code generation.
 # Note that if you turn this on you need to use SET_INTERPROCEDURAL_OPTIMIZATION() or set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) to enable LTO specificly for your own project as well.

+ 10 - 11
Jolt/Jolt.cmake

@@ -429,19 +429,20 @@ endif()
 source_group(TREE ${JOLT_PHYSICS_ROOT} FILES ${JOLT_PHYSICS_SRC_FILES})
 
 # Create Jolt lib
+add_library(Jolt ${JOLT_PHYSICS_SRC_FILES})
 
-if (COMPILE_AS_SHARED_LIBRARY)
-	add_library(Jolt SHARED ${JOLT_PHYSICS_SRC_FILES})
-
+if (BUILD_SHARED_LIBS)
 	# Set default visibility to hidden
 	set(CMAKE_CXX_VISIBILITY_PRESET hidden)
 
-	if (MSVC)
-		# MSVC specific option to enable PDB generation
-		set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:FASTLINK")
-	else()
-		# Clang/GCC option to enable debug symbol generation
-		set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -g")
+	if (GENERATE_DEBUG_SYMBOLS)
+		if (MSVC)
+			# MSVC specific option to enable PDB generation
+			set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:FASTLINK")
+		else()
+			# Clang/GCC option to enable debug symbol generation
+			set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -g")
+		endif()
 	endif()
 
 	# Set linker flags for other build types to be the same as release
@@ -455,8 +456,6 @@ if (COMPILE_AS_SHARED_LIBRARY)
 
 	# Private define to instruct the library to export symbols for shared linking
 	target_compile_definitions(Jolt PRIVATE JPH_BUILD_SHARED_LIBRARY)
-else()
-	add_library(Jolt STATIC ${JOLT_PHYSICS_SRC_FILES})
 endif()
 
 target_include_directories(Jolt PUBLIC ${PHYSICS_REPO_ROOT})